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