Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion coderd/userauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ func (api *API) postChangePasswordWithOneTimePasscode(rw http.ResponseWriter, r

if equal {
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
Message: "New password cannot match old password.",
Message: "New password must be different from your current password.",
})
return nil
}
Expand Down
30 changes: 30 additions & 0 deletions coderd/userauth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2386,6 +2386,36 @@ func TestUserForgotPassword(t *testing.T) {
requireCanLogin(t, ctx, anotherClient, anotherUser.Email, oldPassword)
})

t.Run("CannotReuseOldPassword", func(t *testing.T) {
t.Parallel()

notifyEnq := &notificationstest.FakeEnqueuer{}

client := coderdtest.New(t, &coderdtest.Options{
NotificationsEnqueuer: notifyEnq,
})
user := coderdtest.CreateFirstUser(t, client)

ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
defer cancel()

anotherClient, anotherUser := coderdtest.CreateAnotherUser(t, client, user.OrganizationID)

oneTimePasscode := requireRequestOneTimePasscode(t, ctx, anotherClient, notifyEnq, anotherUser.Email, anotherUser.ID)

err := anotherClient.ChangePasswordWithOneTimePasscode(ctx, codersdk.ChangePasswordWithOneTimePasscodeRequest{
Email: anotherUser.Email,
OneTimePasscode: oneTimePasscode,
Password: oldPassword,
})
var apiErr *codersdk.Error
require.ErrorAs(t, err, &apiErr)
require.Equal(t, http.StatusBadRequest, apiErr.StatusCode())
require.Contains(t, apiErr.Message, "New password must be different from your current password.")

requireCanLogin(t, ctx, anotherClient, anotherUser.Email, oldPassword)
})

t.Run("CannotChangePasswordOfAnotherUser", func(t *testing.T) {
t.Parallel()

Expand Down