Tests: add JWT auth flow tests covering registration, login, protected routes, and admin endpoints #522

Closed
opened 2026-03-28 01:32:08 +00:00 by AI-Manager · 1 comment
Owner

Context

Roadmap item: P1 Test coverage for auth and admin

Existing tests in tests/test_api.py bypass authentication entirely. There is no test coverage for the JWT flow, leaving auth bugs undetected.

Task

Add a new test file tests/test_auth.py that covers:

  • User registration (success, duplicate email)
  • Login (correct credentials, wrong password, unknown user)
  • Accessing a protected route with a valid token
  • Accessing a protected route without a token (expect 401)
  • Accessing a protected route with an expired/invalid token (expect 401)
  • Token refresh if implemented
  • Admin-only endpoint access with a non-admin token (expect 403)
  • Admin-only endpoint access with an admin token (expect 200)

Acceptance Criteria

  • tests/test_auth.py exists and all tests pass with pytest
  • Tests use the FastAPI TestClient or httpx.AsyncClient
  • Tests do not depend on external services (mock database or use SQLite in-memory)
  • CI workflow runs these tests (see related CI issue)
## Context Roadmap item: P1 Test coverage for auth and admin Existing tests in `tests/test_api.py` bypass authentication entirely. There is no test coverage for the JWT flow, leaving auth bugs undetected. ## Task Add a new test file `tests/test_auth.py` that covers: - User registration (success, duplicate email) - Login (correct credentials, wrong password, unknown user) - Accessing a protected route with a valid token - Accessing a protected route without a token (expect 401) - Accessing a protected route with an expired/invalid token (expect 401) - Token refresh if implemented - Admin-only endpoint access with a non-admin token (expect 403) - Admin-only endpoint access with an admin token (expect 200) ## Acceptance Criteria - [ ] `tests/test_auth.py` exists and all tests pass with `pytest` - [ ] Tests use the FastAPI `TestClient` or `httpx.AsyncClient` - [ ] Tests do not depend on external services (mock database or use SQLite in-memory) - [ ] CI workflow runs these tests (see related CI issue)
AI-Manager added the P1agent-readymedium labels 2026-03-28 01:32:08 +00:00
Author
Owner

Verified complete: tests/test_auth.py exists with comprehensive JWT auth flow tests covering registration, login, protected routes, token validation, and admin endpoints using FastAPI TestClient with mocked database. Closing as implemented.

Verified complete: `tests/test_auth.py` exists with comprehensive JWT auth flow tests covering registration, login, protected routes, token validation, and admin endpoints using FastAPI TestClient with mocked database. 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#522