-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_auth.py
More file actions
85 lines (68 loc) · 2.72 KB
/
Copy pathdebug_auth.py
File metadata and controls
85 lines (68 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python3
"""
Debug authentication system
"""
import sys
import os
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
from app.core.database import get_db_session
from app.core.auth import user_manager
from app.core.tenant import tenant_registry
from app.models import User
from sqlalchemy.orm import Session
def debug_auth():
"""Debug authentication system"""
tenant_id = "ui_test_tenant"
print(f"🔍 Debugging authentication for tenant: {tenant_id}")
try:
# Check if tenant exists
print(f"\n1. Checking tenant registration...")
tenant = tenant_registry.get_tenant(tenant_id)
if tenant:
print(f"✅ Tenant exists: {tenant}")
else:
print(f"❌ Tenant not found in registry")
return
# Check database connection
print(f"\n2. Checking database connection...")
db = next(get_db_session(tenant_id))
print(f"✅ Database connection successful")
# Check if users table exists and has data
print(f"\n3. Checking users in database...")
users = db.query(User).all()
print(f"Found {len(users)} users in database:")
for user in users:
print(f" - ID: {user.id}, Username: {user.username}, Email: {user.email}, Active: {user.is_active}")
# Try to authenticate
print(f"\n4. Testing authentication...")
auth_user = user_manager.authenticate_tenant_user(tenant_id, "admin", "admin123")
if auth_user:
print(f"✅ Authentication successful: {auth_user}")
else:
print(f"❌ Authentication failed")
# Try to create user again
print(f"\n5. Attempting to create user again...")
user_data = {
"username": "admin",
"email": "admin@test.com",
"password": "admin123",
"roles": ["admin", "products:read", "products:write", "categories:read", "categories:write"],
}
try:
user = user_manager.create_tenant_user(tenant_id, user_data)
print(f"✅ User created: {user}")
# Test authentication again
auth_user = user_manager.authenticate_tenant_user(tenant_id, "admin", "admin123")
if auth_user:
print(f"✅ Authentication now successful: {auth_user}")
else:
print(f"❌ Authentication still failing")
except Exception as e:
print(f"❌ Error creating user: {e}")
db.close()
except Exception as e:
print(f"❌ Error during debug: {e}")
import traceback
traceback.print_exc()
if __name__ == "__main__":
debug_auth()