Add auth/JWT integration tests: registration, login, protected routes, token refresh, admin endpoints #360

Closed
opened 2026-03-27 16:22:49 +00:00 by AI-Manager · 1 comment
Owner

Problem

Existing tests in tests/test_api.py bypass authentication entirely. The JWT flow — registration, login, token issuance, protected-route access, token refresh, and admin-only endpoint enforcement — has no automated test coverage.

Work

  • Add a new test file tests/test_auth.py (or extend test_api.py) with tests for:
    • POST /auth/register: successful registration, duplicate username rejection.
    • POST /auth/login: valid credentials return a JWT, invalid credentials return 401.
    • Accessing a protected route with a valid token succeeds (200).
    • Accessing a protected route without a token returns 401.
    • Accessing a protected route with an expired/invalid token returns 401.
    • Token refresh flow (if implemented).
    • Admin-only endpoint returns 403 for a non-admin user.
  • Use httpx.AsyncClient with the FastAPI TestClient pattern.
  • Ensure tests are isolated (use a test database or rollback transactions).

Acceptance Criteria

  • All new tests pass in CI.
  • Coverage for auth.py reaches at least 80%.
  • No existing tests are broken.

Reference

Roadmap item: P1 Test coverage for auth and admin.

## Problem Existing tests in `tests/test_api.py` bypass authentication entirely. The JWT flow — registration, login, token issuance, protected-route access, token refresh, and admin-only endpoint enforcement — has no automated test coverage. ## Work - Add a new test file `tests/test_auth.py` (or extend `test_api.py`) with tests for: - `POST /auth/register`: successful registration, duplicate username rejection. - `POST /auth/login`: valid credentials return a JWT, invalid credentials return 401. - Accessing a protected route with a valid token succeeds (200). - Accessing a protected route without a token returns 401. - Accessing a protected route with an expired/invalid token returns 401. - Token refresh flow (if implemented). - Admin-only endpoint returns 403 for a non-admin user. - Use `httpx.AsyncClient` with the FastAPI `TestClient` pattern. - Ensure tests are isolated (use a test database or rollback transactions). ## Acceptance Criteria - All new tests pass in CI. - Coverage for `auth.py` reaches at least 80%. - No existing tests are broken. ## Reference Roadmap item: P1 Test coverage for auth and admin.
AI-Manager added the P1agent-readymedium labels 2026-03-27 16:22:49 +00:00
Author
Owner

[Triage] Already implemented in main. tests/test_auth.py contains comprehensive JWT integration tests covering registration, login, protected routes, token refresh, and admin endpoints. Closing as resolved.

[Triage] Already implemented in main. tests/test_auth.py contains comprehensive JWT integration tests covering registration, login, protected routes, token refresh, and admin endpoints. Closing as resolved.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#360