@@ -2,35 +2,43 @@ package bootstrappolicy
2
2
3
3
import (
4
4
"reflect"
5
+ "sort"
5
6
"testing"
6
7
7
8
"k8s.io/apiserver/pkg/authentication/serviceaccount"
8
9
9
10
securityapi "github.com/openshift/origin/pkg/security/apis/security"
11
+ scc "github.com/openshift/origin/pkg/security/securitycontextconstraints"
10
12
sccutil "github.com/openshift/origin/pkg/security/securitycontextconstraints/util"
11
13
)
12
14
13
15
func TestBootstrappedConstraints (t * testing.T ) {
14
- expectedConstraints := []string {
15
- SecurityContextConstraintPrivileged ,
16
+ // ordering of expectedConstraintNames is important, we check it against scc.ByPriority
17
+ expectedConstraintNames := []string {
18
+ SecurityContextConstraintsAnyUID ,
19
+ SecurityContextConstraintsHostNetwork ,
16
20
SecurityContextConstraintRestricted ,
17
21
SecurityContextConstraintNonRoot ,
18
- SecurityContextConstraintHostMountAndAnyUID ,
19
22
SecurityContextConstraintHostNS ,
20
- SecurityContextConstraintsAnyUID ,
21
- SecurityContextConstraintsHostNetwork ,
23
+ SecurityContextConstraintHostMountAndAnyUID ,
24
+ SecurityContextConstraintPrivileged ,
22
25
}
23
26
expectedGroups , expectedUsers := getExpectedAccess ()
24
27
expectedVolumes := []securityapi.FSType {securityapi .FSTypeEmptyDir , securityapi .FSTypeSecret , securityapi .FSTypeDownwardAPI , securityapi .FSTypeConfigMap , securityapi .FSTypePersistentVolumeClaim }
25
28
26
29
groups , users := GetBoostrapSCCAccess (DefaultOpenShiftInfraNamespace )
27
30
bootstrappedConstraints := GetBootstrapSecurityContextConstraints (groups , users )
28
31
29
- if len (expectedConstraints ) != len (bootstrappedConstraints ) {
30
- t .Errorf ("unexpected number of constraints: found %d, wanted %d" , len (bootstrappedConstraints ), len (expectedConstraints ))
32
+ if len (expectedConstraintNames ) != len (bootstrappedConstraints ) {
33
+ t .Errorf ("unexpected number of constraints: found %d, wanted %d" , len (bootstrappedConstraints ), len (expectedConstraintNames ))
31
34
}
32
35
33
- for _ , constraint := range bootstrappedConstraints {
36
+ sort .Sort (scc .ByPriority (bootstrappedConstraints ))
37
+
38
+ for i , constraint := range bootstrappedConstraints {
39
+ if constraint .Name != expectedConstraintNames [i ] {
40
+ t .Errorf ("unexpected contraint no. %d (by priority). Found %v, wanted %v" , i , constraint .Name , expectedConstraintNames [i ])
41
+ }
34
42
g := expectedGroups [constraint .Name ]
35
43
if ! reflect .DeepEqual (g , constraint .Groups ) {
36
44
t .Errorf ("unexpected group access for %s. Found %v, wanted %v" , constraint .Name , constraint .Groups , g )
0 commit comments