Skip to content

Commit d86b9b2

Browse files
committed
fix rbac
1 parent 6454015 commit d86b9b2

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

coderd/users.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ func (api *API) putUserPassword(rw http.ResponseWriter, r *http.Request) {
359359
params codersdk.UpdateUserPasswordRequest
360360
)
361361

362-
if !api.Authorize(rw, r, rbac.ActionUpdate, rbac.ResourceUserData.WithID(user.ID.String())) {
362+
if !api.Authorize(rw, r, rbac.ActionUpdate, rbac.ResourceUserData.WithOwner(user.ID.String())) {
363363
return
364364
}
365365

coderd/users_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,16 @@ func TestUpdateUserPassword(t *testing.T) {
335335
})
336336
require.NoError(t, err, "member should be able to update own password")
337337
})
338+
t.Run("MemberCantUpdateOwnPasswordWithoutOldPassword", func(t *testing.T) {
339+
t.Parallel()
340+
client := coderdtest.New(t, nil)
341+
admin := coderdtest.CreateFirstUser(t, client)
342+
member := coderdtest.CreateAnotherUser(t, client, admin.OrganizationID)
343+
err := member.UpdateUserPassword(context.Background(), "me", codersdk.UpdateUserPasswordRequest{
344+
Password: "newpassword",
345+
})
346+
require.Error(t, err, "member should not be able to update own password without providing old password")
347+
})
338348
t.Run("AdminCantUpdateOwnPasswordWithoutOldPassword", func(t *testing.T) {
339349
t.Parallel()
340350
client := coderdtest.New(t, nil)

0 commit comments

Comments
 (0)