fix(huya): 抽出通用绑定角色查询,修复外部单协作读到旧角色
This commit is contained in:
@@ -18,8 +18,7 @@ from core.huya.taf_protocol import TafOutputStream, TafType
|
||||
from tests.support.db import get_test_engine, make_test_session
|
||||
from web.backend.deps import require_permission
|
||||
from web.backend.huya_defaults import (
|
||||
HUYA_DEFAULT_BIND_ACT_ID,
|
||||
HUYA_DEFAULT_OUTER_ACT_ID,
|
||||
HUYA_DEFAULT_BIND_GID,
|
||||
)
|
||||
from web.backend.models import (
|
||||
AuditLog,
|
||||
@@ -763,6 +762,13 @@ class FakeBindResp:
|
||||
),
|
||||
)
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
return {
|
||||
"status": self.status,
|
||||
"msg": self.msg,
|
||||
"game_name": self.gameName,
|
||||
}
|
||||
|
||||
|
||||
class FakeGiftResp:
|
||||
"""合成一份 ``getActPrizeList`` 响应(礼包列表)。"""
|
||||
@@ -883,12 +889,21 @@ class FakeProbeClient:
|
||||
self.calls: list[dict] = []
|
||||
self.gift_calls: list[dict] = []
|
||||
self.points_calls: list[dict] = []
|
||||
self._current_bind_outcome: object | None = None
|
||||
|
||||
def check_user_bind_game_account(self, **kwargs):
|
||||
self.calls.append(kwargs)
|
||||
if not self.outcomes:
|
||||
raise AssertionError("探针被调用的次数超出用例预期")
|
||||
outcome = self.outcomes.pop(0)
|
||||
if kwargs.get("outer_act_id"):
|
||||
# 外层(第一路):按脚本弹一个响应。
|
||||
if not self.outcomes:
|
||||
raise AssertionError("探针被调用的次数超出用例预期")
|
||||
outcome = self.outcomes.pop(0)
|
||||
self._current_bind_outcome = outcome
|
||||
else:
|
||||
# 内层(第二路):复用当前外层响应;需要内外层不同时用自定义 client。
|
||||
outcome = self._current_bind_outcome
|
||||
if outcome is None:
|
||||
raise AssertionError("内层查询在没有外层结果时被调用")
|
||||
if isinstance(outcome, Exception):
|
||||
raise outcome
|
||||
return outcome
|
||||
@@ -947,21 +962,49 @@ class TestCollabCkProbe(TestCollabBase):
|
||||
|
||||
collab.verify_ck(self.db, self.user, order, client=client)
|
||||
|
||||
call = client.calls[0]
|
||||
assert call["uid"] == 1199647239697
|
||||
assert isinstance(call["uid"], int)
|
||||
assert call["cookie"] == order.cookie
|
||||
assert (
|
||||
call["b_act_id"]
|
||||
== collab.PROBE_BIND_ACT_ID
|
||||
== int(HUYA_DEFAULT_BIND_ACT_ID)
|
||||
)
|
||||
assert call["is_use_outer_act_id"] == 1
|
||||
assert (
|
||||
call["outer_act_id"]
|
||||
== collab.PROBE_OUTER_ACT_ID
|
||||
== HUYA_DEFAULT_OUTER_ACT_ID
|
||||
)
|
||||
# 通用查询两路:外层 gid+outerActId,内层 gid+outerActId=空。
|
||||
outer, inner = client.calls[0], client.calls[1]
|
||||
assert outer["uid"] == 1199647239697
|
||||
assert isinstance(outer["uid"], int)
|
||||
assert outer["cookie"] == order.cookie
|
||||
assert outer["b_act_id"] == 0
|
||||
assert outer["gid"] == collab.PROBE_GID == int(HUYA_DEFAULT_BIND_GID)
|
||||
assert outer["outer_act_id"] == collab.PROBE_OUTER_ACT_ID
|
||||
assert outer["is_use_outer_act_id"] == 0
|
||||
assert outer["scene"] == collab.PROBE_SCENE == "undefined"
|
||||
assert inner["gid"] == collab.PROBE_GID == 3203
|
||||
assert inner["outer_act_id"] == ""
|
||||
assert inner["is_use_outer_act_id"] == 0
|
||||
assert inner["scene"] == "undefined"
|
||||
|
||||
def test_verify_queries_second_path_for_latest_role(self):
|
||||
"""外层返回旧角色时,必须取第二路(outerActId=空)的最新角色。"""
|
||||
order = self._row_with_ck(uid="1199647239697")
|
||||
|
||||
class StaleThenLatestClient:
|
||||
def __init__(self):
|
||||
self.calls: list[dict] = []
|
||||
|
||||
def check_user_bind_game_account(self, **kwargs):
|
||||
self.calls.append(kwargs)
|
||||
if kwargs["outer_act_id"]:
|
||||
return FakeBindResp(nick="冰点", role="软芙乎")
|
||||
return FakeBindResp(nick="冰点", role="唉哟酪酪")
|
||||
|
||||
client = StaleThenLatestClient()
|
||||
|
||||
collab.verify_ck(self.db, self.user, order, client=client)
|
||||
|
||||
outer, inner = client.calls[0], client.calls[1]
|
||||
assert outer["outer_act_id"] == collab.PROBE_OUTER_ACT_ID
|
||||
assert inner["outer_act_id"] == ""
|
||||
assert inner["gid"] == collab.PROBE_GID == 3203
|
||||
assert inner["scene"] == "undefined"
|
||||
# 快照落的是第二路的最新角色,而不是外层旧角色
|
||||
assert order.bind_game_role == "唉哟酪酪"
|
||||
assert order.bind_game_account == "冰点"
|
||||
assert "唉哟酪酪" in order.ck_check_message
|
||||
assert "软芙乎" not in order.ck_check_message
|
||||
|
||||
def test_verify_marks_invalid_when_status_is_not_200(self):
|
||||
order = self._row_with_ck()
|
||||
@@ -1241,7 +1284,7 @@ class TestCollabCkProbe(TestCollabBase):
|
||||
# 没 CK 的行保持「未验证」,不能谎报成「已失效」
|
||||
assert without_ck.ck_status == "unverified"
|
||||
assert "CK" in result["results"][1]["message"]
|
||||
assert len(client.calls) == 1 # 没 CK 的行不发请求
|
||||
assert len(client.calls) == 2 # 有 CK 的行两路(外层+内层),没 CK 的行不发请求
|
||||
|
||||
def test_batch_keeps_interval_between_rows(self, monkeypatch):
|
||||
"""人工触发也要串行 + 间隔,别把账号送进风控名单。"""
|
||||
@@ -2134,8 +2177,8 @@ class TestCollabRecharge(TestCollabBase):
|
||||
assert (
|
||||
order.points_check_detail["group_key"] == f"{self.BIND} / {self.ROLE}"
|
||||
)
|
||||
# 同一 uid 只验一次 CK、只查一次积分
|
||||
assert len(client.calls) == 1
|
||||
# 同一 uid 只验一次 CK(两路查询)、只查一次积分
|
||||
assert len(client.calls) == 2
|
||||
assert len(client.score_calls) == 1
|
||||
assert "huya:collab:recharge_check" in [
|
||||
row.action for row in self._audits(first)
|
||||
@@ -3136,7 +3179,7 @@ class TestProbeCache(TestCollabBase):
|
||||
collab.probe_ck(order)
|
||||
collab.probe_ck(order)
|
||||
|
||||
assert len(calls) == 1
|
||||
assert len(calls) == 2 # 第一次探针两路(外层+内层),第二次命中缓存
|
||||
collab._probe_cache.clear()
|
||||
|
||||
def test_different_ck_is_probed_separately(self, monkeypatch):
|
||||
@@ -3155,7 +3198,7 @@ class TestProbeCache(TestCollabBase):
|
||||
collab.probe_ck(first)
|
||||
collab.probe_ck(second)
|
||||
|
||||
assert len(calls) == 2
|
||||
assert len(calls) == 4 # 两个 CK 各自两路(外层+内层)
|
||||
collab._probe_cache.clear()
|
||||
|
||||
|
||||
|
||||
@@ -1050,14 +1050,20 @@ def test_confirm_bind_uses_latest_har_protocol(monkeypatch):
|
||||
"outer_act_id": "17096",
|
||||
}
|
||||
]
|
||||
assert all(
|
||||
call["b_act_id"] == 0
|
||||
and call["gid"] == 3203
|
||||
and call["outer_act_id"] == "17096"
|
||||
and call["is_use_outer_act_id"] == 0
|
||||
and call["scene"] == "undefined"
|
||||
for call in client.check_calls
|
||||
)
|
||||
# 通用查询会连打两路:外层 gid+outerActId=17096,内层 gid+outerActId=空。
|
||||
assert len(client.check_calls) == 4 # 绑定前查一次 + 确认后刷新查一次
|
||||
for call in client.check_calls[0::2]:
|
||||
assert call["b_act_id"] == 0
|
||||
assert call["gid"] == 3203
|
||||
assert call["outer_act_id"] == "17096"
|
||||
assert call["is_use_outer_act_id"] == 0
|
||||
assert call["scene"] == "undefined"
|
||||
for call in client.check_calls[1::2]:
|
||||
assert call["b_act_id"] == 0
|
||||
assert call["gid"] == 3203
|
||||
assert call["outer_act_id"] == ""
|
||||
assert call["is_use_outer_act_id"] == 0
|
||||
assert call["scene"] == "undefined"
|
||||
|
||||
|
||||
def test_get_bind_qr_uses_latest_har_protocol(monkeypatch):
|
||||
|
||||
Reference in New Issue
Block a user