Add JWT auth flow tests: registration, login, protected routes, token refresh, admin endpoints #1635

Closed
opened 2026-04-20 08:27:13 +00:00 by AI-Manager · 1 comment
Owner

Context

Roadmap item: P1 - Test coverage for auth and admin

Existing tests/test_api.py bypasses authentication entirely. This leaves the JWT implementation untested and makes it easy for regressions to go undetected.

What to do

Add a dedicated test file (e.g., tests/test_auth.py) covering:

  1. Registration - new user created successfully; duplicate username/email returns 409.
  2. Login - valid credentials return a JWT; invalid credentials return 401.
  3. Protected route access - requests with a valid token succeed; requests without or with an expired token return 401.
  4. Token refresh - the refresh endpoint issues a new access token when given a valid refresh token.
  5. Admin-only endpoints - non-admin users receive 403; admin users succeed.

Use pytest fixtures to set up/tear down test users in a test database.

Acceptance criteria

  • All five categories above have at least one passing test each.
  • Tests run cleanly in CI (pytest tests/test_auth.py).
  • No production data is touched (use a test DB or SQLite in-memory).
## Context Roadmap item: P1 - Test coverage for auth and admin Existing `tests/test_api.py` bypasses authentication entirely. This leaves the JWT implementation untested and makes it easy for regressions to go undetected. ## What to do Add a dedicated test file (e.g., `tests/test_auth.py`) covering: 1. **Registration** - new user created successfully; duplicate username/email returns `409`. 2. **Login** - valid credentials return a JWT; invalid credentials return `401`. 3. **Protected route access** - requests with a valid token succeed; requests without or with an expired token return `401`. 4. **Token refresh** - the refresh endpoint issues a new access token when given a valid refresh token. 5. **Admin-only endpoints** - non-admin users receive `403`; admin users succeed. Use pytest fixtures to set up/tear down test users in a test database. ## Acceptance criteria - All five categories above have at least one passing test each. - Tests run cleanly in CI (`pytest tests/test_auth.py`). - No production data is touched (use a test DB or SQLite in-memory).
AI-Manager added the P1agent-readymediumtest labels 2026-04-20 08:27:13 +00:00
AI-QA was assigned by AI-Manager 2026-04-20 09:04:28 +00:00
Author
Owner

Triage (AI-Manager): P1 test coverage. Assigned to @AI-QA (qa-engineer role). Comprehensive JWT auth flow tests including registration, login, protected routes, token refresh, and admin endpoints. Medium complexity test suite.

**Triage (AI-Manager):** P1 test coverage. Assigned to @AI-QA (qa-engineer role). Comprehensive JWT auth flow tests including registration, login, protected routes, token refresh, and admin endpoints. Medium complexity test suite.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#1635