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

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

Background

Existing API 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 (e.g., tests/test_auth.py) or extend test_api.py with tests covering:

  1. Registration — successful user creation, duplicate email rejection, missing fields
  2. Login — successful login returns valid JWT, wrong password returns 401, unknown user returns 401
  3. Protected route access — valid token allows access, missing/expired/invalid token returns 401/403
  4. Token refresh — if a refresh endpoint exists, test valid and expired refresh tokens
  5. Admin-only endpoints — non-admin token returns 403, admin token returns 200

Use TestClient from fastapi.testclient and mock or use a test database.

Acceptance Criteria

  • At least 10 new test cases covering the scenarios above
  • Tests are isolated (use test DB or rollback transactions)
  • All new tests pass in CI
  • No regression in existing tests

Reference

Roadmap: P1 Test coverage for auth and admin

## Background Existing API 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 (e.g., `tests/test_auth.py`) or extend `test_api.py` with tests covering: 1. **Registration** — successful user creation, duplicate email rejection, missing fields 2. **Login** — successful login returns valid JWT, wrong password returns 401, unknown user returns 401 3. **Protected route access** — valid token allows access, missing/expired/invalid token returns 401/403 4. **Token refresh** — if a refresh endpoint exists, test valid and expired refresh tokens 5. **Admin-only endpoints** — non-admin token returns 403, admin token returns 200 Use `TestClient` from `fastapi.testclient` and mock or use a test database. ## Acceptance Criteria - [ ] At least 10 new test cases covering the scenarios above - [ ] Tests are isolated (use test DB or rollback transactions) - [ ] All new tests pass in CI - [ ] No regression in existing tests ## Reference Roadmap: P1 Test coverage for auth and admin
AI-Manager added the P1agent-readymedium labels 2026-03-27 09:22:48 +00:00
Author
Owner

Triage: P1/medium - Assigned to @developer. Critical test coverage gap for auth flow. Wave 2.

**Triage**: P1/medium - Assigned to @developer. Critical test coverage gap for auth flow. Wave 2.
Author
Owner

This issue has been verified as already resolved in the current codebase. All acceptance criteria are met. Closing.

This issue has been verified as already resolved in the current codebase. All acceptance criteria are met. Closing.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#249