test_zhangsan_menus.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/env python3
  2. import requests
  3. import json
  4. # Test zhangsan user menu access
  5. login_data = {
  6. 'username': 'zhangsan',
  7. 'password': 'zhangsan123' # Try common password
  8. }
  9. # Try different passwords for zhangsan
  10. passwords = ['zhangsan123', 'Zhangsan123', '123456', 'password', 'zhangsan']
  11. for password in passwords:
  12. try:
  13. login_data['password'] = password
  14. login_response = requests.post('http://localhost:8000/api/v1/auth/login', json=login_data)
  15. if login_response.status_code == 200:
  16. login_result = login_response.json()
  17. if login_result.get('code') == 0:
  18. token = login_result['data']['access_token']
  19. print(f'✅ Zhangsan login successful with password: {password}')
  20. # Get user menus
  21. headers = {'Authorization': f'Bearer {token}'}
  22. menus_response = requests.get('http://localhost:8000/api/v1/user/menus', headers=headers)
  23. if menus_response.status_code == 200:
  24. menus_result = menus_response.json()
  25. if menus_result.get('code') == 0:
  26. menus = menus_result['data']
  27. print(f'✅ Zhangsan has access to {len(menus)} menu items')
  28. # Check for admin-dashboard menu
  29. has_admin_dashboard = False
  30. for menu in menus:
  31. if menu.get('menu_type') == 'menu':
  32. print(f'📁 {menu["title"]} ({menu["name"]}) - Path: {menu.get("path", "N/A")}')
  33. if menu.get('children'):
  34. for child in menu['children']:
  35. if child.get('menu_type') == 'menu':
  36. print(f' 📄 {child["title"]} ({child["name"]}) - Path: {child.get("path", "N/A")}')
  37. if child.get('name') == 'admin-dashboard':
  38. has_admin_dashboard = True
  39. print(' ✅ Found 管理概览 (admin-dashboard) menu!')
  40. if has_admin_dashboard:
  41. print('\n🎉 Zhangsan can now see the 管理概览 menu!')
  42. else:
  43. print('\n❌ Zhangsan still cannot see the 管理概览 menu!')
  44. else:
  45. print(f'❌ Menus API error: {menus_result.get("message")}')
  46. else:
  47. print(f'❌ Menus API HTTP error: {menus_response.status_code}')
  48. break
  49. except Exception as e:
  50. continue
  51. else:
  52. print('❌ Could not find correct password for zhangsan user')