gitee.com/mysnapcore/mysnapd@v0.1.0/interfaces/builtin/desktop_launch_test.go (about) 1 // -*- Mode: Go; indent-tabs-mode: t -*- 2 3 /* 4 * Copyright (C) 2019 Canonical Ltd 5 * 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License version 3 as 8 * published by the Free Software Foundation. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 * 18 */ 19 20 package builtin_test 21 22 import ( 23 . "gopkg.in/check.v1" 24 25 "gitee.com/mysnapcore/mysnapd/interfaces" 26 "gitee.com/mysnapcore/mysnapd/interfaces/apparmor" 27 "gitee.com/mysnapcore/mysnapd/interfaces/builtin" 28 "gitee.com/mysnapcore/mysnapd/snap" 29 "gitee.com/mysnapcore/mysnapd/testutil" 30 ) 31 32 type desktopLaunchSuite struct { 33 iface interfaces.Interface 34 slotInfo *snap.SlotInfo 35 slot *interfaces.ConnectedSlot 36 plugInfo *snap.PlugInfo 37 plug *interfaces.ConnectedPlug 38 } 39 40 var _ = Suite(&desktopLaunchSuite{ 41 iface: builtin.MustInterface("desktop-launch"), 42 }) 43 44 const desktopLaunchConsumerYaml = ` 45 name: other 46 version: 0 47 apps: 48 app: 49 command: foo 50 plugs: [desktop-launch] 51 ` 52 53 const desktopLaunchCoreYaml = `name: core 54 version: 0 55 type: os 56 slots: 57 desktop-launch: 58 ` 59 60 func (s *desktopLaunchSuite) SetUpTest(c *C) { 61 s.plug, s.plugInfo = MockConnectedPlug(c, desktopLaunchConsumerYaml, nil, "desktop-launch") 62 s.slot, s.slotInfo = MockConnectedSlot(c, desktopLaunchCoreYaml, nil, "desktop-launch") 63 } 64 65 func (s *desktopLaunchSuite) TestName(c *C) { 66 c.Assert(s.iface.Name(), Equals, "desktop-launch") 67 } 68 69 func (s *desktopLaunchSuite) TestSanitizeSlot(c *C) { 70 c.Assert(interfaces.BeforePrepareSlot(s.iface, s.slotInfo), IsNil) 71 } 72 73 func (s *desktopLaunchSuite) TestSanitizePlug(c *C) { 74 c.Assert(interfaces.BeforePreparePlug(s.iface, s.plugInfo), IsNil) 75 } 76 77 func (s *desktopLaunchSuite) TestConnectedPlugSnippet(c *C) { 78 apparmorSpec := &apparmor.Specification{} 79 err := apparmorSpec.AddConnectedPlug(s.iface, s.plug, s.slot) 80 c.Assert(err, IsNil) 81 c.Assert(apparmorSpec.SecurityTags(), DeepEquals, []string{"snap.other.app"}) 82 c.Assert(apparmorSpec.SnippetForTag("snap.other.app"), testutil.Contains, `Can identify and launch other snaps.`) 83 c.Assert(apparmorSpec.SnippetForTag("snap.other.app"), testutil.Contains, `member=OpenDesktopEntry`) 84 c.Assert(apparmorSpec.SnippetForTag("snap.other.app"), testutil.Contains, `peer=(label=unconfined),`) 85 } 86 87 func (s *desktopLaunchSuite) TestInterfaces(c *C) { 88 c.Check(builtin.Interfaces(), testutil.DeepContains, s.iface) 89 } 90 91 func (s *desktopLaunchSuite) TestStaticInfo(c *C) { 92 si := interfaces.StaticInfoOf(s.iface) 93 c.Assert(si.ImplicitOnCore, Equals, false) 94 c.Assert(si.ImplicitOnClassic, Equals, true) 95 c.Assert(si.Summary, Equals, `allows snaps to identify and launch desktop applications in (or from) other snaps`) 96 c.Assert(si.BaseDeclarationSlots, testutil.Contains, "desktop-launch") 97 c.Assert(si.BaseDeclarationSlots, testutil.Contains, "deny-auto-connection: true") 98 c.Assert(si.BaseDeclarationPlugs, testutil.Contains, "desktop-launch") 99 c.Assert(si.BaseDeclarationPlugs, testutil.Contains, "deny-auto-connection: true") 100 c.Assert(si.BaseDeclarationPlugs, testutil.Contains, "allow-installation: false") 101 }