116 lines
4.3 KiB
Python
116 lines
4.3 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test script to verify the login bug fix configuration.
|
|
This script tests the configuration changes without requiring a running API server.
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
def test_configuration():
|
|
"""Test that the configuration changes are correctly applied."""
|
|
|
|
print("🔍 Testing Login Bug Fix Configuration...")
|
|
print("=" * 50)
|
|
|
|
# Test 1: Check environment files
|
|
print("\n1. Testing Environment Files:")
|
|
|
|
env_files = ["./.env", "./api/.env"]
|
|
for env_file in env_files:
|
|
if os.path.exists(env_file):
|
|
with open(env_file, 'r') as f:
|
|
content = f.read()
|
|
|
|
# Check domain
|
|
if "DOMAIN=rehearshalhub.sschuhmann.de" in content:
|
|
print(f" ✅ {env_file}: DOMAIN correctly set to rehearshalhub.sschuhmann.de")
|
|
else:
|
|
print(f" ❌ {env_file}: DOMAIN not correctly configured")
|
|
|
|
# Check CORS origins
|
|
if "CORS_ORIGINS=" in content:
|
|
print(f" ✅ {env_file}: CORS_ORIGINS configured")
|
|
else:
|
|
print(f" ❌ {env_file}: CORS_ORIGINS missing")
|
|
else:
|
|
print(f" ⚠️ {env_file}: File not found")
|
|
|
|
# Test 2: Check Python source files
|
|
print("\n2. Testing Python Source Files:")
|
|
|
|
source_files = [
|
|
("./api/src/rehearsalhub/config.py", ["cors_origins: str = \"\""], "cors_origins configuration"),
|
|
("./api/src/rehearsalhub/main.py", ["allowed_origins = [", "settings.cors_origins"], "CORS middleware updates"),
|
|
("./api/src/rehearsalhub/routers/auth.py", ["cookie_domain = None", "samesite_value = \"none\""], "cookie configuration updates")
|
|
]
|
|
|
|
for file_path, required_strings, description in source_files:
|
|
if os.path.exists(file_path):
|
|
with open(file_path, 'r') as f:
|
|
content = f.read()
|
|
|
|
all_found = True
|
|
for required_string in required_strings:
|
|
if required_string not in content:
|
|
all_found = False
|
|
print(f" ❌ {file_path}: Missing '{required_string}'")
|
|
break
|
|
|
|
if all_found:
|
|
print(f" ✅ {file_path}: {description} correctly applied")
|
|
else:
|
|
print(f" ⚠️ {file_path}: File not found")
|
|
|
|
# Test 3: Verify cookie domain logic
|
|
print("\n3. Testing Cookie Domain Logic:")
|
|
|
|
# Simulate the cookie domain logic
|
|
test_domains = [
|
|
("localhost", None),
|
|
("rehearshalhub.sschuhmann.de", ".sschuhmann.de"),
|
|
("app.example.com", ".example.com"),
|
|
("sub.domain.co.uk", ".co.uk")
|
|
]
|
|
|
|
for domain, expected in test_domains:
|
|
cookie_domain = None
|
|
if domain != "localhost":
|
|
if "." in domain:
|
|
parts = domain.split(".")
|
|
cookie_domain = "." + parts[-2] + "." + parts[-1]
|
|
|
|
if cookie_domain == expected:
|
|
print(f" ✅ Domain '{domain}' → '{cookie_domain}' (correct)")
|
|
else:
|
|
print(f" ❌ Domain '{domain}' → '{cookie_domain}' (expected '{expected}')")
|
|
|
|
# Test 4: Verify SameSite policy logic
|
|
print("\n4. Testing SameSite Policy Logic:")
|
|
|
|
test_scenarios = [
|
|
("localhost", False, "lax"),
|
|
("rehearshalhub.sschuhmann.de", False, "none"),
|
|
("example.com", True, "none")
|
|
]
|
|
|
|
for domain, debug, expected_samesite in test_scenarios:
|
|
samesite_value = "none" if domain != "localhost" else "lax"
|
|
secure_flag = True if domain != "localhost" else not debug
|
|
|
|
if samesite_value == expected_samesite:
|
|
print(f" ✅ {domain} (debug={debug}) → samesite='{samesite_value}', secure={secure_flag}")
|
|
else:
|
|
print(f" ❌ {domain} (debug={debug}) → samesite='{samesite_value}' (expected '{expected_samesite}')")
|
|
|
|
print("\n" + "=" * 50)
|
|
print("🎉 Configuration Test Complete!")
|
|
print("\nNext Steps:")
|
|
print("1. Start the API server: cd api && python -m rehearsalhub.main")
|
|
print("2. Test login from different hosts")
|
|
print("3. Verify CORS headers in browser developer tools")
|
|
print("4. Check cookie settings in browser storage")
|
|
|
|
if __name__ == "__main__":
|
|
test_configuration() |