RBAC: Refactor GetUserPermissions to use []accesscontrol.Permission (#50683)
* Return slice of permissions instead of slice of pointers for permissions
This commit is contained in:
@@ -15,7 +15,7 @@ type getSettingsTestCase struct {
|
||||
desc string
|
||||
expectedCode int
|
||||
expectedBody string
|
||||
permissions []*accesscontrol.Permission
|
||||
permissions []accesscontrol.Permission
|
||||
}
|
||||
|
||||
func TestAPI_AdminGetSettings(t *testing.T) {
|
||||
@@ -24,7 +24,7 @@ func TestAPI_AdminGetSettings(t *testing.T) {
|
||||
desc: "should return all settings",
|
||||
expectedCode: http.StatusOK,
|
||||
expectedBody: `{"auth.proxy":{"enable_login_token":"false","enabled":"false"},"auth.saml":{"allow_idp_initiated":"false","enabled":"true"}}`,
|
||||
permissions: []*accesscontrol.Permission{
|
||||
permissions: []accesscontrol.Permission{
|
||||
{
|
||||
Action: accesscontrol.ActionSettingsRead,
|
||||
Scope: accesscontrol.ScopeSettingsAll,
|
||||
@@ -35,7 +35,7 @@ func TestAPI_AdminGetSettings(t *testing.T) {
|
||||
desc: "should only return auth.saml settings",
|
||||
expectedCode: http.StatusOK,
|
||||
expectedBody: `{"auth.saml":{"allow_idp_initiated":"false","enabled":"true"}}`,
|
||||
permissions: []*accesscontrol.Permission{
|
||||
permissions: []accesscontrol.Permission{
|
||||
{
|
||||
Action: accesscontrol.ActionSettingsRead,
|
||||
Scope: "settings:auth.saml:*",
|
||||
@@ -46,7 +46,7 @@ func TestAPI_AdminGetSettings(t *testing.T) {
|
||||
desc: "should only partial properties from auth.saml and auth.proxy settings",
|
||||
expectedCode: http.StatusOK,
|
||||
expectedBody: `{"auth.proxy":{"enable_login_token":"false"},"auth.saml":{"enabled":"true"}}`,
|
||||
permissions: []*accesscontrol.Permission{
|
||||
permissions: []accesscontrol.Permission{
|
||||
{
|
||||
Action: accesscontrol.ActionSettingsRead,
|
||||
Scope: "settings:auth.saml:enabled",
|
||||
@@ -101,7 +101,7 @@ func TestAdmin_AccessControl(t *testing.T) {
|
||||
desc: "AdminGetStats should return 200 for user with correct permissions",
|
||||
url: "/api/admin/stats",
|
||||
method: http.MethodGet,
|
||||
permissions: []*accesscontrol.Permission{
|
||||
permissions: []accesscontrol.Permission{
|
||||
{
|
||||
Action: accesscontrol.ActionServerStatsRead,
|
||||
},
|
||||
@@ -112,7 +112,7 @@ func TestAdmin_AccessControl(t *testing.T) {
|
||||
desc: "AdminGetStats should return 403 for user without required permissions",
|
||||
url: "/api/admin/stats",
|
||||
method: http.MethodGet,
|
||||
permissions: []*accesscontrol.Permission{
|
||||
permissions: []accesscontrol.Permission{
|
||||
{
|
||||
Action: "wrong",
|
||||
},
|
||||
@@ -123,7 +123,7 @@ func TestAdmin_AccessControl(t *testing.T) {
|
||||
desc: "AdminGetSettings should return 200 for user with correct permissions",
|
||||
url: "/api/admin/settings",
|
||||
method: http.MethodGet,
|
||||
permissions: []*accesscontrol.Permission{
|
||||
permissions: []accesscontrol.Permission{
|
||||
{
|
||||
Action: accesscontrol.ActionSettingsRead,
|
||||
},
|
||||
@@ -134,7 +134,7 @@ func TestAdmin_AccessControl(t *testing.T) {
|
||||
desc: "AdminGetSettings should return 403 for user without required permissions",
|
||||
url: "/api/admin/settings",
|
||||
method: http.MethodGet,
|
||||
permissions: []*accesscontrol.Permission{
|
||||
permissions: []accesscontrol.Permission{
|
||||
{
|
||||
Action: "wrong",
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user