gitee.com/mysnapcore/mysnapd@v0.1.0/interfaces/builtin/login_session_control_test.go (about)

     1  // -*- Mode: Go; indent-tabs-mode: t -*-
     2  
     3  /*
     4   * Copyright (C) 2019 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/snap"
    29  	"gitee.com/mysnapcore/mysnapd/snap/snaptest"
    30  	"gitee.com/mysnapcore/mysnapd/testutil"
    31  )
    32  
    33  type loginSessionControlSuite struct {
    34  	iface    interfaces.Interface
    35  	slotInfo *snap.SlotInfo
    36  	slot     *interfaces.ConnectedSlot
    37  	plugInfo *snap.PlugInfo
    38  	plug     *interfaces.ConnectedPlug
    39  }
    40  
    41  var _ = Suite(&loginSessionControlSuite{
    42  	iface: builtin.MustInterface("login-session-control"),
    43  })
    44  
    45  func (s *loginSessionControlSuite) SetUpTest(c *C) {
    46  	consumingSnapInfo := snaptest.MockInfo(c, `
    47  name: other
    48  version: 0
    49  apps:
    50   app:
    51      command: foo
    52      plugs: [login-session-control]
    53  `, nil)
    54  	s.plugInfo = consumingSnapInfo.Plugs["login-session-control"]
    55  	s.plug = interfaces.NewConnectedPlug(s.plugInfo, nil, nil)
    56  	s.slotInfo = &snap.SlotInfo{
    57  		Snap:      &snap.Info{SuggestedName: "core", SnapType: snap.TypeOS},
    58  		Name:      "login-session-control",
    59  		Interface: "login-session-control",
    60  	}
    61  	s.slot = interfaces.NewConnectedSlot(s.slotInfo, nil, nil)
    62  }
    63  
    64  func (s *loginSessionControlSuite) TestName(c *C) {
    65  	c.Assert(s.iface.Name(), Equals, "login-session-control")
    66  }
    67  
    68  func (s *loginSessionControlSuite) TestSanitizeSlot(c *C) {
    69  	c.Assert(interfaces.BeforePrepareSlot(s.iface, s.slotInfo), IsNil)
    70  }
    71  
    72  func (s *loginSessionControlSuite) TestSanitizePlug(c *C) {
    73  	c.Assert(interfaces.BeforePreparePlug(s.iface, s.plugInfo), IsNil)
    74  }
    75  
    76  func (s *loginSessionControlSuite) TestConnectedPlugSnippet(c *C) {
    77  	apparmorSpec := &apparmor.Specification{}
    78  	err := apparmorSpec.AddConnectedPlug(s.iface, s.plug, s.slot)
    79  	c.Assert(err, IsNil)
    80  	c.Assert(apparmorSpec.SecurityTags(), DeepEquals, []string{"snap.other.app"})
    81  	snippet := apparmorSpec.SnippetForTag("snap.other.app")
    82  	c.Assert(snippet, testutil.Contains, `Can setup login session & seat.`)
    83  
    84  	c.Assert(snippet, testutil.Contains, `dbus (send,receive)
    85      bus=system
    86      path=/org/freedesktop/login1/{seat,session}/**
    87      interface=org.freedesktop.DBus.Properties
    88      member={GetAll,PropertiesChanged,Get}
    89      peer=(label=unconfined),`)
    90  	c.Assert(snippet, testutil.Contains, `dbus (send,receive)
    91      bus=system
    92      path=/org/freedesktop/login1/seat/**
    93      interface=org.freedesktop.login1.Seat
    94      peer=(label=unconfined),`)
    95  	c.Assert(snippet, testutil.Contains, `dbus (send,receive)
    96      bus=system
    97      path=/org/freedesktop/login1/session/**
    98      interface=org.freedesktop.login1.Session
    99      peer=(label=unconfined),`)
   100  	c.Assert(snippet, testutil.Contains, `dbus (send,receive)
   101      bus=system
   102      path=/org/freedesktop/login1
   103      interface=org.freedesktop.login1.Manager
   104      member={ActivateSession,GetSession,GetSeat,KillSession,ListSessions,LockSession,TerminateSession,UnlockSession}
   105      peer=(label=unconfined),`)
   106  }
   107  
   108  func (s *loginSessionControlSuite) TestInterfaces(c *C) {
   109  	c.Check(builtin.Interfaces(), testutil.DeepContains, s.iface)
   110  }