github.com/bugraaydogar/snapd@v0.0.0-20210315170335-8c70bb858939/interfaces/builtin/cups_test.go (about)

     1  // -*- Mode: Go; indent-tabs-mode: t -*-
     2  
     3  /*
     4   * Copyright (C) 2020 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/apparmor"
    27  	"github.com/snapcore/snapd/interfaces/builtin"
    28  	"github.com/snapcore/snapd/release"
    29  	"github.com/snapcore/snapd/snap"
    30  	"github.com/snapcore/snapd/testutil"
    31  )
    32  
    33  type cupsSuite struct {
    34  	iface            interfaces.Interface
    35  	plugInfo         *snap.PlugInfo
    36  	plug             *interfaces.ConnectedPlug
    37  	providerSlotInfo *snap.SlotInfo
    38  	providerSlot     *interfaces.ConnectedSlot
    39  }
    40  
    41  var _ = Suite(&cupsSuite{iface: builtin.MustInterface("cups")})
    42  
    43  const cupsConsumerYaml = `name: consumer
    44  version: 0
    45  apps:
    46   app:
    47    plugs: [cups]
    48  `
    49  
    50  const cupsProviderYaml = `name: provider
    51  version: 0
    52  apps:
    53   app:
    54    slots: [cups]
    55  `
    56  
    57  func (s *cupsSuite) SetUpTest(c *C) {
    58  	s.plug, s.plugInfo = MockConnectedPlug(c, cupsConsumerYaml, nil, "cups")
    59  	s.providerSlot, s.providerSlotInfo = MockConnectedSlot(c, cupsProviderYaml, nil, "cups")
    60  }
    61  
    62  func (s *cupsSuite) TestName(c *C) {
    63  	c.Assert(s.iface.Name(), Equals, "cups")
    64  }
    65  
    66  func (s *cupsSuite) TestSanitizeSlot(c *C) {
    67  	c.Assert(interfaces.BeforePrepareSlot(s.iface, s.providerSlotInfo), IsNil)
    68  }
    69  
    70  func (s *cupsSuite) TestSanitizePlug(c *C) {
    71  	c.Assert(interfaces.BeforePreparePlug(s.iface, s.plugInfo), IsNil)
    72  }
    73  
    74  func (s *cupsSuite) TestAppArmorSpec(c *C) {
    75  	for _, onClassic := range []bool{true, false} {
    76  		restore := release.MockOnClassic(onClassic)
    77  		defer restore()
    78  
    79  		// consumer to provider on core for ConnectedPlug
    80  		spec := &apparmor.Specification{}
    81  		c.Assert(spec.AddConnectedPlug(s.iface, s.plug, s.providerSlot), IsNil)
    82  		c.Assert(spec.SecurityTags(), DeepEquals, []string{"snap.consumer.app"})
    83  		c.Assert(spec.SnippetForTag("snap.consumer.app"), testutil.Contains, "# Allow communicating with the cups server")
    84  		c.Assert(spec.SnippetForTag("snap.consumer.app"), testutil.Contains, "#include <abstractions/cups-client>")
    85  		restore()
    86  	}
    87  }
    88  
    89  func (s *cupsSuite) TestStaticInfo(c *C) {
    90  	si := interfaces.StaticInfoOf(s.iface)
    91  	c.Assert(si.ImplicitOnCore, Equals, false)
    92  	c.Assert(si.ImplicitOnClassic, Equals, false)
    93  	c.Assert(si.Summary, Equals, `allows access to the CUPS socket for printing`)
    94  	c.Assert(si.BaseDeclarationSlots, testutil.Contains, "cups")
    95  	c.Assert(si.BaseDeclarationSlots, testutil.Contains, "deny-connection: true")
    96  	c.Assert(si.BaseDeclarationSlots, testutil.Contains, "deny-auto-connection: true")
    97  }
    98  
    99  func (s *cupsSuite) TestInterfaces(c *C) {
   100  	c.Check(builtin.Interfaces(), testutil.DeepContains, s.iface)
   101  }