gitee.com/mysnapcore/mysnapd@v0.1.0/interfaces/builtin/kernel_module_control_test.go (about) 1 // -*- Mode: Go; indent-tabs-mode: t -*- 2 3 /* 4 * Copyright (C) 2016-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 "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/testutil" 35 ) 36 37 type KernelModuleControlInterfaceSuite struct { 38 iface interfaces.Interface 39 slotInfo *snap.SlotInfo 40 slot *interfaces.ConnectedSlot 41 plugInfo *snap.PlugInfo 42 plug *interfaces.ConnectedPlug 43 } 44 45 var _ = Suite(&KernelModuleControlInterfaceSuite{ 46 iface: builtin.MustInterface("kernel-module-control"), 47 }) 48 49 const kernelmodctlConsumerYaml = `name: consumer 50 version: 0 51 apps: 52 app: 53 plugs: [kernel-module-control] 54 ` 55 56 const kernelmodctlCoreYaml = `name: core 57 version: 0 58 type: os 59 slots: 60 kernel-module-control: 61 ` 62 63 func (s *KernelModuleControlInterfaceSuite) SetUpTest(c *C) { 64 s.plug, s.plugInfo = MockConnectedPlug(c, kernelmodctlConsumerYaml, nil, "kernel-module-control") 65 s.slot, s.slotInfo = MockConnectedSlot(c, kernelmodctlCoreYaml, nil, "kernel-module-control") 66 } 67 68 func (s *KernelModuleControlInterfaceSuite) TestName(c *C) { 69 c.Assert(s.iface.Name(), Equals, "kernel-module-control") 70 } 71 72 func (s *KernelModuleControlInterfaceSuite) TestSanitizeSlot(c *C) { 73 c.Assert(interfaces.BeforePrepareSlot(s.iface, s.slotInfo), IsNil) 74 } 75 76 func (s *KernelModuleControlInterfaceSuite) TestSanitizePlug(c *C) { 77 c.Assert(interfaces.BeforePreparePlug(s.iface, s.plugInfo), IsNil) 78 } 79 80 func (s *KernelModuleControlInterfaceSuite) TestAppArmorSpec(c *C) { 81 spec := &apparmor.Specification{} 82 c.Assert(spec.AddConnectedPlug(s.iface, s.plug, s.slot), IsNil) 83 c.Check(spec.SuppressSysModuleCapability(), Equals, false) 84 c.Check(spec.UsesSysModuleCapability(), Equals, true) 85 c.Assert(spec.SecurityTags(), DeepEquals, []string{"snap.consumer.app"}) 86 c.Assert(spec.SnippetForTag("snap.consumer.app"), testutil.Contains, "capability sys_module,") 87 } 88 89 func (s *KernelModuleControlInterfaceSuite) TestSecCompSpec(c *C) { 90 spec := &seccomp.Specification{} 91 c.Assert(spec.AddConnectedPlug(s.iface, s.plug, s.slot), IsNil) 92 c.Assert(spec.SecurityTags(), DeepEquals, []string{"snap.consumer.app"}) 93 c.Assert(spec.SnippetForTag("snap.consumer.app"), testutil.Contains, "finit_module\n") 94 } 95 96 func (s *KernelModuleControlInterfaceSuite) TestUDevSpec(c *C) { 97 spec := &udev.Specification{} 98 c.Assert(spec.AddConnectedPlug(s.iface, s.plug, s.slot), IsNil) 99 c.Assert(spec.Snippets(), HasLen, 2) 100 c.Assert(spec.Snippets(), testutil.Contains, `# kernel-module-control 101 KERNEL=="mem", TAG+="snap_consumer_app"`) 102 c.Assert(spec.Snippets(), testutil.Contains, fmt.Sprintf(`TAG=="snap_consumer_app", RUN+="%v/snap-device-helper $env{ACTION} snap_consumer_app $devpath $major:$minor"`, dirs.DistroLibExecDir)) 103 } 104 105 func (s *KernelModuleControlInterfaceSuite) TestStaticInfo(c *C) { 106 si := interfaces.StaticInfoOf(s.iface) 107 c.Assert(si.ImplicitOnCore, Equals, true) 108 c.Assert(si.ImplicitOnClassic, Equals, true) 109 c.Assert(si.Summary, Equals, `allows insertion, removal and querying of kernel modules`) 110 c.Assert(si.BaseDeclarationSlots, testutil.Contains, "kernel-module-control") 111 } 112 113 func (s *KernelModuleControlInterfaceSuite) TestAutoConnect(c *C) { 114 c.Assert(s.iface.AutoConnect(s.plugInfo, s.slotInfo), Equals, true) 115 } 116 117 func (s *KernelModuleControlInterfaceSuite) TestInterfaces(c *C) { 118 c.Check(builtin.Interfaces(), testutil.DeepContains, s.iface) 119 }