-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquick_test.py
More file actions
94 lines (81 loc) · 2.49 KB
/
Copy pathquick_test.py
File metadata and controls
94 lines (81 loc) · 2.49 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
WAF API 快速测试脚本
"""
import subprocess
import time
import requests
import sys
from config import API_CONFIG
def start_server():
"""启动服务器"""
print("启动WAF API服务器...")
try:
# 启动服务器进程
process = subprocess.Popen([sys.executable, "start_server.py"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
# 等待服务器启动
print("等待服务器启动...")
time.sleep(3)
return process
except Exception as e:
print(f"启动服务器失败: {e}")
return None
def test_server():
"""测试服务器"""
base_url = f"http://localhost:{API_CONFIG['port']}"
try:
# 测试基本连接
response = requests.get(f"{base_url}/", timeout=5)
if response.status_code == 200:
print("✓ 服务器启动成功")
return True
else:
print(f"✗ 服务器响应异常: {response.status_code}")
return False
except Exception as e:
print(f"✗ 无法连接到服务器: {e}")
return False
def main():
"""主函数"""
print("=" * 50)
print("WAF API 快速测试")
print("=" * 50)
# 启动服务器
process = start_server()
if not process:
return False
try:
# 测试服务器
if test_server():
print("✓ 系统测试通过")
print("\n系统已准备就绪!")
print(f"管理界面: http://localhost:{API_CONFIG['port']}/admin")
print("默认管理员: admin / waf123456")
print("\n按 Ctrl+C 停止服务器")
# 保持服务器运行
try:
process.wait()
except KeyboardInterrupt:
print("\n正在停止服务器...")
process.terminate()
process.wait()
print("服务器已停止")
else:
print("✗ 系统测试失败")
process.terminate()
return False
except KeyboardInterrupt:
print("\n正在停止服务器...")
process.terminate()
process.wait()
print("服务器已停止")
except Exception as e:
print(f"测试过程中出错: {e}")
process.terminate()
return False
return True
if __name__ == "__main__":
main()