| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- #!/usr/bin/env python3
- import requests
- import json
- # Test app user applications access
- login_data = {
- 'username': 'app',
- 'password': '123456'
- }
- try:
- # Login as app 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('✅ App user login successful')
-
- # Get applications list
- headers = {'Authorization': f'Bearer {token}'}
- apps_response = requests.get('http://localhost:8000/api/v1/apps', headers=headers)
-
- if apps_response.status_code == 200:
- apps_result = apps_response.json()
- if apps_result.get('code') == 0:
- apps_data = apps_result['data']
- apps = apps_data.get('items', [])
- total = apps_data.get('total', 0)
-
- print(f'✅ App user can access applications API')
- print(f'📱 Found {len(apps)} applications (total: {total})')
-
- if apps:
- for app in apps:
- print(f' App: {app["name"]} (Key: {app["app_key"]})')
- print(f' Description: {app.get("description", "N/A")}')
- print(f' Active: {app["is_active"]}')
- print(f' Created: {app["created_at"]}')
- print()
-
- print('🎉 App user can now see all applications!')
- else:
- print('❌ No applications returned - still empty!')
-
- else:
- print(f'❌ Applications API error: {apps_result.get("message")}')
- else:
- print(f'❌ Applications API HTTP error: {apps_response.status_code}')
- print(f'Response: {apps_response.text}')
- 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}')
- # Also test with admin user for comparison
- print('\n' + '='*50)
- print('Testing admin user for comparison...')
- admin_login_data = {
- 'username': 'admin',
- 'password': 'Admin123456'
- }
- try:
- # Login as admin user
- login_response = requests.post('http://localhost:8000/api/v1/auth/login', json=admin_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 applications list
- headers = {'Authorization': f'Bearer {token}'}
- apps_response = requests.get('http://localhost:8000/api/v1/apps', headers=headers)
-
- if apps_response.status_code == 200:
- apps_result = apps_response.json()
- if apps_result.get('code') == 0:
- apps_data = apps_result['data']
- apps = apps_data.get('items', [])
- total = apps_data.get('total', 0)
-
- print(f'✅ Admin user can access applications API')
- print(f'📱 Admin sees {len(apps)} applications (total: {total})')
-
- else:
- print(f'❌ Applications API error: {apps_result.get("message")}')
- else:
- print(f'❌ Applications API HTTP error: {apps_response.status_code}')
- else:
- print(f'❌ Admin login error: {login_result.get("message")}')
- else:
- print(f'❌ Admin login HTTP error: {login_response.status_code}')
-
- except Exception as e:
- print(f'❌ Admin request error: {e}')
|