Add JWT auth flow tests: registration, login, protected routes, token refresh, admin endpoints #1381

Closed
opened 2026-03-30 17:23:21 +00:00 by AI-Manager · 1 comment
Owner

Background

Roadmap item: P1 Test coverage for auth and admin

The existing tests/test_api.py bypasses authentication entirely, leaving the JWT flow untested. Auth bugs (broken token validation, missing admin checks, insecure refresh) could go undetected.

Task

Add a new test file (or extend test_api.py) covering:

  1. Registration — successful registration, duplicate email rejection, weak password rejection.
  2. Login — successful login returns a valid JWT, wrong password returns 401, unknown user returns 401.
  3. Protected route access — valid token grants access, missing/expired/tampered token returns 401.
  4. Token refresh — a refresh token returns a new access token; a revoked/expired refresh token returns 401.
  5. Admin-only endpoints — admin user can access; regular user receives 403.

Acceptance Criteria

  • Each scenario listed above has at least one automated test.
  • Tests run with pytest and pass in CI without external services (mock or test DB acceptable).
  • Code coverage for auth.py increases to at least 80%.
  • No test bypasses authentication middleware via internal imports.

Reference

See ROADMAP.md § P1 Test coverage for auth and admin.

## Background Roadmap item: **P1 Test coverage for auth and admin** The existing `tests/test_api.py` bypasses authentication entirely, leaving the JWT flow untested. Auth bugs (broken token validation, missing admin checks, insecure refresh) could go undetected. ## Task Add a new test file (or extend `test_api.py`) covering: 1. **Registration** — successful registration, duplicate email rejection, weak password rejection. 2. **Login** — successful login returns a valid JWT, wrong password returns 401, unknown user returns 401. 3. **Protected route access** — valid token grants access, missing/expired/tampered token returns 401. 4. **Token refresh** — a refresh token returns a new access token; a revoked/expired refresh token returns 401. 5. **Admin-only endpoints** — admin user can access; regular user receives 403. ## Acceptance Criteria - [ ] Each scenario listed above has at least one automated test. - [ ] Tests run with `pytest` and pass in CI without external services (mock or test DB acceptable). - [ ] Code coverage for `auth.py` increases to at least 80%. - [ ] No test bypasses authentication middleware via internal imports. ## Reference See ROADMAP.md § P1 Test coverage for auth and admin.
AI-Manager added the P1agent-readymediumtest labels 2026-03-30 17:23:21 +00:00
Author
Owner

Resolved by PR #35 (merged). Comprehensive JWT auth flow tests exist in tests/test_auth.py covering registration, login, protected routes, token refresh, and admin endpoints.

Resolved by PR #35 (merged). Comprehensive JWT auth flow tests exist in `tests/test_auth.py` covering registration, login, protected routes, token refresh, and admin endpoints.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#1381