-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5498 from pweil-/addl-sccs
Merged by openshift-bot
- Loading branch information
Showing
3 changed files
with
280 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
pkg/cmd/server/bootstrappolicy/securitycontextconstraints_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package bootstrappolicy | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestBootstrappedConstraints(t *testing.T) { | ||
expectedConstraints := []string{ | ||
SecurityContextConstraintPrivileged, | ||
SecurityContextConstraintRestricted, | ||
SecurityContextConstraintNonRoot, | ||
SecurityContextConstraintHostMount, | ||
SecurityContextConstraintHostNS, | ||
SecurityContextConstraintsAnyUID, | ||
} | ||
expectedGroups, expectedUsers := getExpectedAccess() | ||
|
||
groups, users := GetBoostrapSCCAccess() | ||
bootstrappedConstraints := GetBootstrapSecurityContextConstraints(groups, users) | ||
|
||
if len(expectedConstraints) != len(bootstrappedConstraints) { | ||
t.Errorf("unexpected number of constraints: found %d, wanted %d", len(bootstrappedConstraints), len(expectedConstraints)) | ||
} | ||
|
||
for _, constraint := range bootstrappedConstraints { | ||
g := expectedGroups[constraint.Name] | ||
if !reflect.DeepEqual(g, constraint.Groups) { | ||
t.Errorf("unexpected group access for %s. Found %v, wanted %v", constraint.Name, constraint.Groups, g) | ||
} | ||
|
||
u := expectedUsers[constraint.Name] | ||
if !reflect.DeepEqual(u, constraint.Users) { | ||
t.Errorf("unexpected user access for %s. Found %v, wanted %v", constraint.Name, constraint.Users, u) | ||
} | ||
} | ||
} | ||
|
||
func TestBootstrappedConstraintsWithAddedUser(t *testing.T) { | ||
expectedGroups, expectedUsers := getExpectedAccess() | ||
|
||
// get default access and add our own user to it | ||
groups, users := GetBoostrapSCCAccess() | ||
users[SecurityContextConstraintPrivileged] = append(users[SecurityContextConstraintPrivileged], "foo") | ||
bootstrappedConstraints := GetBootstrapSecurityContextConstraints(groups, users) | ||
|
||
// add it to expected | ||
expectedUsers[SecurityContextConstraintPrivileged] = append(expectedUsers[SecurityContextConstraintPrivileged], "foo") | ||
|
||
for _, constraint := range bootstrappedConstraints { | ||
g := expectedGroups[constraint.Name] | ||
if !reflect.DeepEqual(g, constraint.Groups) { | ||
t.Errorf("unexpected group access for %s. Found %v, wanted %v", constraint.Name, constraint.Groups, g) | ||
} | ||
|
||
u := expectedUsers[constraint.Name] | ||
if !reflect.DeepEqual(u, constraint.Users) { | ||
t.Errorf("unexpected user access for %s. Found %v, wanted %v", constraint.Name, constraint.Users, u) | ||
} | ||
} | ||
} | ||
|
||
func getExpectedAccess() (map[string][]string, map[string][]string) { | ||
groups := map[string][]string{ | ||
SecurityContextConstraintPrivileged: {ClusterAdminGroup, NodesGroup}, | ||
SecurityContextConstraintsAnyUID: {ClusterAdminGroup}, | ||
SecurityContextConstraintRestricted: {AuthenticatedGroup}, | ||
} | ||
users := map[string][]string{} | ||
return groups, users | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters