(t *testing.T)
| 12 | ) |
| 13 | |
| 14 | func TestCheck(t *testing.T) { |
| 15 | testUser := &store.UserMessage{ |
| 16 | ID: 123, |
| 17 | Email: "test@example.com", |
| 18 | Type: storepb.PrincipalType_END_USER, |
| 19 | } |
| 20 | |
| 21 | rolePermissions := make(map[string]map[permission.Permission]bool) |
| 22 | for _, role := range store.PredefinedRoles { |
| 23 | rolePermissions[common.FormatRole(role.ResourceID)] = role.Permissions |
| 24 | } |
| 25 | getPermissions := func(role string) map[permission.Permission]bool { |
| 26 | return rolePermissions[role] |
| 27 | } |
| 28 | |
| 29 | tests := []struct { |
| 30 | permission permission.Permission |
| 31 | policy *storepb.IamPolicy |
| 32 | groupMembers map[string]map[string]bool |
| 33 | want bool |
| 34 | }{ |
| 35 | { |
| 36 | permission: permission.InstancesCreate, |
| 37 | policy: &storepb.IamPolicy{ |
| 38 | Bindings: []*storepb.Binding{ |
| 39 | { |
| 40 | Role: "roles/workspaceMember", |
| 41 | Members: []string{"users/test@example.com"}, |
| 42 | }, |
| 43 | }, |
| 44 | }, |
| 45 | groupMembers: nil, |
| 46 | want: false, |
| 47 | }, |
| 48 | { |
| 49 | permission: permission.InstancesCreate, |
| 50 | policy: &storepb.IamPolicy{ |
| 51 | Bindings: []*storepb.Binding{ |
| 52 | { |
| 53 | Role: "roles/workspaceAdmin", |
| 54 | Members: []string{"users/test@example.com"}, |
| 55 | }, |
| 56 | }, |
| 57 | }, |
| 58 | groupMembers: nil, |
| 59 | want: true, |
| 60 | }, |
| 61 | { |
| 62 | permission: permission.InstancesCreate, |
| 63 | policy: &storepb.IamPolicy{ |
| 64 | Bindings: []*storepb.Binding{ |
| 65 | { |
| 66 | Role: "roles/workspaceAdmin", |
| 67 | Members: []string{"users/other@example.com"}, |
| 68 | }, |
| 69 | }, |
| 70 | }, |
| 71 | groupMembers: nil, |
nothing calls this directly
no test coverage detected