|
| 1 | +// -*- Mode: Go; indent-tabs-mode: t -*- |
| 2 | + |
| 3 | +/* |
| 4 | + * Copyright (C) 2026 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 | + "github.com/snapcore/snapd/interfaces" |
| 26 | + "github.com/snapcore/snapd/interfaces/apparmor" |
| 27 | + "github.com/snapcore/snapd/interfaces/builtin" |
| 28 | + "github.com/snapcore/snapd/snap" |
| 29 | + "github.com/snapcore/snapd/testutil" |
| 30 | +) |
| 31 | + |
| 32 | +type XdgPermissionStoreInterfaceSuite struct { |
| 33 | + iface interfaces.Interface |
| 34 | + slot *interfaces.ConnectedSlot |
| 35 | + slotInfo *snap.SlotInfo |
| 36 | + plug *interfaces.ConnectedPlug |
| 37 | + plugInfo *snap.PlugInfo |
| 38 | +} |
| 39 | + |
| 40 | +var _ = Suite(&XdgPermissionStoreInterfaceSuite{ |
| 41 | + iface: builtin.MustInterface("xdg-permission-store"), |
| 42 | +}) |
| 43 | + |
| 44 | +func (s *XdgPermissionStoreInterfaceSuite) SetUpTest(c *C) { |
| 45 | + const coreYaml = `name: core |
| 46 | +version: 0 |
| 47 | +type: os |
| 48 | +slots: |
| 49 | + xdg-permission-store: |
| 50 | + interface: xdg-permission-store |
| 51 | +` |
| 52 | + s.slot, s.slotInfo = MockConnectedSlot(c, coreYaml, nil, "xdg-permission-store") |
| 53 | + |
| 54 | + const consumerYaml = `name: consumer |
| 55 | +version: 0 |
| 56 | +apps: |
| 57 | + app: |
| 58 | + plugs: [xdg-permission-store] |
| 59 | +` |
| 60 | + s.plug, s.plugInfo = MockConnectedPlug(c, consumerYaml, nil, "xdg-permission-store") |
| 61 | +} |
| 62 | + |
| 63 | +func (s *XdgPermissionStoreInterfaceSuite) TestName(c *C) { |
| 64 | + c.Assert(s.iface.Name(), Equals, "xdg-permission-store") |
| 65 | +} |
| 66 | + |
| 67 | +func (s *XdgPermissionStoreInterfaceSuite) TestSanitize(c *C) { |
| 68 | + c.Assert(interfaces.BeforePreparePlug(s.iface, s.plugInfo), IsNil) |
| 69 | + c.Assert(interfaces.BeforePrepareSlot(s.iface, s.slotInfo), IsNil) |
| 70 | +} |
| 71 | + |
| 72 | +func (s *XdgPermissionStoreInterfaceSuite) TestAppArmorConnectedPlug(c *C) { |
| 73 | + appSet, err := interfaces.NewSnapAppSet(s.plug.Snap(), nil) |
| 74 | + c.Assert(err, IsNil) |
| 75 | + spec := apparmor.NewSpecification(appSet) |
| 76 | + c.Assert(spec.AddConnectedPlug(s.iface, s.plug, s.slot), IsNil) |
| 77 | + c.Assert(spec.SecurityTags(), DeepEquals, []string{"snap.consumer.app"}) |
| 78 | + c.Check(spec.SnippetForTag("snap.consumer.app"), testutil.Contains, "#include <abstractions/dbus-session-strict>") |
| 79 | + c.Check(spec.SnippetForTag("snap.consumer.app"), testutil.Contains, "path=/org/freedesktop/impl/portal/PermissionStore") |
| 80 | + c.Check(spec.SnippetForTag("snap.consumer.app"), testutil.Contains, "interface=org.freedesktop.impl.portal.PermissionStore") |
| 81 | + c.Check(spec.SnippetForTag("snap.consumer.app"), testutil.Contains, "interface=org.freedesktop.DBus.Properties") |
| 82 | + c.Check(spec.SnippetForTag("snap.consumer.app"), testutil.Contains, "interface=org.freedesktop.DBus.Peer") |
| 83 | + c.Check(spec.SnippetForTag("snap.consumer.app"), testutil.Contains, "interface=org.freedesktop.DBus.Introspectable") |
| 84 | + c.Check(spec.SnippetForTag("snap.consumer.app"), testutil.Contains, "peer=(label=unconfined)") |
| 85 | +} |
| 86 | + |
| 87 | +func (s *XdgPermissionStoreInterfaceSuite) TestAppArmorConnectedSlot(c *C) { |
| 88 | + appSet, err := interfaces.NewSnapAppSet(s.slot.Snap(), nil) |
| 89 | + c.Assert(err, IsNil) |
| 90 | + spec := apparmor.NewSpecification(appSet) |
| 91 | + c.Assert(spec.AddConnectedSlot(s.iface, s.plug, s.slot), IsNil) |
| 92 | + c.Assert(spec.SecurityTags(), HasLen, 0) |
| 93 | +} |
| 94 | + |
| 95 | +func (s *XdgPermissionStoreInterfaceSuite) TestAppArmorPermanentSlot(c *C) { |
| 96 | + spec := &apparmor.Specification{} |
| 97 | + c.Assert(spec.AddPermanentSlot(s.iface, s.slotInfo), IsNil) |
| 98 | + c.Assert(spec.SecurityTags(), HasLen, 0) |
| 99 | +} |
| 100 | + |
| 101 | +func (s *XdgPermissionStoreInterfaceSuite) TestStaticInfo(c *C) { |
| 102 | + si := interfaces.StaticInfoOf(s.iface) |
| 103 | + c.Check(si.ImplicitOnCore, Equals, true) |
| 104 | + c.Check(si.ImplicitOnClassic, Equals, true) |
| 105 | + c.Check(si.Summary, Equals, "allows access to the xdg desktop portal PermissionStore service") |
| 106 | + c.Check(si.BaseDeclarationPlugs, testutil.Contains, "xdg-permission-store") |
| 107 | + c.Check(si.BaseDeclarationPlugs, testutil.Contains, "allow-installation: false") |
| 108 | + c.Check(si.BaseDeclarationPlugs, testutil.Contains, "deny-auto-connection: true") |
| 109 | + c.Check(si.BaseDeclarationSlots, testutil.Contains, "xdg-permission-store") |
| 110 | + c.Check(si.BaseDeclarationSlots, testutil.Contains, "deny-auto-connection: true") |
| 111 | +} |
| 112 | + |
| 113 | +func (s *XdgPermissionStoreInterfaceSuite) TestInterfaces(c *C) { |
| 114 | + c.Check(builtin.Interfaces(), testutil.DeepContains, s.iface) |
| 115 | +} |
0 commit comments