@@ -39,15 +39,15 @@ func TestPointValue(t *testing.T) {
39
39
// run through all combos of user strategy + seLinux strategy + priv
40
40
for userStrategy , userStrategyPoints := range userStrategies {
41
41
for seLinuxStrategy , seLinuxStrategyPoints := range seLinuxStrategies {
42
- expectedPoints := privilegedPoints + userStrategyPoints + seLinuxStrategyPoints
42
+ expectedPoints := 5000 + privilegedPoints + userStrategyPoints + seLinuxStrategyPoints
43
43
scc := newSCC (true , seLinuxStrategy , userStrategy )
44
44
actualPoints := pointValue (scc )
45
45
46
46
if actualPoints != expectedPoints {
47
47
t .Errorf ("privileged, user: %v, seLinux %v expected %d score but got %d" , userStrategy , seLinuxStrategy , expectedPoints , actualPoints )
48
48
}
49
49
50
- expectedPoints = userStrategyPoints + seLinuxStrategyPoints
50
+ expectedPoints = 5000 + userStrategyPoints + seLinuxStrategyPoints
51
51
scc = newSCC (false , seLinuxStrategy , userStrategy )
52
52
actualPoints = pointValue (scc )
53
53
@@ -57,12 +57,13 @@ func TestPointValue(t *testing.T) {
57
57
}
58
58
}
59
59
60
- // sanity check to ensure volume score is added (specific volumes scores are tested below
60
+ // sanity check to ensure volume and capabilities scores are added (specific volumes
61
+ // and capabilities scores are tested below
61
62
scc := newSCC (false , kapi .SELinuxStrategyMustRunAs , kapi .RunAsUserStrategyMustRunAs )
62
63
scc .Volumes = []kapi.FSType {kapi .FSTypeHostPath }
63
64
actualPoints := pointValue (scc )
64
- if actualPoints != 120000 { //10000 (SELinux) + 10000 (User) + 100000 (host path volume)
65
- t .Errorf ("volume score was not added to the scc point value correctly!" )
65
+ if actualPoints != 125000 { //10000 (SELinux) + 10000 (User) + 100000 (host path volume) + 5000 capabilities
66
+ t .Errorf ("volume score was not added to the scc point value correctly, got %d!" , actualPoints )
66
67
}
67
68
}
68
69
@@ -172,3 +173,67 @@ func TestVolumePointValue(t *testing.T) {
172
173
}
173
174
}
174
175
}
176
+
177
+ func TestCapabilitiesPointValue (t * testing.T ) {
178
+ newSCC := func (def []kapi.Capability , allow []kapi.Capability , drop []kapi.Capability ) * kapi.SecurityContextConstraints {
179
+ return & kapi.SecurityContextConstraints {
180
+ DefaultAddCapabilities : def ,
181
+ AllowedCapabilities : allow ,
182
+ RequiredDropCapabilities : drop ,
183
+ }
184
+ }
185
+
186
+ tests := map [string ]struct {
187
+ scc * kapi.SecurityContextConstraints
188
+ expectedPoints int
189
+ }{
190
+ "nothing specified" : {
191
+ scc : newSCC ([]kapi.Capability {}, []kapi.Capability {}, []kapi.Capability {}),
192
+ expectedPoints : 5000 ,
193
+ },
194
+ "default" : {
195
+ scc : newSCC ([]kapi.Capability {"KILL" , "MKNOD" },
196
+ []kapi.Capability {},
197
+ []kapi.Capability {}),
198
+ expectedPoints : 5600 ,
199
+ },
200
+ "allow" : {
201
+ scc : newSCC ([]kapi.Capability {},
202
+ []kapi.Capability {"KILL" , "MKNOD" },
203
+ []kapi.Capability {}),
204
+ expectedPoints : 5020 ,
205
+ },
206
+ "allow star" : {
207
+ scc : newSCC ([]kapi.Capability {}, []kapi.Capability {"*" }, []kapi.Capability {}),
208
+ expectedPoints : 9000 ,
209
+ },
210
+ "allow all" : {
211
+ scc : newSCC ([]kapi.Capability {}, []kapi.Capability {"ALL" }, []kapi.Capability {}),
212
+ expectedPoints : 9000 ,
213
+ },
214
+ "drop" : {
215
+ scc : newSCC ([]kapi.Capability {},
216
+ []kapi.Capability {},
217
+ []kapi.Capability {"KILL" , "MKNOD" }),
218
+ expectedPoints : 4900 ,
219
+ },
220
+ "drop all" : {
221
+ scc : newSCC ([]kapi.Capability {},
222
+ []kapi.Capability {},
223
+ []kapi.Capability {"ALL" }),
224
+ expectedPoints : 2000 ,
225
+ },
226
+ "mixture" : {
227
+ scc : newSCC ([]kapi.Capability {"SETUID" , "SETGID" },
228
+ []kapi.Capability {"*" },
229
+ []kapi.Capability {"SYS_CHROOT" }),
230
+ expectedPoints : 9550 ,
231
+ },
232
+ }
233
+ for k , v := range tests {
234
+ actualPoints := capabilitiesPointValue (v .scc )
235
+ if actualPoints != v .expectedPoints {
236
+ t .Errorf ("%s expected %d capability score but got %d" , k , v .expectedPoints , actualPoints )
237
+ }
238
+ }
239
+ }
0 commit comments