Skip to content

feat: set user.must_reset_password to false on change password #14852

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
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
Next Next commit
test: must_reset_password is set to false
  • Loading branch information
DanielleMaywood committed Sep 27, 2024
commit 3a5be113147e6401b35b98e0754933f9c60d42e5
30 changes: 30 additions & 0 deletions coderd/users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1211,6 +1211,36 @@ func TestUpdateUserPassword(t *testing.T) {
cerr := coderdtest.SDKError(t, err)
require.Equal(t, http.StatusBadRequest, cerr.StatusCode())
})

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

client, db := coderdtest.NewWithDatabase(t, nil)
user := coderdtest.CreateFirstUser(t, client)
ctx := testutil.Context(t, testutil.WaitLong)

//nolint:gocritic // Unit test
err := db.UpdateUserMustResetPassword(dbauthz.AsSystemRestricted(ctx), database.UpdateUserMustResetPasswordParams{
ID: user.UserID,
MustResetPassword: true,
})
require.Nil(t, err)

//nolint:gocritic // Unit test
dbUser, err := db.GetUserByID(dbauthz.AsSystemRestricted(ctx), user.UserID)
require.Nil(t, err)
require.True(t, dbUser.MustResetPassword)

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

//nolint:gocritic // Unit test
dbUser, err = db.GetUserByID(dbauthz.AsSystemRestricted(ctx), user.UserID)
require.Nil(t, err)
require.False(t, dbUser.MustResetPassword)
})
}

// TestInitialRoles ensures the starting roles for the first user are correct.
Expand Down
Loading