-
Notifications
You must be signed in to change notification settings - Fork 0
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 #27 from nais/teamrole
Add custom team role
- Loading branch information
Showing
3 changed files
with
113 additions
and
28 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
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 |
---|---|---|
|
@@ -116,8 +116,10 @@ func TestReconcile(t *testing.T) { | |
}, | ||
} | ||
expectedTeamProjectID := "slug-prod-ea99" | ||
expectedRoleId := "CustomCNRMRole" | ||
expectedCnrmRoleName := "projects/slug-prod-ea99/roles/" + expectedRoleId | ||
expectedCNRMRoleId := "CustomCNRMRole" | ||
expectedTeamRoleId := "CustomTeamRole" | ||
expectedCnrmRoleName := "projects/slug-prod-ea99/roles/" + expectedCNRMRoleId | ||
expectedTeamRoleName := "projects/slug-prod-ea99/roles/" + expectedTeamRoleId | ||
flags := config.FeatureFlags{ | ||
AttachSharedVpc: true, | ||
} | ||
|
@@ -292,8 +294,8 @@ func TestReconcile(t *testing.T) { | |
payload := iam.CreateRoleRequest{} | ||
_ = json.NewDecoder(r.Body).Decode(&payload) | ||
|
||
if payload.RoleId != expectedRoleId { | ||
t.Errorf("expected role id %q, got %q", expectedRoleId, payload.RoleId) | ||
if payload.RoleId != expectedCNRMRoleId { | ||
t.Errorf("expected role id %q, got %q", expectedCNRMRoleId, payload.RoleId) | ||
} | ||
|
||
if expected := 35; payload.Role.IncludedPermissions != nil && len(payload.Role.IncludedPermissions) != expected { | ||
|
@@ -306,6 +308,37 @@ func TestReconcile(t *testing.T) { | |
_, _ = w.Write(resp) | ||
}, | ||
|
||
// get existing custom team role | ||
func(w http.ResponseWriter, r *http.Request) { | ||
if r.Method != http.MethodGet { | ||
t.Errorf("expected HTTP GET, got: %q", r.Method) | ||
} | ||
w.WriteHeader(404) | ||
}, | ||
|
||
// create custom team role | ||
func(w http.ResponseWriter, r *http.Request) { | ||
if r.Method != http.MethodPost { | ||
t.Errorf("expected HTTP POST, got: %q", r.Method) | ||
} | ||
|
||
payload := iam.CreateRoleRequest{} | ||
_ = json.NewDecoder(r.Body).Decode(&payload) | ||
|
||
if payload.RoleId != expectedTeamRoleId { | ||
t.Errorf("expected role id %q, got %q", expectedTeamRoleId, payload.RoleId) | ||
} | ||
|
||
if expected := 32; payload.Role.IncludedPermissions != nil && len(payload.Role.IncludedPermissions) != expected { | ||
t.Errorf("expected %d permissions, got %d", expected, len(payload.Role.IncludedPermissions)) | ||
} | ||
|
||
payload.Role.Name = expectedTeamRoleName | ||
|
||
resp, _ := payload.Role.MarshalJSON() | ||
_, _ = w.Write(resp) | ||
}, | ||
|
||
// set workload identity for service account | ||
func(w http.ResponseWriter, r *http.Request) { | ||
if r.Method != http.MethodPost { | ||
|
@@ -347,6 +380,7 @@ func TestReconcile(t *testing.T) { | |
expectedBindings := map[string]string{ | ||
payload.Policy.Bindings[0].Role: payload.Policy.Bindings[0].Members[0], | ||
payload.Policy.Bindings[1].Role: payload.Policy.Bindings[1].Members[0], | ||
payload.Policy.Bindings[2].Role: payload.Policy.Bindings[2].Members[0], | ||
} | ||
|
||
if expectedBindings["roles/owner"] != "group:[email protected]" { | ||
|
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