135 lines
4.1 KiB
Python
135 lines
4.1 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
快速登录测试
|
|
尝试不同的登录方式
|
|
"""
|
|
|
|
import requests
|
|
import json
|
|
|
|
def test_login_methods():
|
|
"""测试不同的登录方式"""
|
|
base_url = "http://localhost:8080"
|
|
|
|
# 方式1: 标准登录(无加密)
|
|
print("🔓 测试方式1:标准登录(无加密)")
|
|
try:
|
|
login_data = {
|
|
"tenantId": "000000",
|
|
"username": "admin",
|
|
"password": "admin123",
|
|
"clientId": "e5cd7e4891bf95d1d19206ce24a7b32e",
|
|
"grantType": "password"
|
|
}
|
|
|
|
headers = {
|
|
'Content-Type': 'application/json;charset=utf-8',
|
|
'clientid': 'e5cd7e4891bf95d1d19206ce24a7b32e',
|
|
'referer': 'http://localhost/login?redirect=%252Findex',
|
|
}
|
|
|
|
response = requests.post(f"{base_url}/auth/login", json=login_data, headers=headers)
|
|
print(f" 状态码: {response.status_code}")
|
|
print(f" 响应: {response.text[:200]}...")
|
|
|
|
if response.status_code == 200:
|
|
result = response.json()
|
|
if result.get('code') == 200:
|
|
print(" ✅ 登录成功!")
|
|
token = result.get('data', {}).get('access_token')
|
|
if token:
|
|
print(f" 🎫 Token: {token[:50]}...")
|
|
return token
|
|
|
|
except Exception as e:
|
|
print(f" ❌ 异常: {str(e)}")
|
|
|
|
# 方式2: 尝试不同的clientid
|
|
print("\n🔓 测试方式2:默认clientid")
|
|
try:
|
|
login_data = {
|
|
"username": "admin",
|
|
"password": "admin123"
|
|
}
|
|
|
|
headers = {
|
|
'Content-Type': 'application/json',
|
|
}
|
|
|
|
response = requests.post(f"{base_url}/auth/login", json=login_data, headers=headers)
|
|
print(f" 状态码: {response.status_code}")
|
|
print(f" 响应: {response.text[:200]}...")
|
|
|
|
except Exception as e:
|
|
print(f" ❌ 异常: {str(e)}")
|
|
|
|
# 方式3: 尝试表单提交
|
|
print("\n🔓 测试方式3:表单提交")
|
|
try:
|
|
login_data = {
|
|
"username": "admin",
|
|
"password": "admin123",
|
|
"tenantId": "000000"
|
|
}
|
|
|
|
headers = {
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
}
|
|
|
|
response = requests.post(f"{base_url}/auth/login", data=login_data, headers=headers)
|
|
print(f" 状态码: {response.status_code}")
|
|
print(f" 响应: {response.text[:200]}...")
|
|
|
|
except Exception as e:
|
|
print(f" ❌ 异常: {str(e)}")
|
|
|
|
# 方式4: 尝试获取公钥再登录
|
|
print("\n🔓 测试方式4:获取公钥")
|
|
try:
|
|
response = requests.get(f"{base_url}/auth/publicKey")
|
|
print(f" 获取公钥状态码: {response.status_code}")
|
|
print(f" 公钥响应: {response.text[:200]}...")
|
|
|
|
except Exception as e:
|
|
print(f" ❌ 异常: {str(e)}")
|
|
|
|
# 方式5: 检查验证码
|
|
print("\n🔓 测试方式5:检查验证码要求")
|
|
try:
|
|
response = requests.get(f"{base_url}/auth/captcha")
|
|
print(f" 验证码状态码: {response.status_code}")
|
|
print(f" 验证码响应: {response.text[:200]}...")
|
|
|
|
except Exception as e:
|
|
print(f" ❌ 异常: {str(e)}")
|
|
|
|
def test_without_auth():
|
|
"""测试不需要认证的接口"""
|
|
print("\n📊 测试无需认证的接口")
|
|
base_url = "http://localhost:8080"
|
|
|
|
endpoints = [
|
|
"/",
|
|
"/health",
|
|
"/actuator/health",
|
|
"/swagger-ui.html",
|
|
"/doc.html"
|
|
]
|
|
|
|
for endpoint in endpoints:
|
|
try:
|
|
response = requests.get(f"{base_url}{endpoint}")
|
|
print(f" {endpoint}: {response.status_code}")
|
|
if response.status_code == 200:
|
|
print(f" 内容类型: {response.headers.get('content-type', 'unknown')}")
|
|
except Exception as e:
|
|
print(f" {endpoint}: 异常 - {str(e)}")
|
|
|
|
if __name__ == "__main__":
|
|
print("🔍 快速登录测试")
|
|
print("="*50)
|
|
|
|
test_login_methods()
|
|
test_without_auth()
|