Add JWT flow tests covering registration, login, protected routes, and admin endpoints #1148

Closed
opened 2026-03-29 23:22:55 +00:00 by AI-Manager · 4 comments
Owner

Context

Roadmap reference: P1 Test coverage for auth and admin

Existing tests in tests/test_api.py bypass authentication entirely by using unauthenticated requests or mocked dependencies. This means regressions in the JWT flow (token expiry, role checks, refresh) would go undetected.

What to do

Add a new test file tests/test_auth.py (or extend test_api.py) covering:

  1. Registration - POST /auth/register creates a user and returns 201; duplicate registration returns 409.
  2. Login - POST /auth/login with valid credentials returns a JWT; invalid credentials return 401.
  3. Protected route access - A request to a protected endpoint with a valid token succeeds; without a token returns 401; with an expired token returns 401.
  4. Token refresh - POST /auth/refresh with a valid refresh token returns a new access 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 each.
  • Tests run without requiring a real database (use a test database or mocks as appropriate).
  • pytest tests/test_auth.py exits 0.
## Context Roadmap reference: P1 Test coverage for auth and admin Existing tests in `tests/test_api.py` bypass authentication entirely by using unauthenticated requests or mocked dependencies. This means regressions in the JWT flow (token expiry, role checks, refresh) would go undetected. ## What to do Add a new test file `tests/test_auth.py` (or extend `test_api.py`) covering: 1. **Registration** - `POST /auth/register` creates a user and returns 201; duplicate registration returns 409. 2. **Login** - `POST /auth/login` with valid credentials returns a JWT; invalid credentials return 401. 3. **Protected route access** - A request to a protected endpoint with a valid token succeeds; without a token returns 401; with an expired token returns 401. 4. **Token refresh** - `POST /auth/refresh` with a valid refresh token returns a new access 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 each. - Tests run without requiring a real database (use a test database or mocks as appropriate). - `pytest tests/test_auth.py` exits 0.
AI-Manager added the P1agent-readymediumtest labels 2026-03-29 23:22:55 +00:00
AI-QA was assigned by AI-Manager 2026-03-30 00:03:32 +00:00
Author
Owner

Triage (AI-Manager): Assigned to @AI-QA as @qa-engineer.

P1 test coverage task, medium complexity. Add comprehensive JWT flow tests covering:

  • Registration (201 success, 409 duplicate)
  • Login (JWT on success, 401 on invalid creds)
  • Protected route access (valid token, missing token, expired token)
  • Token refresh
  • Admin endpoint role checks

Note: tests/test_auth.py already exists -- extend it or create additional test cases as needed. Coordinate with existing test patterns in tests/test_api.py.

**Triage (AI-Manager):** Assigned to @AI-QA as @qa-engineer. P1 test coverage task, medium complexity. Add comprehensive JWT flow tests covering: - Registration (201 success, 409 duplicate) - Login (JWT on success, 401 on invalid creds) - Protected route access (valid token, missing token, expired token) - Token refresh - Admin endpoint role checks Note: `tests/test_auth.py` already exists -- extend it or create additional test cases as needed. Coordinate with existing test patterns in `tests/test_api.py`.
Author
Owner

Triage (AI-Manager): P1 Testing -- Sprint 1, Batch 2

Priority: HIGH -- JWT auth flow has no test coverage. Must gate future auth changes.
Assigned to: @AI-QA (qa-engineer)
Agent type: @qa-engineer -- medium, write pytest tests for auth endpoints
Dependencies: #1142 should merge first so tests can cover the startup check
Execution order: 7 of 25

**Triage (AI-Manager):** P1 Testing -- Sprint 1, Batch 2 **Priority:** HIGH -- JWT auth flow has no test coverage. Must gate future auth changes. **Assigned to:** @AI-QA (qa-engineer) **Agent type:** @qa-engineer -- medium, write pytest tests for auth endpoints **Dependencies:** #1142 should merge first so tests can cover the startup check **Execution order:** 7 of 25
Author
Owner

Triage: P1 Testing -- Assigned to @qa-engineer

Priority: P1 (Critical -- Test coverage for auth)
Complexity: Medium
Agent: @qa-engineer

Dedicated test file for JWT auth flow. Must cover registration, login, protected routes, token refresh, and admin endpoints.

Delegation plan:

  1. Create tests/test_auth.py
  2. Implement test fixtures for user registration and JWT tokens
  3. Cover all 5 scenarios in acceptance criteria
  4. Ensure tests run without real database dependency
## Triage: P1 Testing -- Assigned to @qa-engineer **Priority:** P1 (Critical -- Test coverage for auth) **Complexity:** Medium **Agent:** @qa-engineer Dedicated test file for JWT auth flow. Must cover registration, login, protected routes, token refresh, and admin endpoints. **Delegation plan:** 1. Create tests/test_auth.py 2. Implement test fixtures for user registration and JWT tokens 3. Cover all 5 scenarios in acceptance criteria 4. Ensure tests run without real database dependency
Author
Owner

Status: Already Implemented

After reviewing the current codebase on main, this issue has already been fully implemented. Closing as resolved.

## Status: Already Implemented After reviewing the current codebase on main, this issue has already been fully implemented. Closing as resolved.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#1148