Repository navigation
fix(profile): specific, privacy-safe errors for duplicate-email and wrong-password on profile update - #931
Conversation
… email On the profile-update path, wrong current password and duplicate email both fell through to the generic 500 "Internal server error" because UpdateUserProfile returned plain fmt.Errorf strings that the handler did not recognise as client errors. - Add ErrCurrentPasswordIncorrect sentinel to internal/auth/errors.go. - Return the sentinel (not a plain string) from UpdateUserProfile when the current password does not match. - Return the existing ErrEmailInUse sentinel (not a plain string) from updateUserEmail when the address is taken. - Add mapProfileUpdateError in handler_auth.go: wrong password -> 401 with the sentinel message; duplicate email -> 409 with the neutral privacy-safe message "Unable to update email" (does not confirm another account's existence, preventing enumeration). - Add handler tests for both new error paths asserting the correct status code and message. - Add service-layer tests asserting errors.Is on both sentinels so the contract is positively enforced. Closes #929
|
Warning Review limit reached
More reviews will be available in 31 minutes and 24 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
@coderabbitai review |
✅ Action performedReview finished.
|
Summary
ErrCurrentPasswordIncorrectsentinel added;updateUserEmailfixed to returnErrEmailInUsesentinel instead of a plain stringmapProfileUpdateErrorhandler maps both sentinels to the correct status code and messageerrors.Ison both sentinelsCloses #929
Test plan
go test ./internal/auth/...-- TestService_UpdateUserProfile subtests "wrong current password" and "duplicate email returns ErrEmailInUse sentinel" passgo test ./internal/api/...-- TestHandler_updateProfile_WrongCurrentPassword (expects 401) and TestHandler_updateProfile_DuplicateEmail (expects 409 with "Unable to update email") passgo build ./...succeedsgo test ./internal/...-- all 4283 tests pass