This repository was archived by the owner on Aug 1, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
135 lines (111 loc) · 4.59 KB
/
Copy pathtest.py
File metadata and controls
135 lines (111 loc) · 4.59 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import bit_login
import os
import time
import requests
def get_registration_jwt(
server_url,
username,
password,
audience,
*,
poll_interval=1.0,
timeout=300,
):
"""通过 server challenge 登录,并换取注册 JWT。"""
server_url = server_url.rstrip("/")
session = requests.Session()
response = session.post(
f"{server_url}/api/auth/start",
json={
"username": username,
"password": password,
"services": ["webvpn"],
"wait_seconds": 1,
},
timeout=30,
)
response.raise_for_status()
challenge = response.json()
challenge_id = challenge["challenge_id"]
access_token = challenge["access_token"]
headers = {"X-Challenge-Token": access_token}
deadline = time.monotonic() + timeout
while time.monotonic() < deadline:
status = challenge["status"]
if status == "authenticated":
response = session.post(
f"{server_url}/api/auth/{challenge_id}/registration-token",
headers=headers,
json={"audience": audience},
timeout=30,
)
response.raise_for_status()
return response.json()["registration_token"]
if status == "waiting_sms":
masked_phone = challenge.get("masked_phone", "绑定手机")
sms_code = input(f"请输入发送到 {masked_phone} 的短信验证码: ").strip()
response = session.post(
f"{server_url}/api/auth/{challenge_id}/sms",
headers=headers,
json={"code": sms_code},
timeout=30,
)
response.raise_for_status()
challenge = response.json()
continue
if status in {"failed", "expired", "cancelled"}:
error = challenge.get("error", status)
raise RuntimeError(f"server authentication failed: {error}")
time.sleep(poll_interval)
response = session.get(
f"{server_url}/api/auth/{challenge_id}",
headers=headers,
timeout=30,
)
response.raise_for_status()
challenge = response.json()
raise TimeoutError("server authentication timed out")
username = ""
password = ""
if not username and not password:
username = os.getenv("BITUSERNAME")
password = os.getenv("BITPASSWORD")
print("========== 开始测试Server ==========")
print(get_registration_jwt(
server_url="http://localhost:16384",
username=username,
password=password,
audience="bit101-main",
))
print("========== 开始测试登录模块 ==========")
print("Testing: WEBVPN")
assert bit_login.webvpn_login().login(username=username, password=password).get_session().get("https://webvpn.bit.edu.cn/connection/log?page=1&limit=10").json()["Message"] == "获取成功"
print("✅ PASS: WEBVPN\n")
print("Testing: JWB (教务系统)")
c=0
for i in bit_login.jwb.score(bit_login.jwb_login().login(username=username, password=password).get_session()).get_all_score():
if i["credit"]: c+=float(i["credit"])
print(f"总学分:{c}")
print("✅ PASS: JWB\n")
print("Testing: JWB_CJD (教务系统-成绩单)")
print(bit_login.jwb.cjd(bit_login.jwb_cjd_login().login(username=username,password=password).get_session()).get_cjd())
print("✅ PASS: JWB\n")
print("Testing: JXZXEHALL (教学中心/一站式大厅)")
assert bit_login.jxzxehall.credit(bit_login.jxzxehall_login().login(username=username, password=password).get_session()).get_credit()["total_credit"] > 0
print("✅ PASS: JXZXEHALL\n")
print("Testing: IBIT (iBIT 手机端聚合页)")
assert '{"code":0,"message":"","data":' in bit_login.ibit_login().login(username=username, password=password).get_session().get("https://ibit.yanhekt.cn/proxy/v1/user?with_desensitize=false").text
print("✅ PASS: IBIT\n")
print("Testing: YANHEKT (延河课堂)")
assert '{"code":0,"message":"","data":{"' in bit_login.yanhekt_login().login(username=username, password=password).get_session().get('https://cbiz.yanhekt.cn/v1/user').text
print("✅ PASS: YANHEKT\n")
print("Testing: LIBRARY (图书馆)")
assert bit_login.library_login().login(username=username, password=password).get_result()["cookie_json"] is not None
print("✅ PASS: LIBRARY\n")
# print("Testing: DEKT (第二课堂)")
# assert "cookie_json" in bit_login.dekt_login().login(username=username, password=password).get_result()
# print("✅ PASS: DEKT\n")
# print("Testing: CXCY")
# bit_login.cxcy_login().login(username=username, password=password).get_result()
# print("✅ PASS: CXCY\n")
print("========== 全部测试通过 ==========")