gitee.com/mysnapcore/mysnapd@v0.1.0/interfaces/builtin/microceph_test.go (about) 1 // -*- Mode: Go; indent-tabs-mode: t -*- 2 3 /* 4 * Copyright (C) 2022 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/testutil" 31 ) 32 33 type MicroCephInterfaceSuite struct { 34 iface interfaces.Interface 35 slotInfo *snap.SlotInfo 36 slot *interfaces.ConnectedSlot 37 plugInfo *snap.PlugInfo 38 plug *interfaces.ConnectedPlug 39 } 40 41 var _ = Suite(&MicroCephInterfaceSuite{ 42 iface: builtin.MustInterface("microceph"), 43 }) 44 45 const microcephConsumerYaml = `name: consumer 46 version: 0 47 apps: 48 app: 49 plugs: [microceph] 50 ` 51 52 const microcephCoreYaml = `name: core 53 version: 0 54 type: os 55 slots: 56 microceph: 57 ` 58 59 func (s *MicroCephInterfaceSuite) SetUpTest(c *C) { 60 s.plug, s.plugInfo = MockConnectedPlug(c, microcephConsumerYaml, nil, "microceph") 61 s.slot, s.slotInfo = MockConnectedSlot(c, microcephCoreYaml, nil, "microceph") 62 } 63 64 func (s *MicroCephInterfaceSuite) TestName(c *C) { 65 c.Assert(s.iface.Name(), Equals, "microceph") 66 } 67 68 func (s *MicroCephInterfaceSuite) TestSanitizeSlot(c *C) { 69 c.Assert(interfaces.BeforePrepareSlot(s.iface, s.slotInfo), IsNil) 70 slot := &snap.SlotInfo{ 71 Snap: &snap.Info{SuggestedName: "some-snap"}, 72 Name: "microceph", 73 Interface: "microceph", 74 } 75 76 c.Assert(interfaces.BeforePrepareSlot(s.iface, slot), IsNil) 77 } 78 79 func (s *MicroCephInterfaceSuite) TestSanitizePlug(c *C) { 80 c.Assert(interfaces.BeforePreparePlug(s.iface, s.plugInfo), IsNil) 81 } 82 83 func (s *MicroCephInterfaceSuite) TestAppArmorSpec(c *C) { 84 spec := &apparmor.Specification{} 85 c.Assert(spec.AddConnectedPlug(s.iface, s.plug, s.slot), IsNil) 86 c.Assert(spec.SecurityTags(), DeepEquals, []string{"snap.consumer.app"}) 87 c.Assert(spec.SnippetForTag("snap.consumer.app"), testutil.Contains, "/var/snap/microceph/common/state/control.socket rw,\n") 88 } 89 90 func (s *MicroCephInterfaceSuite) TestSecCompSpec(c *C) { 91 spec := &seccomp.Specification{} 92 c.Assert(spec.AddConnectedPlug(s.iface, s.plug, s.slot), IsNil) 93 c.Assert(spec.SecurityTags(), DeepEquals, []string{"snap.consumer.app"}) 94 c.Check(spec.SnippetForTag("snap.consumer.app"), testutil.Contains, "socket AF_NETLINK - NETLINK_GENERIC\n") 95 } 96 97 func (s *MicroCephInterfaceSuite) TestStaticInfo(c *C) { 98 si := interfaces.StaticInfoOf(s.iface) 99 c.Assert(si.ImplicitOnCore, Equals, false) 100 c.Assert(si.ImplicitOnClassic, Equals, false) 101 c.Assert(si.Summary, Equals, `allows access to the MicroCeph socket`) 102 c.Assert(si.BaseDeclarationSlots, testutil.Contains, "microceph") 103 } 104 105 func (s *MicroCephInterfaceSuite) TestAutoConnect(c *C) { 106 c.Check(s.iface.AutoConnect(nil, nil), Equals, true) 107 } 108 109 func (s *MicroCephInterfaceSuite) TestInterfaces(c *C) { 110 c.Check(builtin.Interfaces(), testutil.DeepContains, s.iface) 111 }