gitee.com/mysnapcore/mysnapd@v0.1.0/interfaces/builtin/mir_test.go (about) 1 // -*- Mode: Go; indent-tabs-mode: t -*- 2 3 /* 4 * Copyright (C) 2016-2018 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 "fmt" 24 25 . "gopkg.in/check.v1" 26 27 "gitee.com/mysnapcore/mysnapd/dirs" 28 "gitee.com/mysnapcore/mysnapd/interfaces" 29 "gitee.com/mysnapcore/mysnapd/interfaces/apparmor" 30 "gitee.com/mysnapcore/mysnapd/interfaces/builtin" 31 "gitee.com/mysnapcore/mysnapd/interfaces/seccomp" 32 "gitee.com/mysnapcore/mysnapd/interfaces/udev" 33 "gitee.com/mysnapcore/mysnapd/snap" 34 "gitee.com/mysnapcore/mysnapd/snap/snaptest" 35 "gitee.com/mysnapcore/mysnapd/testutil" 36 ) 37 38 type MirInterfaceSuite struct { 39 iface interfaces.Interface 40 coreSlotInfo *snap.SlotInfo 41 coreSlot *interfaces.ConnectedSlot 42 classicSlotInfo *snap.SlotInfo 43 classicSlot *interfaces.ConnectedSlot 44 plugInfo *snap.PlugInfo 45 plug *interfaces.ConnectedPlug 46 } 47 48 var _ = Suite(&MirInterfaceSuite{ 49 iface: builtin.MustInterface("mir"), 50 }) 51 52 func (s *MirInterfaceSuite) SetUpTest(c *C) { 53 // a pulseaudio slot on the core snap (as automatically added on classic) 54 const mirMockClassicSlotSnapInfoYaml = `name: core 55 version: 0 56 type: os 57 slots: 58 mir: 59 interface: mir 60 ` 61 const mirMockSlotSnapInfoYaml = `name: mir-server 62 version: 1.0 63 slots: 64 mir: 65 interface: mir 66 apps: 67 mir: 68 command: foo 69 slots: [mir] 70 ` 71 const mockPlugSnapInfoYaml = `name: other 72 version: 1.0 73 apps: 74 app2: 75 command: foo 76 plugs: [mir] 77 ` 78 // mir snap with mir-server slot on an core/all-snap install. 79 snapInfo := snaptest.MockInfo(c, mirMockSlotSnapInfoYaml, nil) 80 s.coreSlotInfo = snapInfo.Slots["mir"] 81 s.coreSlot = interfaces.NewConnectedSlot(s.coreSlotInfo, nil, nil) 82 // mir slot on a core snap in a classic install. 83 snapInfo = snaptest.MockInfo(c, mirMockClassicSlotSnapInfoYaml, nil) 84 s.classicSlotInfo = snapInfo.Slots["mir"] 85 s.classicSlot = interfaces.NewConnectedSlot(s.classicSlotInfo, nil, nil) 86 // snap with the mir plug 87 snapInfo = snaptest.MockInfo(c, mockPlugSnapInfoYaml, nil) 88 s.plugInfo = snapInfo.Plugs["mir"] 89 s.plug = interfaces.NewConnectedPlug(s.plugInfo, nil, nil) 90 } 91 92 func (s *MirInterfaceSuite) TestName(c *C) { 93 c.Assert(s.iface.Name(), Equals, "mir") 94 } 95 96 func (s *MirInterfaceSuite) TestUsedSecuritySystems(c *C) { 97 apparmorSpec := &apparmor.Specification{} 98 err := apparmorSpec.AddPermanentSlot(s.iface, s.coreSlotInfo) 99 c.Assert(err, IsNil) 100 c.Assert(apparmorSpec.SecurityTags(), DeepEquals, []string{"snap.mir-server.mir"}) 101 c.Assert(apparmorSpec.SnippetForTag("snap.mir-server.mir"), testutil.Contains, "capability sys_tty_config") 102 103 apparmorSpec = &apparmor.Specification{} 104 err = apparmorSpec.AddPermanentSlot(s.iface, s.classicSlotInfo) 105 c.Assert(err, IsNil) 106 c.Assert(apparmorSpec.SecurityTags(), HasLen, 0) 107 108 apparmorSpec = &apparmor.Specification{} 109 err = apparmorSpec.AddConnectedSlot(s.iface, s.plug, s.coreSlot) 110 c.Assert(err, IsNil) 111 c.Assert(apparmorSpec.SecurityTags(), DeepEquals, []string{"snap.mir-server.mir"}) 112 c.Assert(apparmorSpec.SnippetForTag("snap.mir-server.mir"), testutil.Contains, "unix (receive, send) type=seqpacket addr=none peer=(label=\"snap.other") 113 114 apparmorSpec = &apparmor.Specification{} 115 err = apparmorSpec.AddConnectedPlug(s.iface, s.plug, s.coreSlot) 116 c.Assert(err, IsNil) 117 c.Assert(apparmorSpec.SecurityTags(), DeepEquals, []string{"snap.other.app2"}) 118 c.Assert(apparmorSpec.SnippetForTag("snap.other.app2"), testutil.Contains, "/run/mir_socket rw,") 119 } 120 121 func (s *MirInterfaceSuite) TestSecComp(c *C) { 122 seccompSpec := &seccomp.Specification{} 123 err := seccompSpec.AddPermanentSlot(s.iface, s.coreSlotInfo) 124 c.Assert(err, IsNil) 125 c.Assert(seccompSpec.SecurityTags(), DeepEquals, []string{"snap.mir-server.mir"}) 126 c.Check(seccompSpec.SnippetForTag("snap.mir-server.mir"), testutil.Contains, "listen\n") 127 } 128 129 func (s *MirInterfaceSuite) TestSecCompOnClassic(c *C) { 130 seccompSpec := &seccomp.Specification{} 131 err := seccompSpec.AddPermanentSlot(s.iface, s.classicSlotInfo) 132 c.Assert(err, IsNil) 133 snippets := seccompSpec.Snippets() 134 // no permanent seccomp snippet for the slot 135 c.Assert(len(snippets), Equals, 0) 136 } 137 138 func (s *MirInterfaceSuite) TestUDevSpec(c *C) { 139 udevSpec := &udev.Specification{} 140 c.Assert(udevSpec.AddPermanentSlot(s.iface, s.coreSlotInfo), IsNil) 141 c.Assert(udevSpec.Snippets(), HasLen, 6) 142 c.Assert(udevSpec.Snippets(), testutil.Contains, `# mir 143 KERNEL=="tty[0-9]*", TAG+="snap_mir-server_mir"`) 144 c.Assert(udevSpec.Snippets(), testutil.Contains, `# mir 145 KERNEL=="mice", TAG+="snap_mir-server_mir"`) 146 c.Assert(udevSpec.Snippets(), testutil.Contains, `# mir 147 KERNEL=="mouse[0-9]*", TAG+="snap_mir-server_mir"`) 148 c.Assert(udevSpec.Snippets(), testutil.Contains, `# mir 149 KERNEL=="event[0-9]*", TAG+="snap_mir-server_mir"`) 150 c.Assert(udevSpec.Snippets(), testutil.Contains, `# mir 151 KERNEL=="ts[0-9]*", TAG+="snap_mir-server_mir"`) 152 c.Assert(udevSpec.Snippets(), testutil.Contains, fmt.Sprintf(`TAG=="snap_mir-server_mir", RUN+="%v/snap-device-helper $env{ACTION} snap_mir-server_mir $devpath $major:$minor"`, dirs.DistroLibExecDir)) 153 c.Assert(udevSpec.TriggeredSubsystems(), DeepEquals, []string{"input"}) 154 } 155 156 func (s *MirInterfaceSuite) TestInterfaces(c *C) { 157 c.Check(builtin.Interfaces(), testutil.DeepContains, s.iface) 158 }