File size: 1,791 Bytes
d3cadd5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0edbd7b
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python3
"""测试反向代理是否正常工作"""

import requests
import json

PROXY_URL = "http://127.0.0.1:8000"

def test_health():
    """测试健康检查"""
    print("1. 测试健康检查...")
    r = requests.get(f"{PROXY_URL}/")
    print(f"   ✅ {r.json()}")

def test_chat():
    """测试聊天接口"""
    print("\n2. 测试聊天接口...")
    r = requests.post(
        f"{PROXY_URL}/v1/chat/completions",
        json={
            "model": "test",
            "messages": [{"role": "user", "content": "Hello"}]
        }
    )
    print(f"   ✅ {r.json()['choices'][0]['message']['content']}")

def test_catch_all():
    """测试通用捕获"""
    print("\n3. 测试任意路径捕获...")
    r = requests.post(
        f"{PROXY_URL}/api/v1/some/kiro/endpoint",
        json={"test": "data"}
    )
    print(f"   ✅ {r.json()['message']}")

def test_auth():
    """测试认证端点"""
    print("\n4. 测试认证端点...")
    r = requests.post(f"{PROXY_URL}/auth/login")
    print(f"   ✅ Token: {r.json()['token']}")

def view_logs():
    """查看日志"""
    print("\n5. 查看捕获的请求日志...")
    r = requests.get(f"{PROXY_URL}/logs")
    data = r.json()
    print(f"   ✅ 共捕获 {data['total']} 个请求")

if __name__ == "__main__":
    print("=" * 50)
    print("Kiro 反向代理测试")
    print("=" * 50)
    
    try:
        test_health()
        test_chat()
        test_catch_all()
        test_auth()
        view_logs()
        print("\n" + "=" * 50)
        print("✅ 所有测试通过!反向代理工作正常")
        print("=" * 50)
    except requests.exceptions.ConnectionError:
        print("\n❌ 连接失败!请先启动代理服务器:")
        print("   python scripts/proxy_server.py")