fix: 导入 DramaBox 凭据后先核对个人信息

This commit is contained in:
Nixevol
2026-10-29 21:20:28 +08:00
parent f6274c6ff6
commit 43e06b7d0f
7 changed files with 110 additions and 47 deletions
+22
View File
@@ -1,3 +1,4 @@
from server.services.dramabox.app_api import account_from_bootstrap
from server.services.dramabox.login import _credential_record
@@ -35,6 +36,27 @@ def test_credential_file_is_one_json_document() -> None:
raise AssertionError("不完整的凭据文件应被拒绝")
def test_account_profile_must_match_the_credential() -> None:
app = {"user_id": "88", "token": "Bearer old"}
fresh = account_from_bootstrap(app, {"user": {"uid": "88", "token": "new", "nickname": "阿花", "isVip": 1}})
assert fresh["token"] == "Bearer new"
assert fresh["name"] == "阿花"
assert fresh["vip"] is True
try:
account_from_bootstrap(app, {"user": {"uid": "99", "token": "new", "nickname": "别人"}})
except RuntimeError as exc:
assert "失效" in str(exc)
else:
raise AssertionError("用户编号不一致应视为未登录")
try:
account_from_bootstrap(app, {})
except RuntimeError as exc:
assert "失效" in str(exc)
else:
raise AssertionError("没有个人信息应视为未登录")
if __name__ == "__main__":
test_credential_file_is_one_json_document()
test_account_profile_must_match_the_credential()
print("ok")