This guide will help you quickly set up and test the mock authentication feature.
Create a .env file in the project root (or copy .env.test.example):
# Copy the example file
cp .env.test.example .env
# Or create manually with this content:
MOCK_AUTH_MODE=true
APP_ENV=development# Navigate to backend directory
cd backend/fastapi
# Install dependencies (if not already done)
pip install -r requirements.txt
# Start the server
uvicorn api.main:app --reload --port 8000Check the server logs for the 🎭 emoji:
🎭 Mock Authentication Service initialized
Or visit: http://localhost:8000/api/v1/health
Use any of these test accounts:
Standard User:
- Email:
test@example.com - Password:
anything(any password works!)
Admin User:
- Email:
admin@example.com - Password:
anything
2FA User:
- Email:
2fa@example.com - Password:
anything - OTP Code:
999999
# Set mock mode
$env:MOCK_AUTH_MODE="true" # Windows PowerShell
# export MOCK_AUTH_MODE=true # Linux/Mac
# Run tests
pytest tests/test_mock_auth.py -vcurl -X POST http://localhost:8000/api/v1/auth/login \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "username=test@example.com&password=anything"{
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGc...",
"token_type": "bearer",
"refresh_token": "..."
}# Login with test user
POST /api/v1/auth/login
Body: username=test@example.com&password=anything
# Expected: 200 OK with tokens# Step 1: Login with 2FA user
POST /api/v1/auth/login
Body: username=2fa@example.com&password=anything
# Expected: 202 Accepted with pre_auth_token
# Step 2: Verify 2FA
POST /api/v1/auth/login/2fa
Body: {
"pre_auth_token": "<token_from_step_1>",
"code": "999999"
}
# Expected: 200 OK with tokens# Step 1: Initiate reset
POST /api/v1/auth/password-reset/initiate
Body: {"email": "test@example.com"}
# Check logs for OTP: 123456
# Step 2: Complete reset
POST /api/v1/auth/password-reset/complete
Body: {
"email": "test@example.com",
"otp_code": "123456",
"new_password": "new_pass"
}
# Expected: 200 OKEnable mock mode to develop frontend features without backend dependencies:
// useAuth.tsx will automatically detect mock mode
const { login, isMockMode } = useAuth();
// Login works the same way
await login('test@example.com', 'anything', true);import os
os.environ["MOCK_AUTH_MODE"] = "true"
from backend.fastapi.api.services.mock_auth_service import MockAuthService
def test_user_flow():
auth = MockAuthService()
user = auth.authenticate_user("test@example.com", "anything")
assert user is not None# .github/workflows/test.yml
env:
MOCK_AUTH_MODE: true
steps:
- name: Run tests
run: pytest tests/Solution 1: Check environment variable
# Windows PowerShell
echo $env:MOCK_AUTH_MODE
# Linux/Mac
echo $MOCK_AUTH_MODESolution 2: Verify in code
from backend.fastapi.api.config import get_settings
settings = get_settings()
print(f"Mock mode: {settings.mock_auth_mode}")Possible causes:
- Mock mode not enabled
- Using wrong test email (must be one of the predefined users)
- Backend not running
Solution:
# Check backend is running
curl http://localhost:8000/api/v1/health
# Verify mock users are available
# Should see test@example.com, admin@example.com, 2fa@example.comSolution: Use the correct OTP codes:
test@example.com:123456admin@example.com:6543212fa@example.com:999999- 2FA Setup:
888888
- Read Full Documentation: See
docs/MOCK_AUTH.mdfor complete details - Explore Test Users: Try all predefined users and flows
- Run Test Suite: Execute
pytest tests/test_mock_auth.py -v - Frontend Integration: Add
<MockModeBanner />to your app layout
- ✅ DO use mock mode for development and testing
- ✅ DO use any password (it's not validated)
- ✅ DO check logs for OTP codes (marked with 🎭)
- ❌ DON'T enable mock mode in production
- ❌ DON'T commit
.envwith mock mode enabled - ❌ DON'T rely on mock mode for security testing
If you encounter issues:
- Check the logs for 🎭 indicators
- Verify environment variables are set
- Review
docs/MOCK_AUTH.mdfor detailed documentation - Check
tests/test_mock_auth.pyfor working examples
Before reporting issues, verify:
-
MOCK_AUTH_MODE=trueis set in environment - Backend server is running
- Using one of the predefined test users
- Checked server logs for errors
- Tried restarting the backend server
Happy Testing! 🎭