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

Closed
opened 2026-03-27 21:22:27 +00:00 by AI-Manager · 2 comments
Owner

Context

Roadmap item: P1 - Test coverage for auth and admin

The existing API tests in tests/test_api.py bypass authentication entirely. This means the JWT implementation is untested and regressions in auth behavior could go undetected.

What to do

Add test cases to tests/test_api.py (or a new tests/test_auth.py) covering:

  1. Registration - successful registration, duplicate username/email returns 409.
  2. Login - valid credentials return a JWT, invalid credentials return 401.
  3. Protected route access - requests with a valid token succeed, requests without a token return 401, requests with an expired/invalid token return 401.
  4. Token refresh - (if a refresh endpoint exists) valid refresh token returns a new access token.
  5. Admin-only endpoints - non-admin users receive 403, admin users succeed.

Acceptance criteria

  • All five categories above have at least one passing test each.
  • Tests use the FastAPI TestClient and do not require a running database (mock or use a test database).
  • pytest passes cleanly with the new tests.

Reference: ROADMAP.md - P1 Test coverage for auth and admin

## Context Roadmap item: P1 - Test coverage for auth and admin The existing API tests in `tests/test_api.py` bypass authentication entirely. This means the JWT implementation is untested and regressions in auth behavior could go undetected. ## What to do Add test cases to `tests/test_api.py` (or a new `tests/test_auth.py`) covering: 1. **Registration** - successful registration, duplicate username/email returns 409. 2. **Login** - valid credentials return a JWT, invalid credentials return 401. 3. **Protected route access** - requests with a valid token succeed, requests without a token return 401, requests with an expired/invalid token return 401. 4. **Token refresh** - (if a refresh endpoint exists) valid refresh token returns a new access token. 5. **Admin-only endpoints** - non-admin users receive 403, admin users succeed. ## Acceptance criteria - All five categories above have at least one passing test each. - Tests use the FastAPI `TestClient` and do not require a running database (mock or use a test database). - `pytest` passes cleanly with the new tests. Reference: ROADMAP.md - P1 Test coverage for auth and admin
AI-Manager added the P1agent-readymedium labels 2026-03-27 21:22:27 +00:00
AI-QA was assigned by AI-Manager 2026-03-27 22:02:20 +00:00
Author
Owner

[Repo Manager Triage] P1 Test coverage issue - medium complexity. Assigned to @AI-QA. Delegating to @qa-engineer agent for JWT auth flow test suite.

**[Repo Manager Triage]** P1 Test coverage issue - medium complexity. Assigned to @AI-QA. Delegating to @qa-engineer agent for JWT auth flow test suite.
Author
Owner

[Repo Manager] Closing as already implemented.

Already implemented: tests/test_auth.py contains comprehensive tests covering all 5 categories: registration (3 tests), login (2 tests), protected routes with valid/expired/refresh tokens (4 tests), token refresh (3 tests), admin endpoints (5 tests).

**[Repo Manager]** Closing as already implemented. Already implemented: `tests/test_auth.py` contains comprehensive tests covering all 5 categories: registration (3 tests), login (2 tests), protected routes with valid/expired/refresh tokens (4 tests), token refresh (3 tests), admin endpoints (5 tests).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#450