Skip to content

Commit febf14d

Browse files
authored
Merge pull request #4633 from eexe1/patch-1
Support AppArmor beta version format for Ubuntu 20.10
2 parents 22aea1e + 6d08854 commit febf14d

2 files changed

Lines changed: 111 additions & 0 deletions

File tree

contrib/apparmor/apparmor_test.go

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
// +build linux
2+
3+
/*
4+
Copyright The containerd Authors.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
19+
package apparmor
20+
21+
import (
22+
"testing"
23+
)
24+
25+
type versionExpected struct {
26+
output string
27+
version int
28+
}
29+
30+
func TestParseVersion(t *testing.T) {
31+
versions := []versionExpected{
32+
{
33+
output: `AppArmor parser version 2.10
34+
Copyright (C) 1999-2008 Novell Inc.
35+
Copyright 2009-2012 Canonical Ltd.
36+
`,
37+
version: 210000,
38+
},
39+
{
40+
output: `AppArmor parser version 2.8
41+
Copyright (C) 1999-2008 Novell Inc.
42+
Copyright 2009-2012 Canonical Ltd.
43+
`,
44+
version: 208000,
45+
},
46+
{
47+
output: `AppArmor parser version 2.20
48+
Copyright (C) 1999-2008 Novell Inc.
49+
Copyright 2009-2012 Canonical Ltd.
50+
`,
51+
version: 220000,
52+
},
53+
{
54+
output: `AppArmor parser version 2.05
55+
Copyright (C) 1999-2008 Novell Inc.
56+
Copyright 2009-2012 Canonical Ltd.
57+
`,
58+
version: 205000,
59+
},
60+
{
61+
output: `AppArmor parser version 2.9.95
62+
Copyright (C) 1999-2008 Novell Inc.
63+
Copyright 2009-2012 Canonical Ltd.
64+
`,
65+
version: 209095,
66+
},
67+
{
68+
output: `AppArmor parser version 3.14.159
69+
Copyright (C) 1999-2008 Novell Inc.
70+
Copyright 2009-2012 Canonical Ltd.
71+
`,
72+
version: 314159,
73+
},
74+
{
75+
output: `AppArmor parser version 3.0.0-beta1
76+
Copyright (C) 1999-2008 Novell Inc.
77+
Copyright 2009-2018 Canonical Ltd.
78+
`,
79+
version: 300000,
80+
},
81+
{
82+
output: `AppArmor parser version 3.0.0-beta1-foo-bar
83+
Copyright (C) 1999-2008 Novell Inc.
84+
Copyright 2009-2018 Canonical Ltd.
85+
`,
86+
version: 300000,
87+
},
88+
{
89+
output: `AppArmor parser version 2.7.0~rc2
90+
Copyright (C) 1999-2008 Novell Inc.
91+
Copyright 2009-2018 Canonical Ltd.
92+
`,
93+
version: 207000,
94+
},
95+
}
96+
97+
for _, v := range versions {
98+
version, err := parseVersion(v.output)
99+
if err != nil {
100+
t.Fatalf("expected error to be nil for %#v, got: %v", v, err)
101+
}
102+
if version != v.version {
103+
t.Fatalf("expected version to be %d, was %d, for: %#v\n", v.version, version, v)
104+
}
105+
}
106+
}

contrib/apparmor/template.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@ func parseVersion(output string) (int, error) {
154154
words := strings.Split(lines[0], " ")
155155
version := words[len(words)-1]
156156

157+
// trim "-beta1" suffix from version="3.0.0-beta1" if exists
158+
version = strings.SplitN(version, "-", 2)[0]
159+
// also trim tilde
160+
version = strings.SplitN(version, "~", 2)[0]
161+
157162
// split by major minor version
158163
v := strings.Split(version, ".")
159164
if len(v) == 0 || len(v) > 3 {

0 commit comments

Comments
 (0)