fix: return HTTP 400 for invalid/expired/used tokens on confirm endpoint #139
No reviewers
Labels
No labels
domain:backend
domain:devops
domain:frontend
status:approved
status:in-progress
status:needs-fix
status:qa
type:bug
type:devops
type:feature
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
forgejo_admin/basketball-api!139
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "138-fix-confirm-status-code"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Changes
src/basketball_api/routes/password_reset.py: ImportJSONResponse; change three error return paths (invalid token, used token, expired token) fromPasswordResetResponse(...)(200) toJSONResponse(status_code=400, content={...})tests/test_password_reset.py: Update three test assertions (test_rejects_invalid_token,test_rejects_expired_token,test_rejects_used_token) to expect HTTP 400 instead of 200; update docstringsTest Plan
pytest tests/test_password_reset.py -v-- all 7 tests passruff checkandruff format --check-- clean/request) still returns 200 for all cases (no user enumeration change)Review Checklist
Related
Self-Review
Reviewed the diff. No issues found.
Verified:
confirm_password_resetchanged fromPasswordResetResponse(...)(200) toJSONResponse(status_code=400, ...)Ready for human review.
PR #139 Review
DOMAIN REVIEW
Tech stack: Python / FastAPI / SQLAlchemy / Pydantic
Correctness verified:
/confirmnow return HTTP 400 viaJSONResponse: invalid token, used token, expired token. Message bodies are identical to the previousPasswordResetResponsevalues -- no frontend breakage.PasswordResetResponse(message="Your password has been reset successfully.")) still returns 200. Correct.PasswordResetResponse. This is intentional -- server-side failures should not be exposed as 4xx to the client./requestendpoint is completely untouched. Still returns 200 for all cases (no user enumeration). Correct.JSONResponseimport added cleanly. No unused imports.FastAPI pattern note: The
response_model=PasswordResetResponseon the/confirmendpoint describes the 200 success shape. TheJSONResponsereturns for error paths bypass the response model, which is standard FastAPI practice for non-200 responses. No issue here.Test coverage: 7 tests covering all paths -- 3 error paths now assert 400, success path asserts 200, Keycloak failure asserts 200, request endpoint tests assert 200 for both known and unknown emails. Docstrings updated to match.
BLOCKERS
None.
NITS
None. This is a clean, minimal, correct fix.
SOP COMPLIANCE
138-fix-confirm-status-codereferences #138)Closes forgejo_admin/basketball-api#138)PROCESS OBSERVATIONS
Tight, well-scoped bugfix. Two files changed, +19/-9 lines, all directly relevant. The test plan in the PR body explicitly confirms ruff compliance and that the request endpoint was verified unchanged. Low change failure risk.
VERDICT: APPROVED