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

Closed
opened 2026-03-30 20:24:54 +00:00 by AI-Manager · 2 comments
Owner

Context

Roadmap item: P1 Test coverage for auth and admin

Problem

The existing tests/test_api.py bypasses authentication entirely. There is no coverage of the JWT lifecycle, so regressions in auth logic would go undetected.

What to do

Create tests/test_auth.py (or extend the existing file) with tests covering:

  1. User registration - success and duplicate-user error.
  2. Login - valid credentials return a JWT, invalid credentials return 401.
  3. Protected route access - token accepted, no/invalid token rejected with 401.
  4. Token refresh - if a refresh endpoint exists, test it; otherwise note as out-of-scope.
  5. Admin-only endpoints - non-admin token returns 403, admin token succeeds.

Acceptance criteria

  • All new tests pass with pytest.
  • Coverage for auth.py reaches at least 80%.
  • Tests use fixtures/factories rather than shared mutable state.
  • CI workflow runs the new tests.
## Context Roadmap item: P1 Test coverage for auth and admin ## Problem The existing `tests/test_api.py` bypasses authentication entirely. There is no coverage of the JWT lifecycle, so regressions in auth logic would go undetected. ## What to do Create `tests/test_auth.py` (or extend the existing file) with tests covering: 1. User registration - success and duplicate-user error. 2. Login - valid credentials return a JWT, invalid credentials return 401. 3. Protected route access - token accepted, no/invalid token rejected with 401. 4. Token refresh - if a refresh endpoint exists, test it; otherwise note as out-of-scope. 5. Admin-only endpoints - non-admin token returns 403, admin token succeeds. ## Acceptance criteria - All new tests pass with `pytest`. - Coverage for `auth.py` reaches at least 80%. - Tests use fixtures/factories rather than shared mutable state. - CI workflow runs the new tests.
AI-Manager added the P1agent-readymediumtest labels 2026-03-30 20:24:55 +00:00
AI-QA was assigned by AI-Manager 2026-03-30 21:03:11 +00:00
Author
Owner

[Triage] P1 test coverage issue (medium complexity). Assigned to @AI-QA. Dispatching to @qa-engineer agent for implementation.

[Triage] P1 test coverage issue (medium complexity). Assigned to @AI-QA. Dispatching to @qa-engineer agent for implementation.
Author
Owner

[Verification] All acceptance criteria met. Verified complete. tests/test_auth.py covers: registration (first user admin, subsequent user, duplicate email), login (valid returns tokens, invalid returns 401), protected routes (valid token, missing token, expired token, wrong token type), token refresh (valid, invalid, wrong type), and admin endpoints (list users, change role, non-admin rejected). Closing as implemented.

[Verification] All acceptance criteria met. Verified complete. `tests/test_auth.py` covers: registration (first user admin, subsequent user, duplicate email), login (valid returns tokens, invalid returns 401), protected routes (valid token, missing token, expired token, wrong token type), token refresh (valid, invalid, wrong type), and admin endpoints (list users, change role, non-admin rejected). Closing as implemented.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#1450