接入匿名设备态协议补齐Cookie字段并放宽保存
This commit is contained in:
@@ -147,6 +147,46 @@ def test_app_login_cookie_contains_web_session_shape():
|
||||
assert expected <= keys
|
||||
|
||||
|
||||
def test_supplement_anonymous_device_adds_four_fields(monkeypatch):
|
||||
anon = {
|
||||
"udb_deviceid": "w_1147246591246680065",
|
||||
"udb_guiddata": "a" * 32,
|
||||
"udb_anobiztoken": "B" * 344,
|
||||
"udb_anouid": "1471255709907",
|
||||
}
|
||||
monkeypatch.setattr(
|
||||
"core.huya.anon_device.fetch_anonymous_device_state", lambda **kw: anon
|
||||
)
|
||||
merged = HuyaAppPasswordLogin._supplement_anonymous_device({"guid": "g" * 32})
|
||||
assert merged["udb_deviceid"] == anon["udb_deviceid"]
|
||||
assert merged["udb_guiddata"] == anon["udb_guiddata"]
|
||||
assert merged["udb_anobiztoken"] == anon["udb_anobiztoken"]
|
||||
assert merged["udb_anouid"] == anon["udb_anouid"]
|
||||
assert merged["guid"] == "g" * 32 # 已有显式值不被覆盖
|
||||
|
||||
|
||||
def test_supplement_anonymous_device_keeps_explicit_values(monkeypatch):
|
||||
anon = {"udb_deviceid": "w_9999999999999999999", "udb_anobiztoken": "B" * 344}
|
||||
monkeypatch.setattr(
|
||||
"core.huya.anon_device.fetch_anonymous_device_state", lambda **kw: anon
|
||||
)
|
||||
merged = HuyaAppPasswordLogin._supplement_anonymous_device(
|
||||
{"udb_deviceid": "w_1111111111111111111"}
|
||||
)
|
||||
assert merged["udb_deviceid"] == "w_1111111111111111111" # setdefault 语义
|
||||
|
||||
|
||||
def test_supplement_anonymous_device_failure_does_not_raise(monkeypatch):
|
||||
def boom(**kw):
|
||||
from core.huya.anon_device import AnonymousDeviceError
|
||||
|
||||
raise AnonymousDeviceError("network down")
|
||||
|
||||
monkeypatch.setattr("core.huya.anon_device.fetch_anonymous_device_state", boom)
|
||||
merged = HuyaAppPasswordLogin._supplement_anonymous_device({"guid": "g"})
|
||||
assert merged == {"guid": "g"}
|
||||
|
||||
|
||||
class TestHuyaAppLogin:
|
||||
def setup_method(self):
|
||||
self.engine = create_engine("sqlite://")
|
||||
|
||||
@@ -10,8 +10,7 @@ def test_minimal_app_cookie_reports_only_missing_web_guid():
|
||||
)
|
||||
|
||||
assert HuyaBatchRunnerCore._web_wss_cookie_missing(cookie) == (
|
||||
"guid", "udb_guiddata", "udb_deviceid", "game_did",
|
||||
"_qimei_uuid42", "udb_anobiztoken", "__yamid_new",
|
||||
"udb_deviceid", "udb_guiddata", "udb_anobiztoken",
|
||||
)
|
||||
assert not HuyaBatchRunnerCore._has_web_wss_cookie(cookie)
|
||||
|
||||
@@ -26,3 +25,16 @@ def test_complete_web_cookie_enables_wss_without_logging_values():
|
||||
|
||||
assert HuyaBatchRunnerCore._web_wss_cookie_missing(cookie) == ()
|
||||
assert HuyaBatchRunnerCore._has_web_wss_cookie(cookie)
|
||||
|
||||
|
||||
def test_script_only_fields_do_not_block_wss():
|
||||
"""guid/_qimei_uuid42/__yamid_new/game_did 无服务端签发时不再阻断 WSS。"""
|
||||
cookie = (
|
||||
"udb_cred=cred; udb_biztoken=biz; udb_uid=1199659425268; "
|
||||
"yyuid=1199659425268; sdid=sdid; "
|
||||
"udb_deviceid=w_1234567890123456789; udb_guiddata=guiddata; "
|
||||
"udb_anobiztoken=anobiz"
|
||||
)
|
||||
|
||||
assert HuyaBatchRunnerCore._web_wss_cookie_missing(cookie) == ()
|
||||
assert HuyaBatchRunnerCore._has_web_wss_cookie(cookie)
|
||||
Reference in New Issue
Block a user