Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

interfaces/desktop-launch: support confined snaps launching other snaps #8699

Merged
merged 130 commits into from
May 31, 2021
Merged
Show file tree
Hide file tree
Changes from 124 commits
Commits
Show all changes
130 commits
Select commit Hold shift + click to select a range
0461b76
"shell-support" interface
AlanGriffiths Sep 2, 2019
a954fea
Spike OpenDesktopEntry method
AlanGriffiths Aug 19, 2019
8a60e15
Add OpenDesktopEntryEnv to permit setting environment variables
AlanGriffiths Sep 3, 2019
6f8343d
Switch to Desktop File IDs
AlanGriffiths Sep 3, 2019
677a1bd
Extract desktopFileIdToFilename()
AlanGriffiths Sep 4, 2019
2258b75
Extract readExecCommandFromDesktopFile()
AlanGriffiths Sep 4, 2019
5987a0a
Clearer use of whitespace
AlanGriffiths Sep 11, 2019
2bc5922
More robust logic in readExecCommandFromDesktopFile()
AlanGriffiths Sep 19, 2019
71d2123
Document the processing of the exec command
AlanGriffiths Sep 19, 2019
b7de328
> Missing high-level test for interface 'shell-support'. Please add to:
AlanGriffiths Sep 19, 2019
abfc59a
Handle shell quoting in the exec command
AlanGriffiths Sep 19, 2019
c48272c
Drop the `OpenDesktopEntry()` method
AlanGriffiths Sep 19, 2019
67d2f61
Better handling of exec variables
AlanGriffiths Sep 19, 2019
e8dec70
deny-auto-connection: true
AlanGriffiths Sep 19, 2019
b769b09
Use the `MockConnectedPlug` and `MockConnectedSlot` helpers
AlanGriffiths Sep 19, 2019
23e7a89
Use free functions
AlanGriffiths Sep 19, 2019
a11e9b4
Rename `shell-support` => `app-launch`
AlanGriffiths Sep 20, 2019
2671228
Report error if desktop file not found
AlanGriffiths Sep 20, 2019
16f03b0
Search all the paths that can be formed by the desktop ID
AlanGriffiths Sep 20, 2019
00cc0f8
We don't need github.com/google/shlex, we have github.com/snapcore/sn…
AlanGriffiths Sep 23, 2019
f1aeab9
Don't use error to indicate whether a desktop file is found
AlanGriffiths Sep 23, 2019
196ad63
Update comments referring to desktop-entry-spec-latest.html
AlanGriffiths Sep 23, 2019
09f9474
Don't ignore errors from os.Stat()
AlanGriffiths Sep 23, 2019
fca6562
Restrict the environment variables that may be set to those used to d…
AlanGriffiths Sep 23, 2019
848a73e
Comment to explain the code
AlanGriffiths Sep 23, 2019
cca474e
Use dirs.SnapDesktopFilesDir, not a hard coded path
AlanGriffiths Sep 23, 2019
a7f75ee
First cut at some internal tests
AlanGriffiths Sep 25, 2019
5dd7228
Test parsing of Exec command
AlanGriffiths Sep 25, 2019
2567e93
Use the shell to launch the app to avoid becoming a parent and/or lea…
AlanGriffiths Sep 26, 2019
a3c1ed2
Fix "usersession/userd/launcher.go:154:13: undefined: strings.Replace…
AlanGriffiths Sep 26, 2019
c7534e8
Drop implicitOnCore as it isn't supportable (yet)
AlanGriffiths Oct 2, 2019
e6997dc
Remove "unknown field 'reservedForOS' in struct literal of type commo…
AlanGriffiths May 18, 2020
b2567ff
Rename `app-launch` => `desktop-launch`
AlanGriffiths May 19, 2020
9d77a34
Merge remote-tracking branch 'origin/master' into open-desktop-entry
AlanGriffiths May 19, 2020
a10ae4f
Merge remote-tracking branch 'origin/master' into open-desktop-entry
AlanGriffiths May 20, 2020
6547512
Renames to conform to convention
AlanGriffiths May 28, 2020
74c437d
Use a scanner instead of reading lines "by hand"
AlanGriffiths May 28, 2020
fda7fa0
Use the language better
AlanGriffiths May 28, 2020
cd6378f
Update naming
AlanGriffiths May 28, 2020
f18aee7
Use check.v1
AlanGriffiths May 28, 2020
3a44c7f
Less evil hack to avoid zombie processes
AlanGriffiths Jun 1, 2020
2d3b99a
Make interface superprivileged
AlanGriffiths Jun 1, 2020
000837f
Add TestStaticInfo() to interface tests
AlanGriffiths Jun 1, 2020
a6499d8
Reworked comments and added sanity for review
AlanGriffiths Jun 1, 2020
2773622
Additional "hardening" suggested in review
AlanGriffiths Jun 1, 2020
7371e9b
gofmt -s -w
AlanGriffiths Jun 1, 2020
7742cfe
Add BaseDeclarationPlugs to desktopLaunchSuite.TestStaticInfo
AlanGriffiths Jun 11, 2020
fb2764b
Document allowedEnvVars
AlanGriffiths Jun 11, 2020
d30cff7
Update comment
AlanGriffiths Jun 11, 2020
6ede6fe
Document and correct check on desktop file & path
AlanGriffiths Jun 11, 2020
888ffbb
gofmt
AlanGriffiths Jun 11, 2020
6c60b2e
Add test for foo-bar_foo-bar.desktop
AlanGriffiths Jun 11, 2020
805886d
A comment to explain test strategy
AlanGriffiths Jun 11, 2020
bbc945e
Merge remote-tracking branch 'upstream/master' into open-desktop-entry
AlanGriffiths Jun 11, 2020
6848788
Check the desktopFile path all the way down from "/"
AlanGriffiths Jun 16, 2020
2c4ea7d
Comment on the recursion in findDesktopFile
AlanGriffiths Jun 16, 2020
31a13cd
Use err to indicate failure instead of null pointer to string
AlanGriffiths Jun 16, 2020
429b549
Clearer table of test cases in TestParseExecCommandSucceedsWithValidE…
AlanGriffiths Jun 16, 2020
73ff67a
Extract verifyDesktopFileLocation() from readExecCommandFromDesktopFi…
AlanGriffiths Jun 16, 2020
24179b2
Tests for readExecCommandFromDesktopFile()
AlanGriffiths Jun 17, 2020
6adef25
First draft of TestOpenDesktopEntryEnvSucceedsWithGoodDesktopId
AlanGriffiths Jun 17, 2020
5a283e6
Hack the production code to make the tests pass
AlanGriffiths Jun 18, 2020
1553fa3
Test some error paths
AlanGriffiths Jun 18, 2020
f913a42
Merge remote-tracking branch 'upstream/master' into open-desktop-entry
AlanGriffiths Jun 18, 2020
c6a5d1e
Use camelCase
AlanGriffiths Jun 30, 2020
fc17286
Merge remote-tracking branch 'upstream/master' into desktop-launch-iface
jhenstridge Jul 3, 2020
04acb0c
tests: add a basic spread test for the dbus-launch interface
jhenstridge Jul 3, 2020
d8fda58
Merge pull request #2 from jhenstridge/desktop-launch-iface
AlanGriffiths Jul 3, 2020
8ba9b51
Update tests/main/interfaces-desktop-launch/test-app/bin/app.sh
AlanGriffiths Jul 3, 2020
2ecb2b3
Add access to /var/lib/snapd/desktop/icons
AlanGriffiths Aug 6, 2020
8686434
Add RegularFileExists() to osutil
AlanGriffiths Aug 6, 2020
fde5f97
We don't want /foo2 to be treated as under /foo
AlanGriffiths Aug 6, 2020
932e06c
Drop contentious checks
AlanGriffiths Aug 6, 2020
876da60
Error out on unexpected exec variables
AlanGriffiths Aug 6, 2020
461865e
Reword comment
AlanGriffiths Aug 6, 2020
6b25e2d
Update test Exec lines with exec variables we do support
AlanGriffiths Aug 6, 2020
d49bc2e
go fmt
AlanGriffiths Aug 20, 2020
3b94f67
Comments adjusted to match code
AlanGriffiths Aug 20, 2020
bba4b04
Use systemd-run to launch apps
AlanGriffiths Aug 20, 2020
944a9f6
Don't pass environment
AlanGriffiths Aug 20, 2020
df18340
Failed PrivilegedDesktopLauncher
AlanGriffiths Aug 28, 2020
aa309b3
Make path match interface
AlanGriffiths Sep 16, 2020
8779610
Merge remote-tracking branch 'origin/master' into io.snapcraft.Privil…
AlanGriffiths Oct 12, 2020
d5505c7
Update to reflect snapcore#9370
AlanGriffiths Oct 12, 2020
5459324
Merge pull request #3 from MirServer/io.snapcraft.PrivilegedDesktopLa…
AlanGriffiths Oct 12, 2020
5cc65f3
Drop OpenDesktopEntry from io.snapcraft.Launcher
AlanGriffiths Oct 12, 2020
065a98a
Split out PrivilegedDesktopLauncher tests
AlanGriffiths Oct 12, 2020
94dd345
Use export_test.go to access internal functions
AlanGriffiths Oct 12, 2020
dea3c8a
Use dirs.SnapBinariesDir
AlanGriffiths Oct 12, 2020
4ef15aa
Fix and move repetitive test setup to SetUpTest()
AlanGriffiths Oct 13, 2020
17c38e3
go fmt
AlanGriffiths Oct 13, 2020
47872a7
Support for %i
AlanGriffiths Oct 13, 2020
b075034
Correct desktop-launch launcher.sh script
AlanGriffiths Oct 13, 2020
bdc03fa
Merge remote-tracking branch 'origin/master' into open-desktop-entry
AlanGriffiths Oct 13, 2020
607b49a
Revert accidental move of fdToFilename from launcher.go
AlanGriffiths Oct 13, 2020
c228d16
userd: delete unused PrivilegedDesktopLauncher.OpenFile D-Bus method
jhenstridge Dec 3, 2020
cd6244f
userd: clean up PrivilegedDesktopLauncher code based on review from @…
jhenstridge Dec 4, 2020
bade7ab
userd: simplify how the mock fileExists handler is injected for testing
jhenstridge Dec 4, 2020
e7ec6d8
Merge remote-tracking branch 'origin/master' into open-desktop-entry
AlanGriffiths Dec 4, 2020
a64a652
Don't try to pass environment in interfaces-desktop-launch
AlanGriffiths Dec 7, 2020
020b575
Add "internal error: " to what is currently a logic error
AlanGriffiths Dec 16, 2020
dbf2f7f
Merge remote-tracking branch 'origin/master' into open-desktop-entry
AlanGriffiths Feb 3, 2021
dfa591f
Use the new regularFileExists signature
AlanGriffiths Feb 3, 2021
1751bff
Use `--collect` with systemd-run
AlanGriffiths Feb 22, 2021
0e76699
unnecessary whitespace
AlanGriffiths Feb 22, 2021
e312ab1
we should keep the error and include it in the message
AlanGriffiths Feb 22, 2021
d7a07aa
change to a TODO
AlanGriffiths Feb 22, 2021
dcdac5e
Remove spurious comma
AlanGriffiths Feb 22, 2021
a97e900
usersession/userd: only pass --collect if we have a new enough systemd
jhenstridge Feb 25, 2021
5e8c3f3
Merge pull request #4 from jhenstridge/desktop-launch-iface
AlanGriffiths Feb 25, 2021
4ec0b3b
Merge remote-tracking branch 'upstream/master' into desktop-launch-iface
jhenstridge Mar 19, 2021
f6a83df
u/userd: test error message from desktopFileIDToFilename
jhenstridge Mar 19, 2021
742d1d8
usersession/userd: apply a regexp to validate desktop file IDs
jhenstridge Mar 22, 2021
2f45fd4
usersession/userd: update copyright notices
jhenstridge Mar 22, 2021
b16ccb4
usersession/userd: fix up some error assertions in tests, and catch s…
jhenstridge Mar 22, 2021
e5e989e
usersession/userd: follow the XDG Base Dir spec in resolving desktop …
jhenstridge Mar 24, 2021
f5f4873
tests: ensure XDG_DATA_DIRS is set in spread test
jhenstridge Mar 24, 2021
3d48386
usersession/userd: don't reuse the object path of the existing launcher
jhenstridge Mar 24, 2021
14009e0
usersession/userd: add a direct test for DesktopFileIDToFilename with…
jhenstridge Mar 24, 2021
b144983
usersession/userd: add test demonstrating that launching non-snap des…
jhenstridge Mar 24, 2021
a8c979c
usersession/userd: more fixups based on review comments
jhenstridge Mar 24, 2021
47d6a3e
usersession/userd: reject desktop files with multiple [Desktop Entry]…
jhenstridge Mar 25, 2021
7be605e
Merge pull request #6 from jhenstridge/desktop-launch-iface
AlanGriffiths Mar 25, 2021
2284c54
Address latest review feedback
AlanGriffiths Apr 15, 2021
4213409
Fix accidental paste.
AlanGriffiths Apr 16, 2021
57ef4e2
Update tests to match
AlanGriffiths Apr 16, 2021
76a3681
Merge branch 'master' into open-desktop-entry
AlanGriffiths May 21, 2021
ebb891c
Merge remote-tracking branch 'origin/master' into open-desktop-entry
AlanGriffiths May 28, 2021
76284d4
Update tests/main/interfaces-desktop-launch/task.yaml
AlanGriffiths May 28, 2021
13c4aea
Update tests/main/interfaces-desktop-launch/task.yaml
AlanGriffiths May 28, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions interfaces/builtin/desktop_launch.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// -*- Mode: Go; indent-tabs-mode: t -*-

/*
* Copyright (C) 2019 Canonical Ltd
jhenstridge marked this conversation as resolved.
Show resolved Hide resolved
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

package builtin

const desktopLaunchSummary = `allows snaps to identify and launch desktop applications in (or from) other snaps`

const desktopLaunchBaseDeclarationPlugs = `
Copy link
Collaborator

@pedronis pedronis Apr 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the base declaration looks right, it follow the same pattern as snapd-control of a superprivileged interface

desktop-launch:
allow-installation: false
deny-auto-connection: true
`
jhenstridge marked this conversation as resolved.
Show resolved Hide resolved

const desktopLaunchBaseDeclarationSlots = `
desktop-launch:
allow-installation:
slot-snap-type:
- core
deny-auto-connection: true
jdstrand marked this conversation as resolved.
Show resolved Hide resolved
`

const desktopLaunchConnectedPlugAppArmor = `
# Description: Can identify and launch other snaps.

# Access to the desktop and icon files installed by snaps
/var/lib/snapd/desktop/applications/{,*} r,
AlanGriffiths marked this conversation as resolved.
Show resolved Hide resolved
/var/lib/snapd/desktop/icons/{,*} r,

#include <abstractions/dbus-session-strict>

dbus (send)
bus=session
path=/io/snapcraft/PrivilegedDesktopLauncher
interface=io.snapcraft.PrivilegedDesktopLauncher
peer=(label=unconfined),member=OpenDesktopEntry
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks wrong. The comma separates AppArmor rules, so this breaks a rule in half.

Rather than changing the AppArmor snippet, @pedronis was suggesting that an extra assertion be added to the test verifying that the snippet contained this part of the rule.

peer=(label=unconfined),
jhenstridge marked this conversation as resolved.
Show resolved Hide resolved
`

// Only implicitOnClassic since userd isn't yet usable on core
jhenstridge marked this conversation as resolved.
Show resolved Hide resolved
func init() {
registerIface(&commonInterface{
name: "desktop-launch",
summary: desktopLaunchSummary,
implicitOnClassic: true,
jdstrand marked this conversation as resolved.
Show resolved Hide resolved
jhenstridge marked this conversation as resolved.
Show resolved Hide resolved
baseDeclarationPlugs: desktopLaunchBaseDeclarationPlugs,
AlanGriffiths marked this conversation as resolved.
Show resolved Hide resolved
baseDeclarationSlots: desktopLaunchBaseDeclarationSlots,
jdstrand marked this conversation as resolved.
Show resolved Hide resolved
connectedPlugAppArmor: desktopLaunchConnectedPlugAppArmor,
})
}
101 changes: 101 additions & 0 deletions interfaces/builtin/desktop_launch_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// -*- Mode: Go; indent-tabs-mode: t -*-

/*
* Copyright (C) 2019 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

package builtin_test

import (
. "gopkg.in/check.v1"

"github.com/snapcore/snapd/interfaces"
"github.com/snapcore/snapd/interfaces/apparmor"
"github.com/snapcore/snapd/interfaces/builtin"
"github.com/snapcore/snapd/snap"
"github.com/snapcore/snapd/testutil"
)

type desktopLaunchSuite struct {
iface interfaces.Interface
slotInfo *snap.SlotInfo
slot *interfaces.ConnectedSlot
plugInfo *snap.PlugInfo
plug *interfaces.ConnectedPlug
}

var _ = Suite(&desktopLaunchSuite{
iface: builtin.MustInterface("desktop-launch"),
})

const desktopLaunchConsumerYaml = `
name: other
version: 0
apps:
app:
command: foo
plugs: [desktop-launch]
`

const desktopLaunchCoreYaml = `name: core
version: 0
type: os
slots:
desktop-launch:
`

func (s *desktopLaunchSuite) SetUpTest(c *C) {
s.plug, s.plugInfo = MockConnectedPlug(c, desktopLaunchConsumerYaml, nil, "desktop-launch")
s.slot, s.slotInfo = MockConnectedSlot(c, desktopLaunchCoreYaml, nil, "desktop-launch")
}

func (s *desktopLaunchSuite) TestName(c *C) {
c.Assert(s.iface.Name(), Equals, "desktop-launch")
}

func (s *desktopLaunchSuite) TestSanitizeSlot(c *C) {
c.Assert(interfaces.BeforePrepareSlot(s.iface, s.slotInfo), IsNil)
}

func (s *desktopLaunchSuite) TestSanitizePlug(c *C) {
c.Assert(interfaces.BeforePreparePlug(s.iface, s.plugInfo), IsNil)
}

func (s *desktopLaunchSuite) TestConnectedPlugSnippet(c *C) {
apparmorSpec := &apparmor.Specification{}
err := apparmorSpec.AddConnectedPlug(s.iface, s.plug, s.slot)
c.Assert(err, IsNil)
c.Assert(apparmorSpec.SecurityTags(), DeepEquals, []string{"snap.other.app"})
c.Assert(apparmorSpec.SnippetForTag("snap.other.app"), testutil.Contains, `Can identify and launch other snaps.`)
Copy link
Collaborator

@pedronis pedronis Apr 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we probably want to check as well at least for:

member=OpenDesktopEntry
peer=(label=unconfined),

c.Assert(apparmorSpec.SnippetForTag("snap.other.app"), testutil.Contains, `member=OpenDesktopEntry`)
c.Assert(apparmorSpec.SnippetForTag("snap.other.app"), testutil.Contains, `peer=(label=unconfined),`)
}

func (s *desktopLaunchSuite) TestInterfaces(c *C) {
c.Check(builtin.Interfaces(), testutil.DeepContains, s.iface)
}
jdstrand marked this conversation as resolved.
Show resolved Hide resolved

func (s *desktopLaunchSuite) TestStaticInfo(c *C) {
si := interfaces.StaticInfoOf(s.iface)
c.Assert(si.ImplicitOnCore, Equals, false)
c.Assert(si.ImplicitOnClassic, Equals, true)
c.Assert(si.Summary, Equals, `allows snaps to identify and launch desktop applications in (or from) other snaps`)
c.Assert(si.BaseDeclarationSlots, testutil.Contains, "desktop-launch")
c.Assert(si.BaseDeclarationSlots, testutil.Contains, "deny-auto-connection: true")
jdstrand marked this conversation as resolved.
Show resolved Hide resolved
c.Assert(si.BaseDeclarationPlugs, testutil.Contains, "desktop-launch")
c.Assert(si.BaseDeclarationPlugs, testutil.Contains, "deny-auto-connection: true")
c.Assert(si.BaseDeclarationPlugs, testutil.Contains, "allow-installation: false")
}
21 changes: 21 additions & 0 deletions interfaces/policy/basedeclaration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,7 @@ var (
"cups-control": {"app", "core"},
"dbus": {"app"},
"docker-support": {"core"},
"desktop-launch": {"core"},
"dummy": {"app"},
"fwupd": {"app", "core"},
"gpio": {"core", "gadget"},
Expand Down Expand Up @@ -702,6 +703,7 @@ func (s *baseDeclSuite) TestPlugInstallation(c *C) {
restricted := map[string]bool{
"block-devices": true,
"classic-support": true,
"desktop-launch": true,
"docker-support": true,
"greengrass-support": true,
"gpio-control": true,
Expand Down Expand Up @@ -934,6 +936,7 @@ func (s *baseDeclSuite) TestSanity(c *C) {
"audio-playback": true,
"classic-support": true,
"core-support": true,
"desktop-launch": true,
"docker-support": true,
"greengrass-support": true,
"gpio-control": true,
Expand Down Expand Up @@ -1200,3 +1203,21 @@ plugs:
c.Check(err, IsNil)
c.Check(arity.SlotsPerPlugAny(), Equals, false)
}

func (s *baseDeclSuite) TestAutoConnectionDesktopLaunchOverride(c *C) {
cand := s.connectCand(c, "desktop-launch", "", "")
_, err := cand.CheckAutoConnect()
c.Check(err, NotNil)
c.Assert(err, ErrorMatches, "auto-connection denied by plug rule of interface \"desktop-launch\"")

plugsSlots := `
plugs:
desktop-launch:
allow-auto-connection: true
`

snapDecl := s.mockSnapDecl(c, "some-snap", "some-snap-with-desktop-launch-id", "canonical", plugsSlots)
cand.PlugSnapDeclaration = snapDecl
_, err = cand.CheckAutoConnect()
c.Check(err, IsNil)
}
3 changes: 3 additions & 0 deletions tests/lib/snaps/test-snapd-policy-app-consumer/meta/snap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ apps:
desktop:
command: bin/run
plugs: [ desktop ]
desktop-launch:
command: bin/run
plugs: [ desktop-launch ]
desktop-legacy:
command: bin/run
plugs: [ desktop-legacy ]
Expand Down
56 changes: 56 additions & 0 deletions tests/main/interfaces-desktop-launch/task.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
summary: Ensure that the desktop-launch interface works.

details: |
The desktop-launch interface allows a snap to launch other snaps via
the desktop files they provide to the host system.

systems: [-ubuntu-core-*]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you add a comment that userd does not yet work properly enough on ubuntu core to be able to run this test there (fine for followup)?


prepare: |
if ! tests.session has-session-systemd-and-dbus; then
exit 0
fi
tests.session -u test prepare
tests.session -u test exec systemctl --user \
set-environment XDG_DATA_DIRS=/usr/share:/var/lib/snapd/desktop

restore: |
if ! tests.session has-session-systemd-and-dbus; then
exit 0
fi
tests.session -u test restore
rm -f ~test/snap/test-app/current/launch-data.txt

execute: |
if ! tests.session has-session-systemd-and-dbus; then
exit 0
fi

#shellcheck source=tests/lib/snaps.sh
. "$TESTSLIB"/snaps.sh

echo "Install the application snap"
install_local test-app
AlanGriffiths marked this conversation as resolved.
Show resolved Hide resolved
echo "The snap installs a desktop file"
[ -f /var/lib/snapd/desktop/applications/test-app_test-app.desktop ]

echo "Install the launcher snap"
install_local test-launcher
AlanGriffiths marked this conversation as resolved.
Show resolved Hide resolved

echo "The desktop-launch plug is initially disconnected"
snap connections test-launcher | MATCH "desktop-launch +test-launcher:desktop-launch +- +-"

echo "The plug can be connected"
snap connect test-launcher:desktop-launch
snap connections test-launcher | MATCH "desktop-launch +test-launcher:desktop-launch +:desktop-launch +manual"

echo "The launcher snap can launch other snaps via userd"
tests.session -u test exec test-launcher \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this need to be exec? I assume this is somehow related to user sessions?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also should we be checking the output of this command with MATCH, since we are using --print-reply?

test-app_test-app.desktop

echo "The app snap records that it has been launched"
launch_data=~test/snap/test-app/current/launch-data.txt
retry -n 5 --wait 1 test -s "$launch_data"

echo "The app was invoked with the arguments in the desktop file"
MATCH "^args=arg-before arg-after$" < "$launch_data"
12 changes: 12 additions & 0 deletions tests/main/interfaces-desktop-launch/test-app/bin/app.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

echo "App launched"

cat << EOF > "$SNAP_USER_DATA"/launch-data.txt
args=$*
DISPLAY=${DISPLAY}
WAYLAND_DISPLAY=${WAYLAND_DISPLAY}
XDG_CURRENT_DESKTOP=${XDG_CURRENT_DESKTOP}
XDG_SESSION_DESKTOP=${XDG_SESSION_DESKTOP}
XDG_SESSION_TYPE=${XDG_SESSION_TYPE}
EOF
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[Desktop Entry]
Type=Application
Name=test-app
Comment=A desktop file for test-app
Exec=test-app arg-before %U arg-after
9 changes: 9 additions & 0 deletions tests/main/interfaces-desktop-launch/test-app/meta/snap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: test-app
version: 1.0
summary: Basic desktop app test snap
description: A basic snap to act as a target for the launcher

apps:
test-app:
command: bin/app.sh
plugs: [desktop]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

exec dbus-send --session --print-reply \
--dest=io.snapcraft.Launcher /io/snapcraft/PrivilegedDesktopLauncher \
io.snapcraft.PrivilegedDesktopLauncher.OpenDesktopEntry \
string:"$1"
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: test-launcher
version: 1.0
summary: Basic desktop launcher snap
description: A basic snap that attempts to launch other snaps

apps:
test-launcher:
command: bin/launcher.sh
plugs: [desktop-launch]
16 changes: 16 additions & 0 deletions usersession/userd/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,19 @@ func MockSnapFromSender(f func(*dbus.Conn, dbus.Sender) (string, error)) func()
snapFromSender = origSnapFromSender
}
}

var (
DesktopFileSearchPath = desktopFileSearchPath
DesktopFileIDToFilename = desktopFileIDToFilename
VerifyDesktopFileLocation = verifyDesktopFileLocation
ParseExecCommand = parseExecCommand
ReadExecCommandFromDesktopFile = readExecCommandFromDesktopFile
)

func MockRegularFileExists(f func(string) (bool, bool, error)) func() {
old := regularFileExists
regularFileExists = f
return func() {
regularFileExists = old
}
}
Loading