gitee.com/mysnapcore/mysnapd@v0.1.0/interfaces/apparmor/apparmor_test.go (about) 1 // -*- Mode: Go; indent-tabs-mode: t -*- 2 3 /* 4 * Copyright (C) 2016 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 apparmor_test 21 22 import ( 23 "testing" 24 25 . "gopkg.in/check.v1" 26 27 "gitee.com/mysnapcore/mysnapd/interfaces/apparmor" 28 "gitee.com/mysnapcore/mysnapd/testutil" 29 ) 30 31 func Test(t *testing.T) { 32 TestingT(t) 33 } 34 35 type appArmorSuite struct { 36 testutil.BaseTest 37 } 38 39 var _ = Suite(&appArmorSuite{}) 40 41 func (s *appArmorSuite) SetUpTest(c *C) { 42 s.BaseTest.SetUpTest(c) 43 } 44 45 func (s *appArmorSuite) TestValidateNoAppArmorRegexp(c *C) { 46 for _, testData := range []struct { 47 inputString string 48 expectedError string 49 }{ 50 {"", ""}, 51 {"This is f1ne!", ""}, 52 {"No questions?", `"No questions\?" contains a reserved apparmor char.*`}, 53 {"Brackets[]", `"Brackets\[\]" contains a reserved apparmor char.*`}, 54 {"Braces{}", `"Braces{}" contains a reserved apparmor char.*`}, 55 {"Star*", `"Star\*" contains a reserved apparmor char.*`}, 56 {"hat^", `"hat\^" contains a reserved apparmor char.*`}, 57 {`double"quotes`, `"double\\"quotes" contains a reserved apparmor char.*`}, 58 } { 59 testLabel := Commentf("input: %s", testData.inputString) 60 err := apparmor.ValidateNoAppArmorRegexp(testData.inputString) 61 if testData.expectedError != "" { 62 c.Check(err, ErrorMatches, testData.expectedError, testLabel) 63 } else { 64 c.Check(err, IsNil, testLabel) 65 } 66 } 67 }