github.com/bugraaydogar/snapd@v0.0.0-20210315170335-8c70bb858939/interfaces/builtin/thumbnailer_service_test.go (about) 1 // -*- Mode: Go; indent-tabs-mode: t -*- 2 3 /* 4 * Copyright (C) 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 "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 ThumbnailerServiceInterfaceSuite struct { 34 iface interfaces.Interface 35 coreSlotInfo *snap.SlotInfo 36 coreSlot *interfaces.ConnectedSlot 37 classicSlotInfo *snap.SlotInfo 38 classicSlot *interfaces.ConnectedSlot 39 plugInfo *snap.PlugInfo 40 plug *interfaces.ConnectedPlug 41 } 42 43 var _ = Suite(&ThumbnailerServiceInterfaceSuite{ 44 iface: builtin.MustInterface("thumbnailer-service"), 45 }) 46 47 func (s *ThumbnailerServiceInterfaceSuite) SetUpTest(c *C) { 48 // a thumbnailer slot on a thumbnailer snap 49 const thumbnailerServiceMockCoreSlotSnapInfoYaml = `name: thumbnailer-service 50 version: 1.0 51 apps: 52 app: 53 command: foo 54 slots: [thumbnailer-service] 55 ` 56 // a thumbnailer-service slot on the core snap (as automatically added on classic) 57 const thumbnailerServiceMockClassicSlotSnapInfoYaml = `name: core 58 version: 0 59 type: os 60 slots: 61 thumbnailer-service: 62 interface: thumbnailer-service 63 ` 64 const mockPlugSnapInfo = `name: client 65 version: 1.0 66 apps: 67 app: 68 command: foo 69 plugs: [thumbnailer-service] 70 ` 71 // thumbnailer-service snap with thumbnailer-service slot on an core/all-snap install. 72 snapInfo := snaptest.MockInfo(c, thumbnailerServiceMockCoreSlotSnapInfoYaml, nil) 73 s.coreSlotInfo = snapInfo.Slots["thumbnailer-service"] 74 s.coreSlot = interfaces.NewConnectedSlot(s.coreSlotInfo, nil, nil) 75 // thumbnailer-service slot on a core snap in a classic install. 76 snapInfo = snaptest.MockInfo(c, thumbnailerServiceMockClassicSlotSnapInfoYaml, nil) 77 s.classicSlotInfo = snapInfo.Slots["thumbnailer-service"] 78 s.classicSlot = interfaces.NewConnectedSlot(s.classicSlotInfo, nil, nil) 79 80 plugSnap := snaptest.MockInfo(c, mockPlugSnapInfo, nil) 81 s.plugInfo = plugSnap.Plugs["thumbnailer-service"] 82 s.plug = interfaces.NewConnectedPlug(s.plugInfo, nil, nil) 83 } 84 85 func (s *ThumbnailerServiceInterfaceSuite) TestName(c *C) { 86 c.Check(s.iface.Name(), Equals, "thumbnailer-service") 87 } 88 89 func (s *ThumbnailerServiceInterfaceSuite) TestUsedSecuritySystems(c *C) { 90 // connected slots have a non-nil security snippet for apparmor 91 apparmorSpec := &apparmor.Specification{} 92 err := apparmorSpec.AddConnectedSlot(s.iface, s.plug, s.coreSlot) 93 c.Assert(err, IsNil) 94 c.Assert(apparmorSpec.SecurityTags(), DeepEquals, []string{"snap.thumbnailer-service.app"}) 95 c.Assert(apparmorSpec.SnippetForTag("snap.thumbnailer-service.app"), testutil.Contains, `interface=com.canonical.Thumbnailer`) 96 97 // slots have no permanent snippet on classic 98 apparmorSpec = &apparmor.Specification{} 99 err = apparmorSpec.AddConnectedSlot(s.iface, s.plug, s.classicSlot) 100 c.Assert(err, IsNil) 101 c.Assert(apparmorSpec.SecurityTags(), HasLen, 0) 102 103 // slots have a permanent non-nil security snippet for apparmor 104 apparmorSpec = &apparmor.Specification{} 105 err = apparmorSpec.AddPermanentSlot(s.iface, s.coreSlotInfo) 106 c.Assert(err, IsNil) 107 c.Assert(apparmorSpec.SecurityTags(), DeepEquals, []string{"snap.thumbnailer-service.app"}) 108 c.Assert(apparmorSpec.SnippetForTag("snap.thumbnailer-service.app"), testutil.Contains, `member={RequestName,ReleaseName,GetConnectionCredentials}`) 109 } 110 111 func (s *ThumbnailerServiceInterfaceSuite) TestSlotGrantedAccessToPlugFiles(c *C) { 112 apparmorSpec := &apparmor.Specification{} 113 err := apparmorSpec.AddConnectedSlot(s.iface, s.plug, s.coreSlot) 114 c.Assert(err, IsNil) 115 c.Assert(apparmorSpec.SecurityTags(), DeepEquals, []string{"snap.thumbnailer-service.app"}) 116 snippet := apparmorSpec.SnippetForTag("snap.thumbnailer-service.app") 117 c.Check(snippet, testutil.Contains, `@{INSTALL_DIR}/client/**`) 118 c.Check(snippet, testutil.Contains, `@{HOME}/snap/client/**`) 119 c.Check(snippet, testutil.Contains, `/var/snap/client/**`) 120 } 121 122 func (s *ThumbnailerServiceInterfaceSuite) TestInterfaces(c *C) { 123 c.Check(builtin.Interfaces(), testutil.DeepContains, s.iface) 124 }