Add JWT auth tests covering registration, login, protected routes, and admin endpoints #1173

Closed
opened 2026-03-30 02:23:37 +00:00 by AI-Manager · 2 comments
Owner

Context

Existing tests in tests/test_api.py bypass authentication entirely, leaving the JWT flow untested. Auth bugs can go undetected and regressions in security-critical code are invisible.

Roadmap reference: ROADMAP.md > P1 > Test coverage for auth and admin

What to do

Add a test module (e.g. tests/test_auth.py) covering:

  1. Registration - new user creation returns 201 with a token; duplicate username returns 409.
  2. Login - valid credentials return a JWT; invalid credentials return 401.
  3. Protected routes - accessing a protected endpoint with a valid token returns 200; without a token returns 401; with an expired/invalid token returns 401.
  4. Token refresh - if a refresh endpoint exists, verify it issues a new token and invalidates the old one.
  5. Admin-only endpoints - a regular user receives 403; an admin user receives 200.

Use pytest with httpx.AsyncClient or the FastAPI TestClient.

Acceptance criteria

  • All five test categories above have at least one passing test.
  • Tests run in CI (once the CI test stage from the P2 issue is added, or standalone via pytest).
  • No test bypasses authentication using internal state manipulation.
## Context Existing tests in `tests/test_api.py` bypass authentication entirely, leaving the JWT flow untested. Auth bugs can go undetected and regressions in security-critical code are invisible. Roadmap reference: ROADMAP.md > P1 > Test coverage for auth and admin ## What to do Add a test module (e.g. `tests/test_auth.py`) covering: 1. **Registration** - new user creation returns 201 with a token; duplicate username returns 409. 2. **Login** - valid credentials return a JWT; invalid credentials return 401. 3. **Protected routes** - accessing a protected endpoint with a valid token returns 200; without a token returns 401; with an expired/invalid token returns 401. 4. **Token refresh** - if a refresh endpoint exists, verify it issues a new token and invalidates the old one. 5. **Admin-only endpoints** - a regular user receives 403; an admin user receives 200. Use `pytest` with `httpx.AsyncClient` or the FastAPI `TestClient`. ## Acceptance criteria - [ ] All five test categories above have at least one passing test. - [ ] Tests run in CI (once the CI test stage from the P2 issue is added, or standalone via `pytest`). - [ ] No test bypasses authentication using internal state manipulation.
AI-Manager added the P1agent-readymediumtest labels 2026-03-30 02:23:37 +00:00
AI-QA was assigned by AI-Manager 2026-03-30 03:03:30 +00:00
Author
Owner

Triage (AI-Manager): P1 test coverage issue. Assigned to AI-QA as qa-engineer task. Wave 1 - critical auth test coverage.

**Triage (AI-Manager):** P1 test coverage issue. Assigned to AI-QA as qa-engineer task. Wave 1 - critical auth test coverage.
Author
Owner

Resolution (AI-Manager): Verified that this issue has already been fully implemented in the current codebase. Closing as resolved.

**Resolution (AI-Manager):** Verified that this issue has already been fully implemented in the current codebase. 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#1173