gitee.com/mysnapcore/mysnapd@v0.1.0/interfaces/builtin/multipass_support_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/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 MultipassSupportInterfaceSuite struct { 35 iface interfaces.Interface 36 slotInfo *snap.SlotInfo 37 slot *interfaces.ConnectedSlot 38 plugInfo *snap.PlugInfo 39 plug *interfaces.ConnectedPlug 40 } 41 42 const multipassSupportMockPlugSnapInfoYaml = `name: multipass 43 version: 1.0 44 apps: 45 app: 46 command: foo 47 plugs: [multipass-support] 48 ` 49 50 var _ = Suite(&MultipassSupportInterfaceSuite{ 51 iface: builtin.MustInterface("multipass-support"), 52 }) 53 54 func (s *MultipassSupportInterfaceSuite) SetUpTest(c *C) { 55 s.slotInfo = &snap.SlotInfo{ 56 Snap: &snap.Info{SuggestedName: "core", SnapType: snap.TypeOS}, 57 Name: "multipass-support", 58 Interface: "multipass-support", 59 } 60 s.slot = interfaces.NewConnectedSlot(s.slotInfo, nil, nil) 61 plugSnap := snaptest.MockInfo(c, multipassSupportMockPlugSnapInfoYaml, nil) 62 s.plugInfo = plugSnap.Plugs["multipass-support"] 63 s.plug = interfaces.NewConnectedPlug(s.plugInfo, nil, nil) 64 } 65 66 func (s *MultipassSupportInterfaceSuite) TestName(c *C) { 67 c.Assert(s.iface.Name(), Equals, "multipass-support") 68 } 69 70 func (s *MultipassSupportInterfaceSuite) TestUsedSecuritySystems(c *C) { 71 // connected plugs have a non-nil security snippet for apparmor 72 apparmorSpec := &apparmor.Specification{} 73 err := apparmorSpec.AddConnectedPlug(s.iface, s.plug, s.slot) 74 c.Assert(err, IsNil) 75 c.Assert(apparmorSpec.SecurityTags(), HasLen, 1) 76 77 // connected plugs have a non-nil security snippet for seccomp 78 seccompSpec := &seccomp.Specification{} 79 err = seccompSpec.AddConnectedPlug(s.iface, s.plug, s.slot) 80 c.Assert(err, IsNil) 81 c.Assert(seccompSpec.Snippets(), HasLen, 1) 82 } 83 84 func (s *MultipassSupportInterfaceSuite) TestConnectedPlugSnippet(c *C) { 85 apparmorSpec := &apparmor.Specification{} 86 err := apparmorSpec.AddConnectedPlug(s.iface, s.plug, s.slot) 87 c.Assert(err, IsNil) 88 c.Assert(apparmorSpec.SecurityTags(), DeepEquals, []string{"snap.multipass.app"}) 89 c.Assert(apparmorSpec.SnippetForTag("snap.multipass.app"), testutil.Contains, "/{,usr/}sbin/apparmor_parser ixr,\n") 90 91 seccompSpec := &seccomp.Specification{} 92 err = seccompSpec.AddConnectedPlug(s.iface, s.plug, s.slot) 93 c.Assert(err, IsNil) 94 c.Assert(seccompSpec.SecurityTags(), DeepEquals, []string{"snap.multipass.app"}) 95 c.Check(seccompSpec.SnippetForTag("snap.multipass.app"), testutil.Contains, "setgroups32 0 -\n") 96 } 97 98 func (s *MultipassSupportInterfaceSuite) TestSanitizeSlot(c *C) { 99 c.Assert(interfaces.BeforePrepareSlot(s.iface, s.slotInfo), IsNil) 100 } 101 102 func (s *MultipassSupportInterfaceSuite) TestSanitizePlug(c *C) { 103 c.Assert(interfaces.BeforePreparePlug(s.iface, s.plugInfo), IsNil) 104 } 105 106 func (s *MultipassSupportInterfaceSuite) TestInterfaces(c *C) { 107 c.Check(builtin.Interfaces(), testutil.DeepContains, s.iface) 108 }