-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_auth.py
More file actions
32 lines (27 loc) · 949 Bytes
/
test_auth.py
File metadata and controls
32 lines (27 loc) · 949 Bytes
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
#!/usr/bin/env python3
"""
简单的认证测试脚本
"""
import asyncio
import httpx
async def test_auth():
"""测试认证"""
base_url = "http://localhost:8000"
api_key = "pdf2others-convert-2024-demo"
headers = {"X-API-Key": api_key}
# 测试不同的认证方式
test_cases = [
("X-API-Key header", {"X-API-Key": api_key}),
("Authorization Bearer", {"Authorization": f"Bearer {api_key}"}),
]
async with httpx.AsyncClient() as client:
for method, test_headers in test_cases:
print(f"\n测试认证方式: {method}")
try:
response = await client.get(f"{base_url}/auth/me", headers=test_headers)
print(f"状态码: {response.status_code}")
print(f"响应: {response.text}")
except Exception as e:
print(f"错误: {e}")
if __name__ == "__main__":
asyncio.run(test_auth())