Skip to content
Merged
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
13 changes: 10 additions & 3 deletions internal/api/handler_auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -707,8 +707,11 @@ func TestHandler_resetPasswordStatus_NoAuthService(t *testing.T) {
func TestHandler_resetPassword_Error(t *testing.T) {
ctx := context.Background()
mockAuth := new(MockAuthService)
t.Cleanup(func() { mockAuth.AssertExpectations(t) })

mockAuth.On("ConfirmPasswordReset", ctx, mock.Anything).Return(errors.New("invalid or expired token"))
// Use the exact string the real service emits so isResetPasswordClientError
// classifies it as a 400 client error, not a 500 internal error.
mockAuth.On("ConfirmPasswordReset", ctx, mock.Anything).Return(errors.New("invalid or expired reset token"))

handler := &Handler{auth: mockAuth}

Expand All @@ -718,9 +721,12 @@ func TestHandler_resetPassword_Error(t *testing.T) {
encoded := base64.StdEncoding.EncodeToString([]byte("newpassword123"))
req := &events.LambdaFunctionURLRequest{Body: `{"token": "bad-token", "new_password": "` + encoded + `"}`}
result, err := handler.resetPassword(ctx, req)
assert.Error(t, err)
require.Error(t, err)
assert.Nil(t, result)
assert.Contains(t, err.Error(), "invalid or expired token")
ce, ok := IsClientError(err)
require.True(t, ok, "expired-token error must be wrapped as a client error (400)")
assert.Equal(t, 400, ce.code)
assert.Contains(t, ce.Error(), "invalid or expired reset token")
}

// Issue #459: ConfirmPasswordReset errors must surface as a 4xx client
Expand All @@ -732,6 +738,7 @@ func TestHandler_resetPassword_Error(t *testing.T) {
func TestHandler_resetPassword_ErrorIsClientError(t *testing.T) {
ctx := context.Background()
mockAuth := new(MockAuthService)
t.Cleanup(func() { mockAuth.AssertExpectations(t) })

mockAuth.On("ConfirmPasswordReset", ctx, mock.Anything).
Return(errors.New("this is your current password, choose a different one"))
Expand Down
Loading