Implemented complete JWT-based authentication system with RBAC: **Tests (TDD Approach):** - Created contract tests for /api/v1/auth/login endpoint - Created contract tests for /api/v1/auth/logout endpoint - Created unit tests for AuthService (login, logout, validate_token, password hashing) - Created pytest configuration and fixtures (test DB, test users, tokens) **Schemas:** - LoginRequest: username/password validation - TokenResponse: access_token, refresh_token, user info - LogoutResponse: logout confirmation - RefreshTokenRequest: token refresh payload - UserInfo: user data (excludes password_hash) **Services:** - AuthService: login(), logout(), validate_token(), hash_password(), verify_password() - Integrated bcrypt password hashing - JWT token generation (access + refresh tokens) - Token blacklisting in Redis - Audit logging for all auth operations **Middleware:** - Authentication middleware with JWT validation - Role-based access control (RBAC) helpers - require_role() dependency factory - Convenience dependencies: require_viewer(), require_operator(), require_administrator() - Client IP and User-Agent extraction **Router:** - POST /api/v1/auth/login - Authenticate and get tokens - POST /api/v1/auth/logout - Blacklist token - POST /api/v1/auth/refresh - Refresh access token - GET /api/v1/auth/me - Get current user info **Integration:** - Registered auth router in main.py - Updated startup event to initialize Redis and SDK Bridge clients - Updated shutdown event to cleanup connections properly - Fixed error translation utilities - Added asyncpg dependency for PostgreSQL async driver 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
31 lines
647 B
INI
31 lines
647 B
INI
[pytest]
|
|
# Pytest configuration
|
|
testpaths = src/api/tests
|
|
python_files = test_*.py
|
|
python_classes = Test*
|
|
python_functions = test_*
|
|
asyncio_mode = auto
|
|
|
|
# Add src/api to Python path for imports
|
|
pythonpath = src/api
|
|
|
|
# Logging
|
|
log_cli = true
|
|
log_cli_level = INFO
|
|
log_cli_format = %(asctime)s [%(levelname)8s] %(message)s
|
|
log_cli_date_format = %Y-%m-%d %H:%M:%S
|
|
|
|
# Coverage options (if using pytest-cov)
|
|
addopts =
|
|
--verbose
|
|
--strict-markers
|
|
--tb=short
|
|
--color=yes
|
|
|
|
# Markers
|
|
markers =
|
|
asyncio: mark test as async
|
|
unit: mark test as unit test
|
|
integration: mark test as integration test
|
|
slow: mark test as slow running
|