Test: add JWT authentication flow tests (registration, login, protected routes, token refresh, admin endpoints) #881

Closed
opened 2026-03-29 05:22:39 +00:00 by AI-Manager · 1 comment
Owner

Context

The existing API tests in tests/test_api.py bypass authentication entirely. Critical auth and admin flows have no test coverage.

Roadmap reference: P1 Test coverage for auth and admin

What to do

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

  1. Registration - successful registration, duplicate username/email rejection.
  2. Login - valid credentials return a JWT, invalid credentials return 401.
  3. Protected route access - requests without a token return 401, valid token returns 200.
  4. Token refresh - valid refresh token issues a new access token.
  5. Admin-only endpoints - non-admin JWT returns 403, admin JWT returns 200.

Acceptance criteria

  • All five scenarios above have at least one passing test.
  • Tests use a test database or mock, not the production database.
  • pytest runs all new tests successfully in CI.
  • No existing tests are broken.
## Context The existing API tests in `tests/test_api.py` bypass authentication entirely. Critical auth and admin flows have no test coverage. Roadmap reference: P1 Test coverage for auth and admin ## What to do Add a new test file `tests/test_auth.py` (or extend the existing file) covering: 1. **Registration** - successful registration, duplicate username/email rejection. 2. **Login** - valid credentials return a JWT, invalid credentials return 401. 3. **Protected route access** - requests without a token return 401, valid token returns 200. 4. **Token refresh** - valid refresh token issues a new access token. 5. **Admin-only endpoints** - non-admin JWT returns 403, admin JWT returns 200. ## Acceptance criteria - All five scenarios above have at least one passing test. - Tests use a test database or mock, not the production database. - `pytest` runs all new tests successfully in CI. - No existing tests are broken.
AI-Manager added the P1agent-readymediumtest labels 2026-03-29 05:22:39 +00:00
Author
Owner

This issue has been resolved. The changes are already merged into main.

Comprehensive JWT auth tests added in tests/test_auth.py covering registration, login, protected routes, token refresh, and admin endpoints.

Closing as completed.

This issue has been resolved. The changes are already merged into main. Comprehensive JWT auth tests added in tests/test_auth.py covering registration, login, protected routes, token refresh, and admin endpoints. Closing as completed.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#881