修复虎牙手机号登录并统一部署项目名
This commit is contained in:
@@ -17,13 +17,14 @@ from core.huya.app_login import (
|
||||
wup_password_login_raw,
|
||||
)
|
||||
from core.huya.cert_forge import build_p1, decrypt_cert, forge_cert, parse_p1
|
||||
from core.huya.device_fingerprint import account_state_dir, reset_account_state
|
||||
from core.huya.device_profile import generate_profile, get_profile
|
||||
from core.huya.dfp_register import DfpRegistrationError
|
||||
from core.huya.envelope_forge import Envelope
|
||||
from core.huya.login import HuyaLoginResult
|
||||
from core.huya.nonce_forge import K1_DEFAULT, gen_nonce
|
||||
from core.huya.udb_aes import udb_decrypt, udb_encrypt
|
||||
from core.huya.wup_encoder import build_password_login_wup
|
||||
from core.huya.wup_encoder import _make_name, build_password_login_wup
|
||||
from web.backend.database import Base
|
||||
from web.backend.models import HuyaAccount, User
|
||||
from web.backend.routers.huya import (
|
||||
@@ -104,6 +105,18 @@ class TestHuyaAppLogin:
|
||||
p3 = get_profile("test_user_account_123")
|
||||
assert p2["fingerprint"] == p3["fingerprint"]
|
||||
|
||||
def test_force_new_device_clears_hydevice_state(self, tmp_path, monkeypatch):
|
||||
monkeypatch.setattr(
|
||||
"core.huya.device_fingerprint.FP_STATE_ROOT", tmp_path / "fp"
|
||||
)
|
||||
state = account_state_dir("hy_test")
|
||||
state.mkdir(parents=True)
|
||||
(state / "localstorage.json").write_text("{}", encoding="utf-8")
|
||||
(state / "device.json").write_text("{}", encoding="utf-8")
|
||||
reset_account_state("hy_test")
|
||||
assert not (state / "localstorage.json").exists()
|
||||
assert not (state / "device.json").exists()
|
||||
|
||||
def test_wup_encoder_output(self):
|
||||
dev = generate_profile()
|
||||
pkt = build_password_login_wup(
|
||||
@@ -121,6 +134,12 @@ class TestHuyaAppLogin:
|
||||
total_len = struct.unpack(">I", pkt[:4])[0]
|
||||
assert total_len == len(pkt)
|
||||
|
||||
def test_app_login_name_keeps_mobile_number(self):
|
||||
"""App 协议手机号登录名不能套用虎牙号的 hy_ 前缀。"""
|
||||
assert _make_name("15197635967") == "15197635967"
|
||||
assert _make_name("300023887") == "hy_300023887"
|
||||
assert _make_name("hy_300023887") == "hy_300023887"
|
||||
|
||||
# ---- 新设备注册链 (core/huya/dfp_register) 生产接入测试 ----
|
||||
|
||||
def test_wup_login_skips_registration_when_safedeviceid_given(self):
|
||||
@@ -192,6 +211,54 @@ class TestHuyaAppLogin:
|
||||
):
|
||||
login_cred_with_flow("300023887", "pw")
|
||||
|
||||
def test_login_cred_flow_reuses_wup_session_after_slider(self):
|
||||
"""滑块通过后的 WUP 重发必须沿用首次请求的会话上下文。"""
|
||||
assets = ({"session": 123}, "ua", "")
|
||||
responses = [b"risk", b"success"]
|
||||
calls = []
|
||||
|
||||
def fake_wup(*args, **kwargs):
|
||||
calls.append(kwargs["session_assets"])
|
||||
return responses.pop(0)
|
||||
|
||||
with (
|
||||
patch(
|
||||
"core.huya.app_login.register_device",
|
||||
return_value=("a" * 32, "A" * 180, "c" * 40),
|
||||
),
|
||||
patch("core.huya.app_login._golden_session_assets", return_value=assets),
|
||||
patch("core.huya.app_login.wup_password_login_raw", side_effect=fake_wup),
|
||||
patch("core.huya.app_login.parse_cred", side_effect=[None, b"c" * 114]),
|
||||
patch(
|
||||
"core.huya.app_login.parse_risk_url",
|
||||
return_value="https://aq.huya.com/p/safe_auth/pt_auth.html?param=x",
|
||||
),
|
||||
patch("core.huya.app_login.solve_safe_auth", return_value={"authId": "id"}),
|
||||
patch("core.huya.app_login.parse_real_uid", return_value=1199666914671),
|
||||
):
|
||||
cred, uid = login_cred_with_flow("300023887", "pw")
|
||||
|
||||
assert cred == b"c" * 114
|
||||
assert uid == 1199666914671
|
||||
assert calls == [assets, assets]
|
||||
|
||||
def test_login_cred_flow_maps_invalid_password_response(self):
|
||||
"""服务端明确返回账号密码错误时,不再显示泛化的无凭据提示。"""
|
||||
with (
|
||||
patch(
|
||||
"core.huya.app_login.register_device",
|
||||
return_value=("a" * 32, "A" * 180, "c" * 40),
|
||||
),
|
||||
patch(
|
||||
"core.huya.app_login.wup_password_login_raw",
|
||||
return_value=b"F!LGN_INFO_INVALID_USER_OR_PASSWORDV",
|
||||
),
|
||||
patch("core.huya.app_login.parse_cred", return_value=None),
|
||||
patch("core.huya.app_login.parse_risk_url", return_value=None),
|
||||
pytest.raises(HuyaAppLoginError, match="账号或密码错误"),
|
||||
):
|
||||
login_cred_with_flow("300023887", "pw")
|
||||
|
||||
def test_router_functions(self):
|
||||
mock_res = HuyaLoginResult(
|
||||
success=True,
|
||||
|
||||
Reference in New Issue
Block a user