github.com/rigado/snapd@v2.42.5-go-mod+incompatible/interfaces/builtin/netlink_connector_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/builtin"
    27  	"github.com/snapcore/snapd/interfaces/seccomp"
    28  	"github.com/snapcore/snapd/snap"
    29  	"github.com/snapcore/snapd/snap/snaptest"
    30  	"github.com/snapcore/snapd/testutil"
    31  )
    32  
    33  type NetlinkConnectorInterfaceSuite 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 netlinkConnectorMockPlugSnapInfoYaml = `name: other
    42  version: 1.0
    43  apps:
    44   app2:
    45    command: foo
    46    plugs: [netlink-connector]
    47  `
    48  
    49  var _ = Suite(&NetlinkConnectorInterfaceSuite{
    50  	iface: builtin.MustInterface("netlink-connector"),
    51  })
    52  
    53  func (s *NetlinkConnectorInterfaceSuite) SetUpTest(c *C) {
    54  	s.slotInfo = &snap.SlotInfo{
    55  		Snap:      &snap.Info{SuggestedName: "core", SnapType: snap.TypeOS},
    56  		Name:      "netlink-connector",
    57  		Interface: "netlink-connector",
    58  	}
    59  	s.slot = interfaces.NewConnectedSlot(s.slotInfo, nil, nil)
    60  	plugSnap := snaptest.MockInfo(c, netlinkConnectorMockPlugSnapInfoYaml, nil)
    61  	s.plugInfo = plugSnap.Plugs["netlink-connector"]
    62  	s.plug = interfaces.NewConnectedPlug(s.plugInfo, nil, nil)
    63  }
    64  
    65  func (s *NetlinkConnectorInterfaceSuite) TestName(c *C) {
    66  	c.Assert(s.iface.Name(), Equals, "netlink-connector")
    67  }
    68  
    69  func (s *NetlinkConnectorInterfaceSuite) TestSanitizeSlot(c *C) {
    70  	c.Assert(interfaces.BeforePrepareSlot(s.iface, s.slotInfo), IsNil)
    71  }
    72  
    73  func (s *NetlinkConnectorInterfaceSuite) TestSanitizePlug(c *C) {
    74  	c.Assert(interfaces.BeforePreparePlug(s.iface, s.plugInfo), IsNil)
    75  }
    76  
    77  func (s *NetlinkConnectorInterfaceSuite) TestUsedSecuritySystems(c *C) {
    78  	seccompSpec := &seccomp.Specification{}
    79  	err := seccompSpec.AddConnectedPlug(s.iface, s.plug, s.slot)
    80  	c.Assert(err, IsNil)
    81  	c.Assert(seccompSpec.SecurityTags(), DeepEquals, []string{"snap.other.app2"})
    82  	c.Check(seccompSpec.SnippetForTag("snap.other.app2"), testutil.Contains, "socket AF_NETLINK - NETLINK_CONNECTOR\n")
    83  }
    84  
    85  func (s *NetlinkConnectorInterfaceSuite) TestInterfaces(c *C) {
    86  	c.Check(builtin.Interfaces(), testutil.DeepContains, s.iface)
    87  }