gitee.com/mysnapcore/mysnapd@v0.1.0/interfaces/builtin/adb_support_test.go (about) 1 // -*- Mode: Go; indent-tabs-mode: t -*- 2 3 /* 4 * Copyright (C) 2018 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/interfaces/udev" 30 "gitee.com/mysnapcore/mysnapd/snap" 31 "gitee.com/mysnapcore/mysnapd/testutil" 32 ) 33 34 type adbSupportSuite 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(&adbSupportSuite{ 43 iface: builtin.MustInterface("adb-support"), 44 }) 45 46 const adbConsumerYaml = `name: consumer 47 version: 0 48 apps: 49 app: 50 plugs: [adb-support] 51 ` 52 53 const adbCoreYaml = `name: provider 54 version: 0 55 apps: 56 app: 57 slots: [adb-support] 58 ` 59 60 func (s *adbSupportSuite) SetUpTest(c *C) { 61 s.plug, s.plugInfo = MockConnectedPlug(c, adbConsumerYaml, nil, "adb-support") 62 s.slot, s.slotInfo = MockConnectedSlot(c, adbCoreYaml, nil, "adb-support") 63 } 64 65 func (s *adbSupportSuite) TestName(c *C) { 66 c.Assert(s.iface.Name(), Equals, "adb-support") 67 } 68 69 func (s *adbSupportSuite) TestSanitizeSlot(c *C) { 70 c.Assert(interfaces.BeforePrepareSlot(s.iface, s.slotInfo), IsNil) 71 72 slot := &snap.SlotInfo{ 73 Snap: &snap.Info{SuggestedName: "some-snap"}, 74 Name: "adb-support", 75 Interface: "adb-support", 76 } 77 c.Assert(interfaces.BeforePrepareSlot(s.iface, slot), IsNil) 78 } 79 80 func (s *adbSupportSuite) TestSanitizePlug(c *C) { 81 c.Assert(interfaces.BeforePreparePlug(s.iface, s.plugInfo), IsNil) 82 } 83 84 func (s *adbSupportSuite) TestSecCompSpec(c *C) { 85 spec := &seccomp.Specification{} 86 c.Assert(spec.AddPermanentPlug(s.iface, s.plugInfo), IsNil) 87 c.Assert(spec.SecurityTags(), HasLen, 0) 88 89 spec = &seccomp.Specification{} 90 c.Assert(spec.AddPermanentSlot(s.iface, s.slotInfo), IsNil) 91 c.Assert(spec.SecurityTags(), HasLen, 0) 92 93 spec = &seccomp.Specification{} 94 c.Assert(spec.AddConnectedPlug(s.iface, s.plug, s.slot), IsNil) 95 c.Assert(spec.SecurityTags(), HasLen, 0) 96 97 spec = &seccomp.Specification{} 98 c.Assert(spec.AddConnectedSlot(s.iface, s.plug, s.slot), IsNil) 99 c.Assert(spec.SecurityTags(), HasLen, 0) 100 } 101 102 func (s *adbSupportSuite) TestAppArmorSpec(c *C) { 103 spec := &apparmor.Specification{} 104 c.Assert(spec.AddPermanentPlug(s.iface, s.plugInfo), IsNil) 105 c.Assert(spec.SecurityTags(), HasLen, 0) 106 107 spec = &apparmor.Specification{} 108 c.Assert(spec.AddPermanentPlug(s.iface, s.plugInfo), IsNil) 109 c.Assert(spec.AddPermanentSlot(s.iface, s.slotInfo), IsNil) 110 c.Assert(spec.SecurityTags(), HasLen, 0) 111 112 spec = &apparmor.Specification{} 113 c.Assert(spec.AddConnectedPlug(s.iface, s.plug, s.slot), IsNil) 114 c.Assert(spec.SecurityTags(), HasLen, 1) 115 c.Assert(spec.SnippetForTag("snap.consumer.app"), testutil.Contains, "/dev/bus/usb/[0-9][0-9][0-9]/[0-9][0-9][0-9] rw,") 116 c.Assert(spec.SnippetForTag("snap.consumer.app"), testutil.Contains, "/run/udev/data/c189:* r,") 117 118 spec = &apparmor.Specification{} 119 c.Assert(spec.AddConnectedSlot(s.iface, s.plug, s.slot), IsNil) 120 c.Assert(spec.SecurityTags(), HasLen, 0) 121 } 122 123 func (s *adbSupportSuite) TestUDevSpec(c *C) { 124 spec := &udev.Specification{} 125 c.Assert(spec.AddPermanentPlug(s.iface, s.plugInfo), IsNil) 126 c.Assert(spec.Snippets(), HasLen, 0) 127 128 spec = &udev.Specification{} 129 c.Assert(spec.AddPermanentSlot(s.iface, s.slotInfo), IsNil) 130 c.Assert(spec.Snippets(), HasLen, 0) 131 132 spec = &udev.Specification{} 133 c.Assert(spec.AddConnectedPlug(s.iface, s.plug, s.slot), IsNil) 134 c.Assert(spec.Snippets(), HasLen, 82) 135 c.Assert(spec.Snippets(), testutil.Contains, `# adb-support 136 SUBSYSTEM=="usb", ATTR{idVendor}=="0502", TAG+="snap_consumer_app"`) 137 c.Assert(spec.Snippets(), testutil.Contains, `# adb-support 138 SUBSYSTEM=="usb", ATTR{idVendor}=="19d2", TAG+="snap_consumer_app"`) 139 140 // One-plus devices are included. 141 // https://bugs.launchpad.net/snapd/+bug/1821474 142 c.Assert(spec.Snippets(), testutil.Contains, `# adb-support 143 SUBSYSTEM=="usb", ATTR{idVendor}=="2a70", TAG+="snap_consumer_app"`) 144 145 spec = &udev.Specification{} 146 c.Assert(spec.AddConnectedSlot(s.iface, s.plug, s.slot), IsNil) 147 c.Assert(spec.Snippets(), HasLen, 1) 148 c.Assert(spec.Snippets()[0], testutil.Contains, `SUBSYSTEM=="usb", ATTR{idVendor}=="0502", MODE="0666"`) 149 } 150 151 func (s *adbSupportSuite) TestStaticInfo(c *C) { 152 si := interfaces.StaticInfoOf(s.iface) 153 c.Assert(si.ImplicitOnCore, Equals, true) 154 c.Assert(si.ImplicitOnClassic, Equals, true) 155 c.Assert(si.Summary, Equals, `allows operating as Android Debug Bridge service`) 156 c.Assert(si.BaseDeclarationSlots, testutil.Contains, "adb-support") 157 } 158 159 func (s *adbSupportSuite) TestInterfaces(c *C) { 160 c.Check(builtin.Interfaces(), testutil.DeepContains, s.iface) 161 }