gitee.com/mysnapcore/mysnapd@v0.1.0/interfaces/builtin/storage_framework_service_test.go (about) 1 // -*- Mode: Go; indent-tabs-mode: t -*- 2 3 /* 4 * Copyright (C) 2017 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/interfaces/seccomp" 29 "gitee.com/mysnapcore/mysnapd/snap" 30 "gitee.com/mysnapcore/mysnapd/snap/snaptest" 31 "gitee.com/mysnapcore/mysnapd/testutil" 32 ) 33 34 type StorageFrameworkServiceInterfaceSuite struct { 35 iface interfaces.Interface 36 slotInfo *snap.SlotInfo 37 slot *interfaces.ConnectedSlot 38 plugInfo *snap.PlugInfo 39 plug *interfaces.ConnectedPlug 40 } 41 42 var _ = Suite(&StorageFrameworkServiceInterfaceSuite{ 43 iface: builtin.MustInterface("storage-framework-service"), 44 }) 45 46 func (s *StorageFrameworkServiceInterfaceSuite) SetUpTest(c *C) { 47 const providerYaml = `name: provider 48 version: 1.0 49 apps: 50 app: 51 command: foo 52 slots: [storage-framework-service] 53 ` 54 providerInfo := snaptest.MockInfo(c, providerYaml, nil) 55 s.slotInfo = providerInfo.Slots["storage-framework-service"] 56 s.slot = interfaces.NewConnectedSlot(s.slotInfo, nil, nil) 57 58 const consumerYaml = `name: consumer 59 version: 1.0 60 apps: 61 app: 62 command: foo 63 plugs: [storage-framework-service] 64 ` 65 consumerInfo := snaptest.MockInfo(c, consumerYaml, nil) 66 s.plugInfo = consumerInfo.Plugs["storage-framework-service"] 67 s.plug = interfaces.NewConnectedPlug(s.plugInfo, nil, nil) 68 69 } 70 71 func (s *StorageFrameworkServiceInterfaceSuite) TestName(c *C) { 72 c.Check(s.iface.Name(), Equals, "storage-framework-service") 73 } 74 75 func (s *StorageFrameworkServiceInterfaceSuite) TestAppArmorConnectedPlug(c *C) { 76 spec := &apparmor.Specification{} 77 c.Assert(spec.AddConnectedPlug(s.iface, s.plug, s.slot), IsNil) 78 c.Assert(spec.SecurityTags(), DeepEquals, []string{"snap.consumer.app"}) 79 c.Assert(spec.SnippetForTag("snap.consumer.app"), testutil.Contains, `interface=com.canonical.StorageFramework.Registry`) 80 } 81 82 func (s *StorageFrameworkServiceInterfaceSuite) TestAppArmorConnectedSlot(c *C) { 83 spec := &apparmor.Specification{} 84 c.Assert(spec.AddConnectedSlot(s.iface, s.plug, s.slot), IsNil) 85 c.Assert(spec.SecurityTags(), DeepEquals, []string{"snap.provider.app"}) 86 c.Assert(spec.SnippetForTag("snap.provider.app"), testutil.Contains, `interface=com.canonical.StorageFramework`) 87 } 88 89 func (s *StorageFrameworkServiceInterfaceSuite) TestAppArmorPermanentSlot(c *C) { 90 spec := &apparmor.Specification{} 91 c.Assert(spec.AddPermanentSlot(s.iface, s.slotInfo), IsNil) 92 c.Assert(spec.SecurityTags(), DeepEquals, []string{"snap.provider.app"}) 93 c.Assert(spec.SnippetForTag("snap.provider.app"), testutil.Contains, `member={RequestName,ReleaseName,GetConnectionCredentials}`) 94 } 95 96 func (s *StorageFrameworkServiceInterfaceSuite) TestSecCompPermanentSlot(c *C) { 97 spec := &seccomp.Specification{} 98 c.Assert(spec.AddPermanentSlot(s.iface, s.slotInfo), IsNil) 99 c.Assert(spec.SecurityTags(), DeepEquals, []string{"snap.provider.app"}) 100 c.Assert(spec.SnippetForTag("snap.provider.app"), testutil.Contains, "bind\n") 101 } 102 103 func (s *StorageFrameworkServiceInterfaceSuite) TestInterfaces(c *C) { 104 c.Check(builtin.Interfaces(), testutil.DeepContains, s.iface) 105 }