Skip to content

Commit ef2a29e

Browse files
Merge pull request #15923 from adelton/issue-14530-sort-test
Automatic merge from submit-queue (batch tested with PRs 15923, 16172) Check the order of bootstrapped SCCs. Related to #14530 and #14825. Cc @simo5 @openshift/sig-security
2 parents 50094ed + 4a1bceb commit ef2a29e

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

pkg/cmd/server/bootstrappolicy/securitycontextconstraints_test.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,43 @@ package bootstrappolicy
22

33
import (
44
"reflect"
5+
"sort"
56
"testing"
67

78
"k8s.io/apiserver/pkg/authentication/serviceaccount"
89

910
securityapi "github.com/openshift/origin/pkg/security/apis/security"
11+
scc "github.com/openshift/origin/pkg/security/securitycontextconstraints"
1012
sccutil "github.com/openshift/origin/pkg/security/securitycontextconstraints/util"
1113
)
1214

1315
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,
1620
SecurityContextConstraintRestricted,
1721
SecurityContextConstraintNonRoot,
18-
SecurityContextConstraintHostMountAndAnyUID,
1922
SecurityContextConstraintHostNS,
20-
SecurityContextConstraintsAnyUID,
21-
SecurityContextConstraintsHostNetwork,
23+
SecurityContextConstraintHostMountAndAnyUID,
24+
SecurityContextConstraintPrivileged,
2225
}
2326
expectedGroups, expectedUsers := getExpectedAccess()
2427
expectedVolumes := []securityapi.FSType{securityapi.FSTypeEmptyDir, securityapi.FSTypeSecret, securityapi.FSTypeDownwardAPI, securityapi.FSTypeConfigMap, securityapi.FSTypePersistentVolumeClaim}
2528

2629
groups, users := GetBoostrapSCCAccess(DefaultOpenShiftInfraNamespace)
2730
bootstrappedConstraints := GetBootstrapSecurityContextConstraints(groups, users)
2831

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))
3134
}
3235

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+
}
3442
g := expectedGroups[constraint.Name]
3543
if !reflect.DeepEqual(g, constraint.Groups) {
3644
t.Errorf("unexpected group access for %s. Found %v, wanted %v", constraint.Name, constraint.Groups, g)

0 commit comments

Comments
 (0)