Smail/test/tools/test_edit_user_pwd.py
smail 9c450f1734
Some checks are pending
Security Checks / security (push) Waiting to run
运行时配置清理阶段检查点
2026-10-05 01:31:34 +08:00

41 lines
1.3 KiB
Python

import urllib.request, ssl, json, http.cookiejar
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
cj = http.cookiejar.CookieJar()
opener = urllib.request.build_opener(urllib.request.HTTPSHandler(context=ctx), urllib.request.HTTPCookieProcessor(cj))
# 登录 xuans
login_payload = json.dumps({"account": "xuans", "password": "12345678"}).encode("utf-8")
req = urllib.request.Request("https://47.108.78.12/api/v1/login", data=login_payload, headers={
"Content-Type": "application/json",
"Host": "mail.example.com",
"Origin": "https://mail.example.com"
})
opener.open(req, timeout=5)
csrf_token = ""
for c in cj:
if c.name == "smail_csrf":
csrf_token = c.value
headers = {
"Content-Type": "application/json",
"Host": "mail.example.com",
"Origin": "https://mail.example.com",
"Referer": "https://mail.example.com/",
"X-CSRF-Token": csrf_token
}
edit_payload = json.dumps({
"id": 2,
"account": "testuser2",
"username": "普通用户",
"password": "Password123!",
"disabled": 0,
"role": "user"
}).encode("utf-8")
req_edit = urllib.request.Request("https://47.108.78.12/api/v1/user/edit", data=edit_payload, headers=headers)
resp_edit = opener.open(req_edit, timeout=5)
print("Edit user response:", resp_edit.read().decode())