gitee.com/mysnapcore/mysnapd@v0.1.0/interfaces/builtin/cifs_mount_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/interfaces"
    26  	"gitee.com/mysnapcore/mysnapd/interfaces/apparmor"
    27  	"gitee.com/mysnapcore/mysnapd/interfaces/builtin"
    28  	"gitee.com/mysnapcore/mysnapd/interfaces/seccomp"
    29  	"gitee.com/mysnapcore/mysnapd/snap"
    30  	"gitee.com/mysnapcore/mysnapd/testutil"
    31  )
    32  
    33  type CifsMountInterfaceSuite struct {
    34  	iface    interfaces.Interface
    35  	slotInfo *snap.SlotInfo
    36  	slot     *interfaces.ConnectedSlot
    37  	plugInfo *snap.PlugInfo
    38  	plug     *interfaces.ConnectedPlug
    39  }
    40  
    41  const cifsMountConsumerYaml = `name: consumer
    42  version: 0
    43  apps:
    44   app:
    45    plugs: [cifs-mount]
    46  `
    47  
    48  const cifsMountCoreYaml = `name: core
    49  version: 0
    50  type: os
    51  slots:
    52    cifs-mount:
    53  `
    54  
    55  var _ = Suite(&CifsMountInterfaceSuite{
    56  	iface: builtin.MustInterface("cifs-mount"),
    57  })
    58  
    59  func (s *CifsMountInterfaceSuite) SetUpTest(c *C) {
    60  	s.plug, s.plugInfo = MockConnectedPlug(c, cifsMountConsumerYaml, nil, "cifs-mount")
    61  	s.slot, s.slotInfo = MockConnectedSlot(c, cifsMountCoreYaml, nil, "cifs-mount")
    62  }
    63  
    64  func (s *CifsMountInterfaceSuite) TestName(c *C) {
    65  	c.Assert(s.iface.Name(), Equals, "cifs-mount")
    66  }
    67  
    68  func (s *CifsMountInterfaceSuite) TestSanitizeSlot(c *C) {
    69  	c.Assert(interfaces.BeforePrepareSlot(s.iface, s.slotInfo), IsNil)
    70  }
    71  
    72  func (s *CifsMountInterfaceSuite) TestSanitizePlug(c *C) {
    73  	c.Assert(interfaces.BeforePreparePlug(s.iface, s.plugInfo), IsNil)
    74  }
    75  
    76  func (s *CifsMountInterfaceSuite) TestAppArmorSpec(c *C) {
    77  	spec := &apparmor.Specification{}
    78  	c.Assert(spec.AddConnectedPlug(s.iface, s.plug, s.slot), IsNil)
    79  	c.Assert(spec.SecurityTags(), DeepEquals, []string{"snap.consumer.app"})
    80  	c.Assert(spec.SnippetForTag("snap.consumer.app"), testutil.Contains, `#deny /run/mount/utab w,`)
    81  }
    82  
    83  func (s *CifsMountInterfaceSuite) TestSecCompSpec(c *C) {
    84  	spec := &seccomp.Specification{}
    85  	c.Assert(spec.AddConnectedPlug(s.iface, s.plug, s.slot), IsNil)
    86  	c.Assert(spec.SecurityTags(), DeepEquals, []string{"snap.consumer.app"})
    87  	c.Assert(spec.SnippetForTag("snap.consumer.app"), testutil.Contains, "umount2\n")
    88  }
    89  
    90  func (s *CifsMountInterfaceSuite) TestStaticInfo(c *C) {
    91  	si := interfaces.StaticInfoOf(s.iface)
    92  	c.Assert(si.ImplicitOnCore, Equals, true)
    93  	c.Assert(si.ImplicitOnClassic, Equals, true)
    94  	c.Assert(si.Summary, Equals, `allows mounting and unmounting CIFS filesystems`)
    95  	c.Assert(si.BaseDeclarationSlots, testutil.Contains, "cifs-mount")
    96  }
    97  
    98  func (s *CifsMountInterfaceSuite) TestInterfaces(c *C) {
    99  	c.Check(builtin.Interfaces(), testutil.DeepContains, s.iface)
   100  }