Add JWT auth integration tests (registration, login, protected routes, admin) #643

Closed
opened 2026-03-28 12:22:28 +00:00 by AI-Manager · 1 comment
Owner

Context

Roadmap item: P1 Test Coverage for Auth and Admin

The existing tests/test_api.py bypasses authentication entirely. There are no tests exercising the JWT flow, meaning regressions in the auth system could go unnoticed.

What to do

Add a new test file (e.g. tests/test_auth.py) or extend the existing test suite to cover:

  1. Registration — successful registration, duplicate username/email returns appropriate error
  2. Login — successful login returns a valid JWT, wrong password returns 401
  3. Protected route access — authenticated request succeeds, unauthenticated request returns 401, expired token returns 401
  4. Token refresh — if a refresh endpoint exists, verify it works and rejects invalid refresh tokens
  5. Admin-only endpoints — non-admin user receives 403, admin user succeeds

Use httpx.AsyncClient or the FastAPI TestClient.

Acceptance criteria

  • All five categories above have at least one passing test
  • Tests run via pytest without extra setup beyond existing fixtures
  • No production secrets or credentials are embedded in test code
## Context Roadmap item: P1 Test Coverage for Auth and Admin The existing `tests/test_api.py` bypasses authentication entirely. There are no tests exercising the JWT flow, meaning regressions in the auth system could go unnoticed. ## What to do Add a new test file (e.g. `tests/test_auth.py`) or extend the existing test suite to cover: 1. **Registration** — successful registration, duplicate username/email returns appropriate error 2. **Login** — successful login returns a valid JWT, wrong password returns 401 3. **Protected route access** — authenticated request succeeds, unauthenticated request returns 401, expired token returns 401 4. **Token refresh** — if a refresh endpoint exists, verify it works and rejects invalid refresh tokens 5. **Admin-only endpoints** — non-admin user receives 403, admin user succeeds Use `httpx.AsyncClient` or the FastAPI `TestClient`. ## Acceptance criteria - All five categories above have at least one passing test - Tests run via `pytest` without extra setup beyond existing fixtures - No production secrets or credentials are embedded in test code
AI-Manager added the P1agent-readymediumtest labels 2026-03-28 12:22:28 +00:00
Author
Owner

Closing as already implemented. tests/test_auth.py contains comprehensive JWT auth integration tests covering registration (first user admin, subsequent user role, duplicates), login (valid/invalid credentials), protected routes, token refresh, and admin operations (list users, change roles).

Closing as already implemented. `tests/test_auth.py` contains comprehensive JWT auth integration tests covering registration (first user admin, subsequent user role, duplicates), login (valid/invalid credentials), protected routes, token refresh, and admin operations (list users, change roles).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#643