gitee.com/mysnapcore/mysnapd@v0.1.0/interfaces/builtin/online_accounts_service_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  	"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/snap/snaptest"
    31  	"gitee.com/mysnapcore/mysnapd/testutil"
    32  )
    33  
    34  type OnlineAccountsServiceInterfaceSuite struct {
    35  	iface    interfaces.Interface
    36  	slotInfo *snap.SlotInfo
    37  	slot     *interfaces.ConnectedSlot
    38  	plugInfo *snap.PlugInfo
    39  	plug     *interfaces.ConnectedPlug
    40  }
    41  
    42  var _ = Suite(&OnlineAccountsServiceInterfaceSuite{
    43  	iface: builtin.MustInterface("online-accounts-service"),
    44  })
    45  
    46  func (s *OnlineAccountsServiceInterfaceSuite) SetUpTest(c *C) {
    47  	const providerYaml = `name: provider
    48  version: 1.0
    49  slots:
    50   online-accounts-service:
    51    interface: online-accounts-service
    52  apps:
    53   app:
    54    command: foo
    55    slots: [online-accounts-service]
    56  `
    57  	providerInfo := snaptest.MockInfo(c, providerYaml, nil)
    58  	s.slotInfo = providerInfo.Slots["online-accounts-service"]
    59  	s.slot = interfaces.NewConnectedSlot(s.slotInfo, nil, nil)
    60  
    61  	var consumerYaml = `name: consumer
    62  version: 1.0
    63  apps:
    64   app:
    65    command: foo
    66    plugs: [online-accounts-service]
    67  `
    68  	consumerInfo := snaptest.MockInfo(c, consumerYaml, nil)
    69  	s.plugInfo = consumerInfo.Plugs["online-accounts-service"]
    70  	s.plug = interfaces.NewConnectedPlug(s.plugInfo, nil, nil)
    71  }
    72  
    73  func (s *OnlineAccountsServiceInterfaceSuite) TestName(c *C) {
    74  	c.Assert(s.iface.Name(), Equals, "online-accounts-service")
    75  }
    76  
    77  func (s *OnlineAccountsServiceInterfaceSuite) TestSanitize(c *C) {
    78  	c.Assert(interfaces.BeforePreparePlug(s.iface, s.plugInfo), IsNil)
    79  	c.Assert(interfaces.BeforePrepareSlot(s.iface, s.slotInfo), IsNil)
    80  }
    81  
    82  func (s *OnlineAccountsServiceInterfaceSuite) TestAppArmorConnectedPlug(c *C) {
    83  	spec := &apparmor.Specification{}
    84  	c.Assert(spec.AddConnectedPlug(s.iface, s.plug, s.slot), IsNil)
    85  	c.Assert(spec.SecurityTags(), HasLen, 1)
    86  	c.Check(spec.SnippetForTag("snap.consumer.app"), testutil.Contains, `peer=(label="snap.provider.app")`)
    87  }
    88  
    89  func (s *OnlineAccountsServiceInterfaceSuite) TestAppArmorConnectedSlot(c *C) {
    90  	spec := &apparmor.Specification{}
    91  	c.Assert(spec.AddConnectedSlot(s.iface, s.plug, s.slot), IsNil)
    92  	c.Check(spec.SnippetForTag("snap.provider.app"), testutil.Contains, `peer=(label="snap.consumer.app")`)
    93  }
    94  
    95  func (s *OnlineAccountsServiceInterfaceSuite) TestAppArrmorPermanentSlot(c *C) {
    96  	spec := &apparmor.Specification{}
    97  	c.Assert(spec.AddPermanentSlot(s.iface, s.slotInfo), IsNil)
    98  	c.Assert(spec.Snippets(), HasLen, 1)
    99  	c.Assert(spec.SnippetForTag("snap.provider.app"), testutil.Contains, `member={RequestName,ReleaseName,GetConnectionCredentials}`)
   100  	c.Assert(spec.SnippetForTag("snap.provider.app"), testutil.Contains, `name="com.ubuntu.OnlineAccounts.Manager"`)
   101  }
   102  
   103  func (s *OnlineAccountsServiceInterfaceSuite) TestSecCompPermanentSlot(c *C) {
   104  	spec := &seccomp.Specification{}
   105  	c.Assert(spec.AddPermanentSlot(s.iface, s.slotInfo), IsNil)
   106  	c.Check(spec.SnippetForTag("snap.provider.app"), testutil.Contains, "listen\n")
   107  }
   108  
   109  func (s *OnlineAccountsServiceInterfaceSuite) TestInterfaces(c *C) {
   110  	c.Check(builtin.Interfaces(), testutil.DeepContains, s.iface)
   111  }