✨ Major Features Added: - Complete magical theming and rebranding from LifeRPG to The Wizard's Grimoire - Production-grade React frontend with Tailwind CSS v4 and magical aesthetics - Comprehensive analytics dashboard with Recharts integration (ScryingPortal) - Push notifications system with PWA service worker support - Drag & drop functionality using @dnd-kit for habit reordering - Social features with friends system and leaderboards - Performance optimization tools and monitoring - Mobile app enhancement with PWA installation support 🏗️ Technical Infrastructure: - Advanced service worker with offline support and background sync - Zustand state management for scalable application state - Production-ready UI component system with enhanced Button, Card, Input - Progressive Web App (PWA) with manifest and app installation - FastAPI backend with comprehensive API endpoints - Docker containerization and CI/CD pipeline setup 📱 Progressive Web App Features: - Offline functionality with intelligent caching - Push notification support for habit reminders - App installation on mobile and desktop platforms - Background sync for offline data management - Performance monitoring and optimization tools 🎨 User Experience: - Magical wizard/grimoire theming throughout application - Responsive design optimized for all device sizes - Drag & drop habit management with smooth animations - Interactive analytics with multiple chart types - Social connectivity with friends and competitive features - Comprehensive notification and performance settings 🔧 Developer Experience: - Modern development stack with Vite and React - Comprehensive testing setup and CI/CD pipelines - Code quality tools with pre-commit hooks - Docker development environment - Detailed documentation and implementation guides This represents a complete transformation from prototype to production-ready application with enterprise-grade features and magical user experience.
67 lines
2.4 KiB
Python
67 lines
2.4 KiB
Python
import importlib
|
|
|
|
def test_totp_setup_enable_and_login_with_totp(client):
|
|
# Sign up a user with password
|
|
r = client.post('/api/v1/auth/signup', json={'email': '2fa@example.com', 'password': 'pw'} )
|
|
assert r.status_code == 200
|
|
|
|
# Begin setup
|
|
r = client.post('/api/v1/auth/2fa/setup')
|
|
assert r.status_code == 200
|
|
data = r.json()
|
|
assert 'otpauth_uri' in data and 'recovery_codes' in data
|
|
assert len(data['recovery_codes']) >= 8
|
|
|
|
# Extract current TOTP from secret by reading from DB
|
|
import modern.backend.models as models
|
|
db = models.SessionLocal()
|
|
u = db.query(models.User).filter_by(email='2fa@example.com').first()
|
|
assert u and u.totp_secret
|
|
|
|
# compute a valid code
|
|
import pyotp
|
|
code = pyotp.TOTP(u.totp_secret).now()
|
|
|
|
# Enable 2FA
|
|
r2 = client.post('/api/v1/auth/2fa/enable', json={'code': code})
|
|
assert r2.status_code == 200
|
|
|
|
# Logout to clear session
|
|
client.post('/api/v1/auth/logout')
|
|
|
|
# Login must now include totp_code
|
|
r3 = client.post('/api/v1/auth/login', json={'email': '2fa@example.com', 'password': 'pw'})
|
|
assert r3.status_code == 401
|
|
r4 = client.post('/api/v1/auth/login', json={'email': '2fa@example.com', 'password': 'pw', 'totp_code': code})
|
|
assert r4.status_code == 200
|
|
|
|
|
|
def test_login_with_recovery_code(client):
|
|
# new user
|
|
r = client.post('/api/v1/auth/signup', json={'email': '2fa2@example.com', 'password': 'pw'} )
|
|
assert r.status_code == 200
|
|
|
|
# setup 2fa to generate recovery codes
|
|
r = client.post('/api/v1/auth/2fa/setup')
|
|
codes = r.json()['recovery_codes']
|
|
|
|
# enable 2fa
|
|
import modern.backend.models as models
|
|
db = models.SessionLocal()
|
|
u = db.query(models.User).filter_by(email='2fa2@example.com').first()
|
|
import pyotp
|
|
code = pyotp.TOTP(u.totp_secret).now()
|
|
client.post('/api/v1/auth/2fa/enable', json={'code': code})
|
|
|
|
# logout
|
|
client.post('/api/v1/auth/logout')
|
|
|
|
# login using one recovery code
|
|
r2 = client.post('/api/v1/auth/login', json={'email': '2fa2@example.com', 'password': 'pw', 'recovery_code': codes[0]})
|
|
assert r2.status_code == 200
|
|
|
|
# recovery code should be consumed; using again should fail
|
|
client.post('/api/v1/auth/logout')
|
|
r3 = client.post('/api/v1/auth/login', json={'email': '2fa2@example.com', 'password': 'pw', 'recovery_code': codes[0]})
|
|
assert r3.status_code == 401
|