Skip to content

fix(auth): extract refresh token field and validate JWT with secret - #19

Merged
SrStamm merged 1 commit into
mainfrom
fix/refresh-token
Oct 17, 2026
Merged

SrStamm merged 1 commit into
mainfrom
fix/refresh-token

Conversation

@SrStamm

@SrStamm SrStamm commented Oct 17, 2026

Copy link
Copy Markdown
Owner

Summary

  • POST /refresh always returned 401: the router passed the whole RefreshTokenRequest model into AuthService.refresh, which fed it to jwt.get_unverified_claims/jwt.decode as if it were a raw string token. The service now reads the .refresh field and decodes it with SECRET and ALGORITHM.
  • The old refresh tests were disabled inside a string literal and targeted a router signature that no longer exists. They are replaced by unit tests over AuthService.refresh() covering every error branch (missing session, missing/wrong scope, missing sub, unknown user, missing/expired exp, invalid signature, database error) plus the session-rotation happy path.
  • test_refresh exercises the full HTTP path (200 with a valid token); a garbage token is asserted to return 401.

Changes

File Change
services/auth_services.py refresh() decodes refresh.refresh with SECRET/ALGORITHM instead of the Pydantic model
test/test_routers/test_auth.py 10 unit tests for AuthService.refresh() branches, HTTP integration test, garbage-token 401 test; removed dead string-literal tests and the no-assert test_refresh_token_format

Test plan

  • Full suite: pytest -q --disable-warnings → 169 passed (Redis up via docker compose)
  • Mutation testing: 7/7 branch mutations killed — each neutralized guard in refresh() makes exactly its covering test(s) fail
  • RED/GREEN: the fix was verified to fail against the pre-fix code (test_refresh: 401 ≠ 200) and pass with the fix
  • Pending B4/B6/B7 changes (README demo password, db/database.py, CORS origin) remain stashed and out of this PR

@SrStamm
SrStamm merged commit 1076ad9 into main Oct 17, 2026
1 check passed
@SrStamm
SrStamm deleted the fix/refresh-token branch October 17, 2026 22:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant