gitee.com/mysnapcore/mysnapd@v0.1.0/interfaces/builtin/bluetooth_control_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  	"gitee.com/mysnapcore/mysnapd/dirs"
    28  	"gitee.com/mysnapcore/mysnapd/interfaces"
    29  	"gitee.com/mysnapcore/mysnapd/interfaces/apparmor"
    30  	"gitee.com/mysnapcore/mysnapd/interfaces/builtin"
    31  	"gitee.com/mysnapcore/mysnapd/interfaces/seccomp"
    32  	"gitee.com/mysnapcore/mysnapd/interfaces/udev"
    33  	"gitee.com/mysnapcore/mysnapd/snap"
    34  	"gitee.com/mysnapcore/mysnapd/snap/snaptest"
    35  	"gitee.com/mysnapcore/mysnapd/testutil"
    36  )
    37  
    38  type BluetoothControlInterfaceSuite struct {
    39  	iface    interfaces.Interface
    40  	slot     *interfaces.ConnectedSlot
    41  	slotInfo *snap.SlotInfo
    42  	plug     *interfaces.ConnectedPlug
    43  	plugInfo *snap.PlugInfo
    44  }
    45  
    46  const btcontrolMockPlugSnapInfoYaml = `name: other
    47  version: 1.0
    48  apps:
    49   app2:
    50    command: foo
    51    plugs: [bluetooth-control]
    52  `
    53  
    54  var _ = Suite(&BluetoothControlInterfaceSuite{
    55  	iface: builtin.MustInterface("bluetooth-control"),
    56  })
    57  
    58  func (s *BluetoothControlInterfaceSuite) SetUpTest(c *C) {
    59  	s.slotInfo = &snap.SlotInfo{
    60  		Snap:      &snap.Info{SuggestedName: "core", SnapType: snap.TypeOS},
    61  		Name:      "bluetooth-control",
    62  		Interface: "bluetooth-control",
    63  		Apps: map[string]*snap.AppInfo{
    64  			"app1": {
    65  				Snap: &snap.Info{
    66  					SuggestedName: "core",
    67  				},
    68  				Name: "app1"}},
    69  	}
    70  	s.slot = interfaces.NewConnectedSlot(s.slotInfo, nil, nil)
    71  	plugSnap := snaptest.MockInfo(c, btcontrolMockPlugSnapInfoYaml, nil)
    72  	s.plugInfo = plugSnap.Plugs["bluetooth-control"]
    73  	s.plug = interfaces.NewConnectedPlug(s.plugInfo, nil, nil)
    74  }
    75  
    76  func (s *BluetoothControlInterfaceSuite) TestName(c *C) {
    77  	c.Assert(s.iface.Name(), Equals, "bluetooth-control")
    78  }
    79  
    80  func (s *BluetoothControlInterfaceSuite) TestSanitizeSlot(c *C) {
    81  	c.Assert(interfaces.BeforePrepareSlot(s.iface, s.slotInfo), IsNil)
    82  }
    83  
    84  func (s *BluetoothControlInterfaceSuite) TestSanitizePlug(c *C) {
    85  	c.Assert(interfaces.BeforePreparePlug(s.iface, s.plugInfo), IsNil)
    86  }
    87  
    88  func (s *BluetoothControlInterfaceSuite) TestAppArmorSpec(c *C) {
    89  	spec := &apparmor.Specification{}
    90  	c.Assert(spec.AddConnectedPlug(s.iface, s.plug, s.slot), IsNil)
    91  	c.Assert(spec.SecurityTags(), DeepEquals, []string{"snap.other.app2"})
    92  	c.Assert(spec.SnippetForTag("snap.other.app2"), testutil.Contains, "capability net_admin")
    93  }
    94  
    95  func (s *BluetoothControlInterfaceSuite) TestSecCompSpec(c *C) {
    96  	spec := &seccomp.Specification{}
    97  	c.Assert(spec.AddConnectedPlug(s.iface, s.plug, s.slot), IsNil)
    98  	c.Assert(spec.SecurityTags(), DeepEquals, []string{"snap.other.app2"})
    99  	c.Assert(spec.SnippetForTag("snap.other.app2"), testutil.Contains, "\nbind\n")
   100  }
   101  
   102  func (s *BluetoothControlInterfaceSuite) TestUDevSpec(c *C) {
   103  	spec := &udev.Specification{}
   104  	c.Assert(spec.AddConnectedPlug(s.iface, s.plug, s.slot), IsNil)
   105  	c.Assert(spec.Snippets(), HasLen, 3)
   106  	c.Assert(spec.Snippets(), testutil.Contains, `# bluetooth-control
   107  SUBSYSTEM=="bluetooth", TAG+="snap_other_app2"`)
   108  	c.Assert(spec.Snippets(), testutil.Contains, `# bluetooth-control
   109  SUBSYSTEM=="BT_chrdev", TAG+="snap_other_app2"`)
   110  	c.Assert(spec.Snippets(), testutil.Contains, fmt.Sprintf(`TAG=="snap_other_app2", RUN+="%v/snap-device-helper $env{ACTION} snap_other_app2 $devpath $major:$minor"`, dirs.DistroLibExecDir))
   111  }
   112  
   113  func (s *BluetoothControlInterfaceSuite) TestInterfaces(c *C) {
   114  	c.Check(builtin.Interfaces(), testutil.DeepContains, s.iface)
   115  }