gitee.com/mysnapcore/mysnapd@v0.1.0/interfaces/builtin/ssh_keys_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/snap" 29 "gitee.com/mysnapcore/mysnapd/testutil" 30 ) 31 32 type SshKeysInterfaceSuite struct { 33 iface interfaces.Interface 34 slotInfo *snap.SlotInfo 35 slot *interfaces.ConnectedSlot 36 plugInfo *snap.PlugInfo 37 plug *interfaces.ConnectedPlug 38 } 39 40 var _ = Suite(&SshKeysInterfaceSuite{ 41 iface: builtin.MustInterface("ssh-keys"), 42 }) 43 44 const sshKeysConsumerYaml = `name: consumer 45 version: 0 46 apps: 47 app: 48 plugs: [ssh-keys] 49 ` 50 51 const sshKeysCoreYaml = `name: core 52 version: 0 53 type: os 54 slots: 55 ssh-keys: 56 ` 57 58 func (s *SshKeysInterfaceSuite) SetUpTest(c *C) { 59 s.plug, s.plugInfo = MockConnectedPlug(c, sshKeysConsumerYaml, nil, "ssh-keys") 60 s.slot, s.slotInfo = MockConnectedSlot(c, sshKeysCoreYaml, nil, "ssh-keys") 61 } 62 63 func (s *SshKeysInterfaceSuite) TestName(c *C) { 64 c.Assert(s.iface.Name(), Equals, "ssh-keys") 65 } 66 67 func (s *SshKeysInterfaceSuite) TestSanitizeSlot(c *C) { 68 c.Assert(interfaces.BeforePrepareSlot(s.iface, s.slotInfo), IsNil) 69 } 70 71 func (s *SshKeysInterfaceSuite) TestSanitizePlug(c *C) { 72 c.Assert(interfaces.BeforePreparePlug(s.iface, s.plugInfo), IsNil) 73 } 74 75 func (s *SshKeysInterfaceSuite) TestAppArmorSpec(c *C) { 76 spec := &apparmor.Specification{} 77 c.Assert(spec.AddConnectedPlug(s.iface, s.plug, s.slot), IsNil) 78 c.Assert(spec.SecurityTags(), DeepEquals, []string{"snap.consumer.app"}) 79 c.Assert(spec.SnippetForTag("snap.consumer.app"), testutil.Contains, `/etc/ssh/ssh_config.d/{,**} r,`) 80 c.Assert(spec.SnippetForTag("snap.consumer.app"), testutil.Contains, `owner @{HOME}/.ssh/{,**} r,`) 81 } 82 83 func (s *SshKeysInterfaceSuite) TestStaticInfo(c *C) { 84 si := interfaces.StaticInfoOf(s.iface) 85 c.Assert(si.ImplicitOnCore, Equals, true) 86 c.Assert(si.ImplicitOnClassic, Equals, true) 87 c.Assert(si.Summary, Equals, `allows reading ssh user configuration and keys`) 88 c.Assert(si.BaseDeclarationSlots, testutil.Contains, "ssh-keys") 89 } 90 91 func (s *SshKeysInterfaceSuite) TestAutoConnect(c *C) { 92 c.Assert(s.iface.AutoConnect(s.plugInfo, s.slotInfo), Equals, true) 93 } 94 95 func (s *SshKeysInterfaceSuite) TestInterfaces(c *C) { 96 c.Check(builtin.Interfaces(), testutil.DeepContains, s.iface) 97 }