github.com/meulengracht/snapd@v0.0.0-20210719210640-8bde69bcc84e/interfaces/builtin/login_session_observe_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 "github.com/snapcore/snapd/interfaces" 26 "github.com/snapcore/snapd/interfaces/apparmor" 27 "github.com/snapcore/snapd/interfaces/builtin" 28 "github.com/snapcore/snapd/snap" 29 "github.com/snapcore/snapd/snap/snaptest" 30 "github.com/snapcore/snapd/testutil" 31 ) 32 33 type LoginSessionObserveSuite struct { 34 iface interfaces.Interface 35 slotInfo *snap.SlotInfo 36 slot *interfaces.ConnectedSlot 37 plugInfo *snap.PlugInfo 38 plug *interfaces.ConnectedPlug 39 } 40 41 var _ = Suite(&LoginSessionObserveSuite{ 42 iface: builtin.MustInterface("login-session-observe"), 43 }) 44 45 const loginObserveMockPlugSnapInfo = `name: other 46 version: 1.0 47 apps: 48 app2: 49 command: foo 50 plugs: [login-session-observe] 51 ` 52 53 func (s *LoginSessionObserveSuite) SetUpTest(c *C) { 54 s.slotInfo = &snap.SlotInfo{ 55 Snap: &snap.Info{SuggestedName: "core", SnapType: snap.TypeOS}, 56 Name: "login-session-observe", 57 Interface: "login-session-observe", 58 Apps: map[string]*snap.AppInfo{ 59 "app1": { 60 Snap: &snap.Info{ 61 SuggestedName: "core", 62 }, 63 Name: "app1"}}, 64 } 65 s.slot = interfaces.NewConnectedSlot(s.slotInfo, nil, nil) 66 67 plugSnap := snaptest.MockInfo(c, loginObserveMockPlugSnapInfo, nil) 68 s.plugInfo = plugSnap.Plugs["login-session-observe"] 69 s.plug = interfaces.NewConnectedPlug(s.plugInfo, nil, nil) 70 } 71 72 func (s *LoginSessionObserveSuite) TestName(c *C) { 73 c.Assert(s.iface.Name(), Equals, "login-session-observe") 74 } 75 76 func (s *LoginSessionObserveSuite) TestSanitizeSlot(c *C) { 77 c.Assert(interfaces.BeforePrepareSlot(s.iface, s.slotInfo), IsNil) 78 } 79 80 func (s *LoginSessionObserveSuite) TestSanitizePlug(c *C) { 81 c.Assert(interfaces.BeforePreparePlug(s.iface, s.plugInfo), IsNil) 82 } 83 84 func (s *LoginSessionObserveSuite) TestAppArmor(c *C) { 85 // connected plugs have a non-nil security snippet for apparmor 86 apparmorSpec := &apparmor.Specification{} 87 err := apparmorSpec.AddConnectedPlug(s.iface, s.plug, s.slot) 88 c.Assert(err, IsNil) 89 c.Assert(apparmorSpec.SecurityTags(), DeepEquals, []string{"snap.other.app2"}) 90 c.Assert(apparmorSpec.SnippetForTag("snap.other.app2"), testutil.Contains, "/{,usr/}bin/who") 91 } 92 93 func (s *LoginSessionObserveSuite) TestInterfaces(c *C) { 94 c.Check(builtin.Interfaces(), testutil.DeepContains, s.iface) 95 }