github.com/kubiko/snapd@v0.0.0-20201013125620-d4f3094d9ddf/interfaces/builtin/gconf_test.go (about) 1 // -*- Mode: Go; indent-tabs-mode: t -*- 2 3 /* 4 * Copyright (C) 2020 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/dirs" 26 "github.com/snapcore/snapd/interfaces" 27 "github.com/snapcore/snapd/interfaces/apparmor" 28 "github.com/snapcore/snapd/interfaces/builtin" 29 "github.com/snapcore/snapd/release" 30 "github.com/snapcore/snapd/snap" 31 "github.com/snapcore/snapd/testutil" 32 ) 33 34 type gconfInterfaceSuite struct { 35 iface interfaces.Interface 36 coreSlotInfo *snap.SlotInfo 37 coreSlot *interfaces.ConnectedSlot 38 plugInfo *snap.PlugInfo 39 plug *interfaces.ConnectedPlug 40 } 41 42 var _ = Suite(&gconfInterfaceSuite{ 43 iface: builtin.MustInterface("gconf"), 44 }) 45 46 const gconfConsumerYaml = `name: consumer 47 version: 0 48 apps: 49 app: 50 plugs: [gconf] 51 ` 52 53 const gconfCoreYaml = `name: core 54 version: 0 55 type: os 56 slots: 57 gconf: 58 ` 59 60 func (s *gconfInterfaceSuite) SetUpTest(c *C) { 61 s.plug, s.plugInfo = MockConnectedPlug(c, gconfConsumerYaml, nil, "gconf") 62 s.coreSlot, s.coreSlotInfo = MockConnectedSlot(c, gconfCoreYaml, nil, "gconf") 63 } 64 65 func (s *gconfInterfaceSuite) TearDownTest(c *C) { 66 dirs.SetRootDir("/") 67 } 68 69 func (s *gconfInterfaceSuite) TestName(c *C) { 70 c.Assert(s.iface.Name(), Equals, "gconf") 71 } 72 73 func (s *gconfInterfaceSuite) TestSanitizeSlot(c *C) { 74 c.Assert(interfaces.BeforePrepareSlot(s.iface, s.coreSlotInfo), IsNil) 75 } 76 77 func (s *gconfInterfaceSuite) TestSanitizePlug(c *C) { 78 c.Assert(interfaces.BeforePreparePlug(s.iface, s.plugInfo), IsNil) 79 } 80 81 func (s *gconfInterfaceSuite) TestAppArmorSpec(c *C) { 82 restore := release.MockOnClassic(true) 83 defer restore() 84 85 spec := &apparmor.Specification{} 86 c.Assert(spec.AddConnectedPlug(s.iface, s.plug, s.coreSlot), IsNil) 87 c.Assert(spec.SecurityTags(), DeepEquals, []string{"snap.consumer.app"}) 88 c.Assert(spec.SnippetForTag("snap.consumer.app"), testutil.Contains, "# Description: Can access gconf databases from the user's session.") 89 c.Assert(spec.SnippetForTag("snap.consumer.app"), testutil.Contains, "interface=org.gnome.GConf.Database") 90 } 91 92 func (s *gconfInterfaceSuite) TestStaticInfo(c *C) { 93 si := interfaces.StaticInfoOf(s.iface) 94 c.Assert(si.ImplicitOnCore, Equals, false) 95 c.Assert(si.ImplicitOnClassic, Equals, true) 96 c.Assert(si.Summary, Equals, `allows access to any item from the legacy gconf configuration system for the current user`) 97 c.Assert(si.BaseDeclarationSlots, testutil.Contains, "gconf") 98 c.Assert(si.BaseDeclarationSlots, testutil.Contains, "deny-auto-connection: true") 99 } 100 101 func (s *gconfInterfaceSuite) TestInterfaces(c *C) { 102 c.Check(builtin.Interfaces(), testutil.DeepContains, s.iface) 103 }