#!/usr/bin/env python3 import requests import json # Test admin user profile to see roles login_data = { 'username': 'admin', 'password': 'Admin123456' } try: # Login as admin user login_response = requests.post('http://localhost:8000/api/v1/auth/login', json=login_data) if login_response.status_code == 200: login_result = login_response.json() if login_result.get('code') == 0: token = login_result['data']['access_token'] print('✅ Admin user login successful') # Get user profile headers = {'Authorization': f'Bearer {token}'} profile_response = requests.get('http://localhost:8000/api/v1/users/profile', headers=headers) if profile_response.status_code == 200: profile_result = profile_response.json() if profile_result.get('code') == 0: profile = profile_result['data'] print('✅ Admin user profile:') print(f' Username: {profile.get("username")}') print(f' Email: {profile.get("email")}') print(f' Is Superuser: {profile.get("is_superuser")}') print(f' Is Active: {profile.get("is_active")}') print(f' Roles: {profile.get("roles", [])}') else: print(f'❌ Profile API error: {profile_result.get("message")}') else: print(f'❌ Profile API HTTP error: {profile_response.status_code}') else: print(f'❌ Login error: {login_result.get("message")}') else: print(f'❌ Login HTTP error: {login_response.status_code}') except Exception as e: print(f'❌ Request error: {e}') # Now test with app user (need to find correct password first) print('\n' + '='*50) print('Testing app user...') # Try common passwords for app user app_passwords = ['App123456', 'app123456', 'password', '123456', 'admin'] for password in app_passwords: try: login_data = {'username': 'app', 'password': password} login_response = requests.post('http://localhost:8000/api/v1/auth/login', json=login_data) if login_response.status_code == 200: login_result = login_response.json() if login_result.get('code') == 0: token = login_result['data']['access_token'] print(f'✅ App user login successful with password: {password}') # Get user profile headers = {'Authorization': f'Bearer {token}'} profile_response = requests.get('http://localhost:8000/api/v1/users/profile', headers=headers) if profile_response.status_code == 200: profile_result = profile_response.json() if profile_result.get('code') == 0: profile = profile_result['data'] print('✅ App user profile:') print(f' Username: {profile.get("username")}') print(f' Email: {profile.get("email")}') print(f' Is Superuser: {profile.get("is_superuser")}') print(f' Is Active: {profile.get("is_active")}') print(f' Roles: {profile.get("roles", [])}') break else: print(f'❌ Profile API error: {profile_result.get("message")}') else: print(f'❌ Profile API HTTP error: {profile_response.status_code}') break except Exception as e: continue else: print('❌ Could not find correct password for app user')