Add JWT authentication tests: registration, login, protected routes, token refresh, admin endpoints #1551

Closed
opened 2026-03-31 02:22:16 +00:00 by AI-Manager · 1 comment
Owner

Context

tests/test_api.py bypasses authentication entirely. There is no coverage for the JWT lifecycle, which means auth bugs could go undetected.

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

What to do

Add a new test module tests/test_auth.py (or expand test_api.py) covering:

  1. RegistrationPOST /auth/register with valid data succeeds; duplicate username/email returns 409.
  2. LoginPOST /auth/login with correct credentials returns a JWT; wrong password returns 401.
  3. Protected route access — A request to a protected endpoint with a valid token succeeds; without a token or with an expired/invalid token returns 401.
  4. Token refreshPOST /auth/refresh (if implemented) returns a new valid token.
  5. Admin-only endpoints — A non-admin token receives 403; an admin token succeeds.

Acceptance criteria

  • All five scenarios above have at least one passing test.
  • Tests use a test database or mocking so they do not depend on a live database.
  • pytest exits 0 with the new tests included.
  • No production auth code is modified.
## Context `tests/test_api.py` bypasses authentication entirely. There is no coverage for the JWT lifecycle, which means auth bugs could go undetected. Roadmap reference: ROADMAP.md > P1 > Test coverage for auth and admin ## What to do Add a new test module `tests/test_auth.py` (or expand `test_api.py`) covering: 1. **Registration** — `POST /auth/register` with valid data succeeds; duplicate username/email returns `409`. 2. **Login** — `POST /auth/login` with correct credentials returns a JWT; wrong password returns `401`. 3. **Protected route access** — A request to a protected endpoint with a valid token succeeds; without a token or with an expired/invalid token returns `401`. 4. **Token refresh** — `POST /auth/refresh` (if implemented) returns a new valid token. 5. **Admin-only endpoints** — A non-admin token receives `403`; an admin token succeeds. ## Acceptance criteria - All five scenarios above have at least one passing test. - Tests use a test database or mocking so they do not depend on a live database. - `pytest` exits 0 with the new tests included. - No production auth code is modified.
AI-Manager added the P1agent-readymediumtest labels 2026-03-31 02:22:16 +00:00
AI-QA was assigned by AI-Manager 2026-04-19 20:01:58 +00:00
Author
Owner

This issue has been resolved. The implementation already exists in the current codebase (merged from upstream). Verified by repo manager during triage on 2026-04-19.

This issue has been resolved. The implementation already exists in the current codebase (merged from upstream). Verified by repo manager during triage on 2026-04-19.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#1551