Mock authentication has been successfully implemented for the Soul Sense EQ Test application.
- File:
backend/fastapi/api/services/mock_auth_service.py - Features:
- Complete authentication simulation
- Predefined test users (test@example.com, admin@example.com, 2fa@example.com)
- 2FA flow support
- Password reset simulation
- Token management (access + refresh)
- Same interface as real AuthService
- File:
backend/fastapi/api/config.py - Added:
mock_auth_modeboolean field - Default:
False(disabled by default)
- File:
backend/fastapi/api/routers/auth.py - Added:
get_auth_service()dependency function - Updated: All endpoints to use the new dependency
- Behavior: Automatically switches between real and mock auth based on config
- File:
frontend-web/src/hooks/useAuth.tsx - Features:
- Real API authentication support
- Mock mode detection
- Automatic mode switching
- File:
frontend-web/src/components/MockModeBanner.tsx - Components:
MockModeBanner: Full-width banner at topMockModeIndicator: Corner indicator with tooltip- Animated 🎭 emoji for easy identification
- File:
tests/test_mock_auth.py - Coverage:
- User authentication (email and username)
- 2FA flow (initiate and verify)
- Token management (create, refresh, revoke)
- Password reset flow
- 2FA setup flow
- All mock users
- File:
docs/MOCK_AUTH.md - Contents:
- Feature overview
- Configuration instructions
- Mock test users and credentials
- Usage examples for all flows
- Security considerations
- Troubleshooting guide
- Architecture details
- File:
docs/MOCK_AUTH_QUICKSTART.md - Contents:
- 5-minute setup
- Test scenarios
- Common use cases
- Troubleshooting checklist
- File:
.env.test.example - Purpose: Ready-to-use configuration for testing
- File:
README.md - Added: Mock authentication to Developer Experience section
- Mock authentication service implemented
- Configuration flag added (
MOCK_AUTH_MODE) - Automatic service selection based on config
- All authentication flows work in mock mode:
- Login (username/email)
- Registration
- 2FA authentication
- Password reset
- Token refresh
- Token revocation
- No database required for authentication
- No password validation
- Predefined test users
- In-memory token storage
- Full API compatibility
| Username | Password | 2FA | OTP Code | |
|---|---|---|---|---|
| test@example.com | testuser | any | No | 123456 |
| admin@example.com | admin | any | No | 654321 |
| 2fa@example.com | twofa | any | Yes | 999999 |
Special Codes:
- 2FA Setup:
888888
# Set environment variable
MOCK_AUTH_MODE=true
# Or in .env file
echo "MOCK_AUTH_MODE=true" >> .env# Start backend
python backend/fastapi/start_server.py
# Login with any test user
curl -X POST http://localhost:8000/api/v1/auth/login \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "username=test@example.com&password=anything"# Set mock mode
$env:MOCK_AUTH_MODE="true"
# Run mock auth tests
pytest tests/test_mock_auth.py -vThe mock authentication test suite includes:
- ✅ Authentication with email
- ✅ Authentication with username
- ✅ Case-insensitive authentication
- ✅ Invalid user handling
- ✅ Access token creation
- ✅ Pre-auth token creation
- ✅ Complete 2FA flow
- ✅ Invalid 2FA code handling
- ✅ Refresh token flow
- ✅ Token rotation
- ✅ Invalid refresh token handling
- ✅ Token revocation
- ✅ Password reset flow
- ✅ Invalid OTP handling
- ✅ 2FA setup flow
- ✅ 2FA disable
- ✅ Last login update
- Never enable in production
- Passwords are not validated
- OTP codes are predictable
- No real security measures
- Data is not persisted
backend/fastapi/api/services/mock_auth_service.py- Mock auth servicetests/test_mock_auth.py- Test suitedocs/MOCK_AUTH.md- Comprehensive documentationdocs/MOCK_AUTH_QUICKSTART.md- Quick start guide.env.test.example- Example environment filefrontend-web/src/components/MockModeBanner.tsx- Visual indicators
backend/fastapi/api/config.py- Added mock_auth_mode fieldbackend/fastapi/api/routers/auth.py- Added dependency injectionfrontend-web/src/hooks/useAuth.tsx- Added mock mode supportREADME.md- Added feature mention
When mock mode is active, users will see:
- 🎭 Banner: Purple gradient banner at top of page
- 🎭 Indicator: Animated corner indicator (alternative)
- 🎭 Logs: All mock auth operations logged with emoji
- Enable mock mode: Set
MOCK_AUTH_MODE=true - Start backend:
python backend/fastapi/start_server.py - Check logs: Look for 🎭 emoji
- Test login: Use any test user with any password
- Verify response: Should receive valid JWT tokens
- Set environment:
$env:MOCK_AUTH_MODE="true" - Run tests:
pytest tests/test_mock_auth.py -v - Check results: All tests should pass
Potential enhancements:
- Add more mock users via environment variables
- Implement mock user registration persistence
- Add simulated rate limiting
- Create mock email service integration
- Add performance metrics
- ✅ Mock mode can be enabled via environment variable
- ✅ All authentication flows work without real credentials
- ✅ Tests pass with mock authentication
- ✅ Documentation is comprehensive
- ✅ Frontend detects and displays mock mode
- ✅ Same API interface as real authentication
- ✅ No database required for auth operations
For questions or issues:
- Check
docs/MOCK_AUTH.mdfor detailed documentation - Review
docs/MOCK_AUTH_QUICKSTART.mdfor quick setup - Check test files for working examples
- Look for 🎭 in logs to verify mock mode is active
Implementation Date: 2026-02-10
Status: ✅ Complete
Version: 1.0.0