虎牙网页Cookie来源驱动合并与WSS传输门禁
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
import asyncio
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
from core.huya.activity_structs import ActPrizeDetailItem, GetActPrizeDetailResp
|
||||
from core.huya.http_client import SHOP_BIZ_UA, HuyaHttpClient
|
||||
from core.huya.shop_structs import (
|
||||
@@ -8,6 +11,8 @@ from core.huya.shop_structs import (
|
||||
ShopCodeRsp,
|
||||
)
|
||||
from core.huya.taf_protocol import TafInputStream, TafOutputStream, TafType
|
||||
from core.huya.wss_client import TAIL_BYTES, HuyaWssClient, WssCommand, WssMessage
|
||||
from web.backend.services.huya_runner_core import HuyaBatchRunnerCore
|
||||
|
||||
|
||||
def _round_trip(value):
|
||||
@@ -87,3 +92,39 @@ def test_shop_preflight_response_contracts():
|
||||
status.message = ""
|
||||
decoded_status = _round_trip(status)
|
||||
assert decoded_status.code == 200
|
||||
|
||||
|
||||
def test_wss_requires_web_device_cookie_fields():
|
||||
assert not HuyaBatchRunnerCore._has_web_wss_cookie(
|
||||
"udb_cred=x; udb_biztoken=x; udb_uid=1; yyuid=1"
|
||||
)
|
||||
assert HuyaBatchRunnerCore._has_web_wss_cookie(
|
||||
"udb_cred=x; udb_biztoken=x; udb_uid=1; yyuid=1; sdid=s; guid=g; "
|
||||
"udb_guiddata=gd; udb_deviceid=w_1234567890123456789; game_did=did; "
|
||||
"_qimei_uuid42=q; udb_anobiztoken=ab; __yamid_new=y"
|
||||
)
|
||||
|
||||
|
||||
def test_activity_auth_frame_matches_latest_capture_layout():
|
||||
async def build_frame():
|
||||
client = HuyaWssClient()
|
||||
client.ws = type("FakeWs", (), {"send": AsyncMock()})()
|
||||
await client.send_auth(1199664135026, "udb_cred=" + "x" * 300, sequence=0x1D000109)
|
||||
return client.ws.send.call_args.args[0]
|
||||
|
||||
message = WssMessage.decode(asyncio.run(build_frame()))
|
||||
assert message.command == WssCommand.AUTH
|
||||
assert message.sequence == 0x1D000109
|
||||
assert message.body.endswith(TAIL_BYTES)
|
||||
|
||||
stream = TafInputStream(message.body[: -len(TAIL_BYTES)])
|
||||
assert stream.read_int64(0) == 1199664135026
|
||||
assert stream.read_string(1) == "webh5&0.0.1&websocket&&diypc_52775"
|
||||
assert stream.read_head() == (2, TafType.STRING4)
|
||||
cookie_len = int.from_bytes(stream.buf.read(4), "big")
|
||||
assert cookie_len > 255
|
||||
stream.buf.read(cookie_len)
|
||||
assert stream.read_int32(3) == 0
|
||||
assert stream.read_int8(4) == 1
|
||||
assert stream.read_string(5) == "HUYA&ZH&2052"
|
||||
assert stream.read_string(6) == ""
|
||||
|
||||
Reference in New Issue
Block a user