41 lines
1.2 KiB
Python
41 lines
1.2 KiB
Python
from server.services.dramabox.login import _credential_record
|
|
|
|
|
|
def test_credential_file_is_one_json_document() -> None:
|
|
document = {
|
|
"kind": "dramabox-login",
|
|
"version": 1,
|
|
"app": {
|
|
"token": "raw-token",
|
|
"device_id": "ad-1",
|
|
"android_id": "android-1",
|
|
"user_id": "88",
|
|
"vip": "y",
|
|
"name": "示例",
|
|
},
|
|
}
|
|
record = _credential_record(document)
|
|
assert record["token"] == "Bearer raw-token"
|
|
assert record["device_id"] == "ad-1"
|
|
assert record["android_id"] == "android-1"
|
|
assert record["user_id"] == "88"
|
|
assert record["vip"] is True
|
|
assert record["name"] == "示例"
|
|
|
|
for broken in (
|
|
{},
|
|
{"kind": "other", "version": 1, "app": document["app"]},
|
|
{"kind": "dramabox-login", "version": 2, "app": document["app"]},
|
|
{"kind": "dramabox-login", "version": 1, "app": {"token": "Bearer x"}},
|
|
):
|
|
try:
|
|
_credential_record(broken)
|
|
except RuntimeError:
|
|
continue
|
|
raise AssertionError("不完整的凭据文件应被拒绝")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
test_credential_file_is_one_json_document()
|
|
print("ok")
|