- Notifications
You must be signed in to change notification settings - Fork928
feat: Prevent role changing on yourself.#1931
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -409,11 +409,11 @@ func TestGrantRoles(t *testing.T) { | ||
t.Run("UpdateIncorrectRoles", func(t *testing.T) { | ||
t.Parallel() | ||
ctx := context.Background() | ||
var err error | ||
admin := coderdtest.New(t, nil) | ||
first := coderdtest.CreateFirstUser(t, admin) | ||
member := coderdtest.CreateAnotherUser(t, admin, first.OrganizationID) | ||
_, err = admin.UpdateUserRoles(ctx, codersdk.Me, codersdk.UpdateRoles{ | ||
Roles: []string{rbac.RoleOrgMember(first.OrganizationID)}, | ||
@@ -445,7 +445,7 @@ func TestGrantRoles(t *testing.T) { | ||
require.Error(t, err, "member cannot change other's roles") | ||
requireStatusCode(t, err, http.StatusForbidden) | ||
_, err = member.UpdateUserRoles(ctx,first.UserID.String(), codersdk.UpdateRoles{ | ||
Roles: []string{rbac.RoleMember()}, | ||
}) | ||
require.Error(t, err, "member cannot change any roles") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. This should reference "changing their own role" in the error or test name. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I added those tests 👍 | ||
@@ -456,6 +456,18 @@ func TestGrantRoles(t *testing.T) { | ||
}) | ||
require.Error(t, err, "member cannot change other's org roles") | ||
requireStatusCode(t, err, http.StatusForbidden) | ||
_, err = admin.UpdateUserRoles(ctx, first.UserID.String(), codersdk.UpdateRoles{ | ||
Roles: []string{}, | ||
}) | ||
require.Error(t, err, "admin cannot change self roles") | ||
requireStatusCode(t, err, http.StatusBadRequest) | ||
_, err = admin.UpdateOrganizationMemberRoles(ctx, first.OrganizationID, first.UserID.String(), codersdk.UpdateRoles{ | ||
Roles: []string{}, | ||
}) | ||
require.Error(t, err, "admin cannot change self org roles") | ||
requireStatusCode(t, err, http.StatusBadRequest) | ||
}) | ||
t.Run("FirstUserRoles", func(t *testing.T) { | ||
@@ -508,7 +520,7 @@ func TestGrantRoles(t *testing.T) { | ||
require.NoError(t, err, "grant member admin role") | ||
// Promote to org admin | ||
_, err =admin.UpdateOrganizationMemberRoles(ctx, first.OrganizationID,memberUser.ID.String(), codersdk.UpdateRoles{ | ||
Roles: []string{ | ||
// Promote to org admin | ||
rbac.RoleOrgMember(first.OrganizationID), | ||