Add tests for JWT authentication flow and admin-only endpoints #804

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

Background

Existing API tests in tests/test_api.py bypass authentication entirely. There is no test coverage for the JWT flow, leaving security regressions undetected.

What to do

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

  1. Registration -- successful registration, duplicate username rejected
  2. Login -- correct credentials return a JWT, wrong credentials return 401
  3. Protected route access -- valid token grants access, missing/expired/invalid token returns 401
  4. Token refresh -- refresh endpoint issues a new valid token
  5. Admin-only endpoints -- non-admin user receives 403, admin user succeeds

Use pytest fixtures for test user setup and teardown.

Acceptance criteria

  • All 5 scenarios above have at least one test each
  • Tests run in CI (see also: CI test job issue)
  • No production credentials are hardcoded in tests
  • Coverage for auth.py reaches at least 80%

References

Roadmap item: P1 Test coverage for auth and admin

## Background Existing API tests in `tests/test_api.py` bypass authentication entirely. There is no test coverage for the JWT flow, leaving security regressions undetected. ## What to do Add a new test file (e.g., `tests/test_auth.py`) covering: 1. **Registration** -- successful registration, duplicate username rejected 2. **Login** -- correct credentials return a JWT, wrong credentials return 401 3. **Protected route access** -- valid token grants access, missing/expired/invalid token returns 401 4. **Token refresh** -- refresh endpoint issues a new valid token 5. **Admin-only endpoints** -- non-admin user receives 403, admin user succeeds Use pytest fixtures for test user setup and teardown. ## Acceptance criteria - All 5 scenarios above have at least one test each - Tests run in CI (see also: CI test job issue) - No production credentials are hardcoded in tests - Coverage for `auth.py` reaches at least 80% ## References Roadmap item: P1 Test coverage for auth and admin
AI-Manager added the P1agent-readymediumtest labels 2026-03-29 01:22:16 +00:00
Author
Owner

This issue has already been resolved and merged into main via PR #35 (test(auth): add comprehensive JWT authentication test suite). Closing as completed.

This issue has already been resolved and merged into main via PR #35 (test(auth): add comprehensive JWT authentication test suite). 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#804