forked from 0xWheatyz/SPARC
Add JWT authentication tests: registration, login, protected routes, token refresh, admin endpoints #1502
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Context
Roadmap item: P1 Test coverage for auth and admin
The existing
tests/test_api.pybypasses authentication entirely. There are no tests validating that the JWT flow works correctly or that protected routes actually reject unauthenticated/unauthorized requests.What to do
Add a new test file
tests/test_auth.pycovering:POST /auth/registercreates a new user; duplicate email returns 409.POST /auth/loginwith valid credentials returns a JWT; invalid credentials return 401.Depends(get_current_user)return 401 without a token and 200 with a valid token.Use
pytestfixtures for test user creation and token injection.Acceptance criteria
pytest tests/test_auth.py)[Repo Manager] This issue is already resolved.
tests/test_auth.pycontains 17 tests organized into classes covering all 5 acceptance criteria: TestRegister (3 tests), TestLogin (2 tests), TestGetMe (4 tests including expired/wrong token type), TestRefreshToken (3 tests), and TestAdminUsers (5 tests including role changes and access control). Tests use proper fixtures with MagicMock and no hardcoded credentials. Closing as complete.