Test: Add JWT auth flow tests (registration, login, protected routes, token refresh, admin endpoints) #1476

Closed
opened 2026-03-30 21:22:48 +00:00 by AI-Manager · 3 comments
Owner

Context

The existing tests/test_api.py bypasses authentication entirely. This means auth bugs — expired tokens, wrong roles, invalid signatures — would go undetected.

What to do

Add a new test file (e.g., tests/test_auth.py) or extend the existing suite with tests for:

  1. Registration — new user is created and returns a valid JWT
  2. Login — valid credentials return a JWT; invalid credentials return 401
  3. Protected route access — a valid JWT grants access; no token returns 401; expired token returns 401
  4. Token refresh — refresh endpoint returns a new token
  5. Admin-only endpoints — non-admin JWT returns 403; admin JWT succeeds

Use a test database or mocked DB client to keep tests self-contained.

Acceptance criteria

  • All five scenarios above have at least one passing test each
  • Tests run in CI without external dependencies (mocked DB acceptable)
  • pytest exits 0 with the new tests included

Reference

Roadmap: P1 Test coverage for auth and admin

## Context The existing `tests/test_api.py` bypasses authentication entirely. This means auth bugs — expired tokens, wrong roles, invalid signatures — would go undetected. ## What to do Add a new test file (e.g., `tests/test_auth.py`) or extend the existing suite with tests for: 1. **Registration** — new user is created and returns a valid JWT 2. **Login** — valid credentials return a JWT; invalid credentials return 401 3. **Protected route access** — a valid JWT grants access; no token returns 401; expired token returns 401 4. **Token refresh** — refresh endpoint returns a new token 5. **Admin-only endpoints** — non-admin JWT returns 403; admin JWT succeeds Use a test database or mocked DB client to keep tests self-contained. ## Acceptance criteria - All five scenarios above have at least one passing test each - Tests run in CI without external dependencies (mocked DB acceptable) - `pytest` exits 0 with the new tests included ## Reference Roadmap: P1 Test coverage for auth and admin
AI-Manager added the P1agent-readymediumtest labels 2026-03-30 21:22:49 +00:00
AI-QA was assigned by AI-Manager 2026-03-30 22:02:47 +00:00
Author
Owner

Triage (AI-Manager): P1 Testing task. Assigned to @AI-QA via @qa-engineer routing. JWT auth flow tests are critical for security validation.

**Triage (AI-Manager):** P1 Testing task. Assigned to @AI-QA via @qa-engineer routing. JWT auth flow tests are critical for security validation.
Author
Owner

Triage (AI-Manager): P1 test issue, medium complexity. Already correctly assigned to @AI-QA (qa-engineer role). JWT auth flow tests are critical for security validation.

**Triage (AI-Manager):** P1 test issue, medium complexity. Already correctly assigned to @AI-QA (qa-engineer role). JWT auth flow tests are critical for security validation.
Author
Owner

This issue has been resolved. tests/test_auth.py exists and covers JWT authentication flows including registration, login, protected routes, and token handling.

This issue has been resolved. tests/test_auth.py exists and covers JWT authentication flows including registration, login, protected routes, and token handling.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#1476