gitee.com/mysnapcore/mysnapd@v0.1.0/interfaces/builtin/core_support_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 . "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 CoreSupportInterfaceSuite 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(&CoreSupportInterfaceSuite{ 43 iface: builtin.MustInterface("core-support"), 44 }) 45 46 func (s *CoreSupportInterfaceSuite) SetUpTest(c *C) { 47 const mockPlugSnapInfo = `name: other 48 version: 1.0 49 hooks: 50 prepare-device: 51 plugs: [core-support] 52 ` 53 s.slotInfo = &snap.SlotInfo{ 54 Snap: &snap.Info{SuggestedName: "core", SnapType: snap.TypeOS}, 55 Name: "core-support", 56 Interface: "core-support", 57 } 58 s.slot = interfaces.NewConnectedSlot(s.slotInfo, nil, nil) 59 60 plugSnap := snaptest.MockInfo(c, mockPlugSnapInfo, nil) 61 s.plugInfo = plugSnap.Plugs["core-support"] 62 s.plug = interfaces.NewConnectedPlug(s.plugInfo, nil, nil) 63 } 64 65 func (s *CoreSupportInterfaceSuite) TestName(c *C) { 66 c.Assert(s.iface.Name(), Equals, "core-support") 67 } 68 69 func (s *CoreSupportInterfaceSuite) TestSanitizeSlot(c *C) { 70 c.Assert(interfaces.BeforePrepareSlot(s.iface, s.slotInfo), IsNil) 71 } 72 73 func (s *CoreSupportInterfaceSuite) TestSanitizePlug(c *C) { 74 c.Assert(interfaces.BeforePreparePlug(s.iface, s.plugInfo), IsNil) 75 } 76 77 func (s *CoreSupportInterfaceSuite) TestNoSecuritySystems(c *C) { 78 apparmorSpec := &apparmor.Specification{} 79 c.Assert(apparmorSpec.AddConnectedPlug(s.iface, s.plug, s.slot), IsNil) 80 c.Assert(apparmorSpec.SecurityTags(), HasLen, 0) 81 seccompSpec := &seccomp.Specification{} 82 c.Assert(seccompSpec.AddConnectedPlug(s.iface, s.plug, s.slot), IsNil) 83 c.Assert(seccompSpec.SecurityTags(), HasLen, 0) 84 } 85 86 func (s *CoreSupportInterfaceSuite) TestInterfaces(c *C) { 87 c.Check(builtin.Interfaces(), testutil.DeepContains, s.iface) 88 }