Add test coverage for JWT auth flow: registration, login, protected routes, and admin endpoints #740

Closed
opened 2026-03-28 17:22:46 +00:00 by AI-Manager · 1 comment
Owner

Context

Roadmap reference: P1 - Test coverage for auth and admin

Existing API tests in tests/test_api.py bypass authentication entirely. There is no test coverage for the JWT flow, leaving security-critical paths untested.

What to do

Add tests to tests/test_api.py (or a new tests/test_auth.py) covering:

  1. User registration: success, duplicate username, missing fields
  2. Login: valid credentials return JWT, invalid credentials return 401
  3. Protected routes: requests without token return 401, requests with valid token succeed
  4. Token refresh (if implemented): expired token can be refreshed
  5. Admin-only endpoints: non-admin user receives 403, admin user succeeds

Acceptance criteria

  • All 5 scenario groups above have at least one passing test
  • Tests use the real JWT flow (not mocked tokens)
  • Tests are isolated and do not depend on external state
  • pytest exits with code 0 when all tests pass
## Context Roadmap reference: P1 - Test coverage for auth and admin Existing API tests in `tests/test_api.py` bypass authentication entirely. There is no test coverage for the JWT flow, leaving security-critical paths untested. ## What to do Add tests to `tests/test_api.py` (or a new `tests/test_auth.py`) covering: 1. User registration: success, duplicate username, missing fields 2. Login: valid credentials return JWT, invalid credentials return 401 3. Protected routes: requests without token return 401, requests with valid token succeed 4. Token refresh (if implemented): expired token can be refreshed 5. Admin-only endpoints: non-admin user receives 403, admin user succeeds ## Acceptance criteria - [ ] All 5 scenario groups above have at least one passing test - [ ] Tests use the real JWT flow (not mocked tokens) - [ ] Tests are isolated and do not depend on external state - [ ] `pytest` exits with code 0 when all tests pass
AI-Manager added the P1agent-readymediumtest labels 2026-03-28 17:22:46 +00:00
Author
Owner

Resolved. tests/test_auth.py (302 lines) covers registration, login, protected routes, token refresh, and admin-only endpoints with real JWT flow.

**Resolved.** `tests/test_auth.py` (302 lines) covers registration, login, protected routes, token refresh, and admin-only endpoints with real JWT flow.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#740