github.com/bugraaydogar/snapd@v0.0.0-20210315170335-8c70bb858939/interfaces/builtin/fuse_support_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 "github.com/snapcore/snapd/dirs" 28 "github.com/snapcore/snapd/interfaces" 29 "github.com/snapcore/snapd/interfaces/apparmor" 30 "github.com/snapcore/snapd/interfaces/builtin" 31 "github.com/snapcore/snapd/interfaces/seccomp" 32 "github.com/snapcore/snapd/interfaces/udev" 33 "github.com/snapcore/snapd/release" 34 "github.com/snapcore/snapd/snap" 35 "github.com/snapcore/snapd/testutil" 36 ) 37 38 type FuseSupportInterfaceSuite struct { 39 iface interfaces.Interface 40 slotInfo *snap.SlotInfo 41 slot *interfaces.ConnectedSlot 42 plugInfo *snap.PlugInfo 43 plug *interfaces.ConnectedPlug 44 } 45 46 const fuseSupportConsumerYaml = `name: consumer 47 version: 0 48 apps: 49 app: 50 plugs: [fuse-support] 51 ` 52 53 const fuseSupportCoreYaml = `name: core 54 version: 0 55 type: os 56 slots: 57 fuse-support: 58 ` 59 60 var _ = Suite(&FuseSupportInterfaceSuite{ 61 iface: builtin.MustInterface("fuse-support"), 62 }) 63 64 func (s *FuseSupportInterfaceSuite) SetUpTest(c *C) { 65 s.plug, s.plugInfo = MockConnectedPlug(c, fuseSupportConsumerYaml, nil, "fuse-support") 66 s.slot, s.slotInfo = MockConnectedSlot(c, fuseSupportCoreYaml, nil, "fuse-support") 67 } 68 69 func (s *FuseSupportInterfaceSuite) TestName(c *C) { 70 c.Assert(s.iface.Name(), Equals, "fuse-support") 71 } 72 73 func (s *FuseSupportInterfaceSuite) TestSanitizeSlot(c *C) { 74 c.Assert(interfaces.BeforePrepareSlot(s.iface, s.slotInfo), IsNil) 75 } 76 77 func (s *FuseSupportInterfaceSuite) TestSanitizePlug(c *C) { 78 c.Assert(interfaces.BeforePreparePlug(s.iface, s.plugInfo), IsNil) 79 } 80 81 func (s *FuseSupportInterfaceSuite) TestAppArmorSpec(c *C) { 82 spec := &apparmor.Specification{} 83 c.Assert(spec.AddConnectedPlug(s.iface, s.plug, s.slot), IsNil) 84 c.Assert(spec.SecurityTags(), DeepEquals, []string{"snap.consumer.app"}) 85 c.Assert(spec.SnippetForTag("snap.consumer.app"), testutil.Contains, `/dev/fuse`) 86 } 87 88 func (s *FuseSupportInterfaceSuite) TestSecCompSpec(c *C) { 89 spec := &seccomp.Specification{} 90 c.Assert(spec.AddConnectedPlug(s.iface, s.plug, s.slot), IsNil) 91 c.Assert(spec.SecurityTags(), DeepEquals, []string{"snap.consumer.app"}) 92 c.Assert(spec.SnippetForTag("snap.consumer.app"), testutil.Contains, "mount\n") 93 } 94 95 func (s *FuseSupportInterfaceSuite) TestUDevSpec(c *C) { 96 spec := &udev.Specification{} 97 c.Assert(spec.AddConnectedPlug(s.iface, s.plug, s.slot), IsNil) 98 c.Assert(spec.Snippets(), HasLen, 2) 99 c.Assert(spec.Snippets(), testutil.Contains, `# fuse-support 100 KERNEL=="fuse", TAG+="snap_consumer_app"`) 101 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)) 102 } 103 104 func (s *FuseSupportInterfaceSuite) TestStaticInfo(c *C) { 105 si := interfaces.StaticInfoOf(s.iface) 106 c.Assert(si.ImplicitOnCore, Equals, true) 107 c.Assert(si.ImplicitOnClassic, Equals, !(release.ReleaseInfo.ID == "ubuntu" && release.ReleaseInfo.VersionID == "14.04")) 108 c.Assert(si.Summary, Equals, `allows access to the FUSE file system`) 109 c.Assert(si.BaseDeclarationSlots, testutil.Contains, "fuse-support") 110 } 111 112 func (s *FuseSupportInterfaceSuite) TestAutoConnect(c *C) { 113 c.Assert(s.iface.AutoConnect(s.plugInfo, s.slotInfo), Equals, true) 114 } 115 116 func (s *FuseSupportInterfaceSuite) TestInterfaces(c *C) { 117 c.Check(builtin.Interfaces(), testutil.DeepContains, s.iface) 118 }