gitee.com/mysnapcore/mysnapd@v0.1.0/interfaces/builtin/unity8_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 . "gopkg.in/check.v1" 24 25 "gitee.com/mysnapcore/mysnapd/dirs" 26 "gitee.com/mysnapcore/mysnapd/interfaces" 27 "gitee.com/mysnapcore/mysnapd/interfaces/apparmor" 28 "gitee.com/mysnapcore/mysnapd/interfaces/builtin" 29 "gitee.com/mysnapcore/mysnapd/snap" 30 "gitee.com/mysnapcore/mysnapd/snap/snaptest" 31 "gitee.com/mysnapcore/mysnapd/testutil" 32 ) 33 34 type unity8InterfaceSuite 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(&unity8InterfaceSuite{ 43 iface: builtin.MustInterface("unity8"), 44 }) 45 46 func (s *unity8InterfaceSuite) SetUpTest(c *C) { 47 const mockPlugSnapInfoYaml = `name: other 48 version: 1.0 49 apps: 50 unity8-app: 51 command: foo 52 plugs: [unity8] 53 ` 54 dirs.SetRootDir(c.MkDir()) 55 s.slotInfo = &snap.SlotInfo{ 56 Snap: &snap.Info{SuggestedName: "unity8-session"}, 57 Name: "unity8-session", 58 Interface: "unity8", 59 } 60 s.slot = interfaces.NewConnectedSlot(s.slotInfo, nil, nil) 61 plugSnap := snaptest.MockInfo(c, mockPlugSnapInfoYaml, nil) 62 s.plugInfo = plugSnap.Plugs["unity8"] 63 s.plug = interfaces.NewConnectedPlug(s.plugInfo, nil, nil) 64 65 } 66 67 func (s *unity8InterfaceSuite) TearDownTest(c *C) { 68 dirs.SetRootDir("") 69 } 70 71 func (s *unity8InterfaceSuite) TestName(c *C) { 72 c.Assert(s.iface.Name(), Equals, "unity8") 73 } 74 75 func (s *unity8InterfaceSuite) TestUsedSecuritySystems(c *C) { 76 // connected plugs have a non-nil security snippet for apparmor 77 apparmorSpec := &apparmor.Specification{} 78 err := apparmorSpec.AddConnectedPlug(s.iface, s.plug, s.slot) 79 c.Assert(err, IsNil) 80 c.Assert(apparmorSpec.SecurityTags(), DeepEquals, []string{"snap.other.unity8-app"}) 81 c.Check(apparmorSpec.SnippetForTag("snap.other.unity8-app"), testutil.Contains, "name=com.canonical.URLDispatcher") 82 } 83 84 func (s *unity8InterfaceSuite) TestSecurityTags(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.other.unity8-app"}) 89 c.Check(apparmorSpec.SnippetForTag("snap.other.unity8-app"), testutil.Contains, "label=\"snap.unity8-session.*\"") 90 } 91 92 func (s *unity8InterfaceSuite) TestInterfaces(c *C) { 93 c.Check(builtin.Interfaces(), testutil.DeepContains, s.iface) 94 }