|
| 1 | +package selfsubjectaccessreview |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + authorizationscope "github.com/openshift/apiserver-library-go/pkg/authorization/scope" |
| 7 | +) |
| 8 | + |
| 9 | +func TestScopesNeedUserFull(t *testing.T) { |
| 10 | + roleScope := "role:testrole:testns" |
| 11 | + tests := []struct { |
| 12 | + want bool |
| 13 | + scopes []string |
| 14 | + }{ |
| 15 | + {true, []string{authorizationscope.UserAccessCheck}}, |
| 16 | + {true, []string{authorizationscope.UserInfo, authorizationscope.UserAccessCheck}}, |
| 17 | + {true, []string{authorizationscope.UserListAllProjects, authorizationscope.UserAccessCheck}}, |
| 18 | + {true, []string{authorizationscope.UserListAllProjects, authorizationscope.UserInfo, authorizationscope.UserAccessCheck}}, |
| 19 | + {false, nil}, |
| 20 | + {false, []string{}}, |
| 21 | + {false, []string{authorizationscope.UserInfo}}, |
| 22 | + {false, []string{authorizationscope.UserListAllProjects}}, |
| 23 | + {false, []string{authorizationscope.UserFull}}, |
| 24 | + {false, []string{roleScope}}, |
| 25 | + {false, []string{authorizationscope.UserAccessCheck, authorizationscope.UserFull}}, |
| 26 | + {false, []string{authorizationscope.UserAccessCheck, roleScope}}, |
| 27 | + {false, []string{authorizationscope.UserInfo, authorizationscope.UserListAllProjects}}, |
| 28 | + {false, []string{authorizationscope.UserInfo, authorizationscope.UserFull}}, |
| 29 | + {false, []string{authorizationscope.UserInfo, roleScope}}, |
| 30 | + {false, []string{authorizationscope.UserListAllProjects, authorizationscope.UserFull}}, |
| 31 | + {false, []string{authorizationscope.UserListAllProjects, roleScope}}, |
| 32 | + {false, []string{authorizationscope.UserFull, roleScope}}, |
| 33 | + {false, []string{authorizationscope.UserAccessCheck, authorizationscope.UserInfo, authorizationscope.UserFull}}, |
| 34 | + {false, []string{authorizationscope.UserAccessCheck, authorizationscope.UserInfo, roleScope}}, |
| 35 | + {false, []string{authorizationscope.UserAccessCheck, authorizationscope.UserListAllProjects, authorizationscope.UserFull}}, |
| 36 | + {false, []string{authorizationscope.UserAccessCheck, authorizationscope.UserListAllProjects, roleScope}}, |
| 37 | + {false, []string{authorizationscope.UserAccessCheck, authorizationscope.UserFull, roleScope}}, |
| 38 | + {false, []string{authorizationscope.UserInfo, authorizationscope.UserListAllProjects, authorizationscope.UserFull}}, |
| 39 | + {false, []string{authorizationscope.UserInfo, authorizationscope.UserListAllProjects, roleScope}}, |
| 40 | + {false, []string{authorizationscope.UserInfo, authorizationscope.UserFull, roleScope}}, |
| 41 | + {false, []string{authorizationscope.UserListAllProjects, authorizationscope.UserFull, roleScope}}, |
| 42 | + {false, []string{authorizationscope.UserAccessCheck, authorizationscope.UserInfo, authorizationscope.UserListAllProjects, authorizationscope.UserFull}}, |
| 43 | + {false, []string{authorizationscope.UserAccessCheck, authorizationscope.UserInfo, authorizationscope.UserListAllProjects, roleScope}}, |
| 44 | + {false, []string{authorizationscope.UserAccessCheck, authorizationscope.UserInfo, authorizationscope.UserFull, roleScope}}, |
| 45 | + {false, []string{authorizationscope.UserAccessCheck, authorizationscope.UserListAllProjects, authorizationscope.UserFull, roleScope}}, |
| 46 | + {false, []string{authorizationscope.UserInfo, authorizationscope.UserListAllProjects, authorizationscope.UserFull, roleScope}}, |
| 47 | + {false, []string{authorizationscope.UserAccessCheck, authorizationscope.UserInfo, authorizationscope.UserListAllProjects, authorizationscope.UserFull, roleScope}}, |
| 48 | + } |
| 49 | + |
| 50 | + for _, tt := range tests { |
| 51 | + if got := scopesNeedUserFull(tt.scopes); got != tt.want { |
| 52 | + t.Errorf("scopes %v; got %v; want %v", tt.scopes, got, tt.want) |
| 53 | + } |
| 54 | + } |
| 55 | +} |
0 commit comments