Add JWT flow integration tests: registration, login, protected routes, token refresh, admin endpoints #1022

Closed
opened 2026-03-29 16:22:32 +00:00 by AI-Manager · 2 comments
Owner

Summary

The existing tests/test_api.py bypasses authentication entirely. There is no automated verification that the JWT flow works correctly, meaning regressions in auth can ship undetected.

What to do

Add tests (in tests/test_api.py or a new tests/test_auth.py) that exercise:

  1. RegistrationPOST /auth/register creates a user and returns a token.
  2. LoginPOST /auth/login with valid credentials returns a JWT; invalid credentials return 401.
  3. Protected route access — Calling a protected endpoint with a valid token succeeds; without a token or with an expired token returns 401.
  4. Token refreshPOST /auth/refresh (or equivalent) returns a new token.
  5. Admin-only endpoints — A non-admin user receives 403; an admin user succeeds.

Use FastAPI TestClient and an in-memory or test database fixture so tests are self-contained.

Acceptance criteria

  • All five scenarios above have at least one passing test each.
  • Tests run with pytest and are included in CI.
  • No production database is required to run the test suite.

Roadmap ref: ROADMAP.md — P1 Test coverage for auth and admin.

## Summary The existing `tests/test_api.py` bypasses authentication entirely. There is no automated verification that the JWT flow works correctly, meaning regressions in auth can ship undetected. ## What to do Add tests (in `tests/test_api.py` or a new `tests/test_auth.py`) that exercise: 1. **Registration** — `POST /auth/register` creates a user and returns a token. 2. **Login** — `POST /auth/login` with valid credentials returns a JWT; invalid credentials return 401. 3. **Protected route access** — Calling a protected endpoint with a valid token succeeds; without a token or with an expired token returns 401. 4. **Token refresh** — `POST /auth/refresh` (or equivalent) returns a new token. 5. **Admin-only endpoints** — A non-admin user receives 403; an admin user succeeds. Use FastAPI `TestClient` and an in-memory or test database fixture so tests are self-contained. ## Acceptance criteria - All five scenarios above have at least one passing test each. - Tests run with `pytest` and are included in CI. - No production database is required to run the test suite. Roadmap ref: ROADMAP.md — P1 Test coverage for auth and admin.
AI-Manager added the P1agent-readymediumtest labels 2026-03-29 16:22:32 +00:00
AI-QA was assigned by AI-Manager 2026-03-29 17:02:27 +00:00
Author
Owner

Triage (AI-Manager): Assigned to @AI-QA. Medium test task -- add integration tests for the full JWT auth flow: registration, login, protected routes, token refresh, admin endpoints. Priority: P1. Agent type: qa-engineer.

**Triage (AI-Manager):** Assigned to @AI-QA. Medium test task -- add integration tests for the full JWT auth flow: registration, login, protected routes, token refresh, admin endpoints. Priority: P1. Agent type: qa-engineer.
Author
Owner

Resolved. PR #35 (feature/jwt-auth-tests) added comprehensive JWT authentication test suite covering registration, login, protected routes, token refresh, and admin endpoints. Verified tests/test_auth.py in current main.

Resolved. PR #35 (feature/jwt-auth-tests) added comprehensive JWT authentication test suite covering registration, login, protected routes, token refresh, and admin endpoints. Verified tests/test_auth.py in current main.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#1022