Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
feat(password): add test for validate admin use case and change logic
  • Loading branch information
defelmnq committed Oct 24, 2024
commit 94c4311a05e6b2a9b449debac6375987559e8159
10 changes: 6 additions & 4 deletions coderd/users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1122,7 +1122,7 @@ func TestUpdateUserPassword(t *testing.T) {
Password: "newpassword",
})
require.Error(t, err, "member should not be able to update own password without providing old password")
require.ErrorContains(t, err, "Old password is required for non-admin users.")
require.ErrorContains(t, err, "Old password is required.")
})

t.Run("AuditorCantTellIfPasswordIncorrect", func(t *testing.T) {
Expand Down Expand Up @@ -1159,7 +1159,7 @@ func TestUpdateUserPassword(t *testing.T) {
require.Equal(t, int32(http.StatusNotFound), auditor.AuditLogs()[numLogs-1].StatusCode)
})

t.Run("AdminCanUpdateOwnPasswordWithoutOldPassword", func(t *testing.T) {
t.Run("AdminCantUpdateOwnPasswordWithoutOldPassword", func(t *testing.T) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this test to reflect the logic change here.

IMO even an admin should not be able to change its own password without giving the old password - also the UI currently forces users (admin too) to have the old password.

t.Parallel()
auditor := audit.NewMock()
client := coderdtest.New(t, &coderdtest.Options{Auditor: auditor})
Expand All @@ -1176,7 +1176,8 @@ func TestUpdateUserPassword(t *testing.T) {
})
numLogs++ // add an audit log for user update

require.NoError(t, err, "admin should be able to update own password without providing old password")
require.Error(t, err, "admin should not be able to update own password without providing old password")
require.ErrorContains(t, err, "Old password is required.")

require.Len(t, auditor.AuditLogs(), numLogs)
require.Equal(t, database.AuditActionWrite, auditor.AuditLogs()[numLogs-1].Action)
Expand All @@ -1196,7 +1197,8 @@ func TestUpdateUserPassword(t *testing.T) {
require.NoError(t, err)

err = client.UpdateUserPassword(ctx, "me", codersdk.UpdateUserPasswordRequest{
Password: "MyNewSecurePassword!",
OldPassword: "SomeSecurePassword!",
Password: "MyNewSecurePassword!",
})
require.NoError(t, err)

Expand Down
Loading