Files
live-hub-py/tests/test_huya_rotate_auth.py
T
yml2213 d3005478a9 feat(huya): 支持四段式账号导入接码及旋转/文本点选多级验证码闭环过验
- 账号导入:支持'账号----密码----手机号----接码链接'四段式解析与持久化存储
- 旋转验证码 (rotate_auth / xz):逆向分析官方协议,基于圆周边界采样互相关算法秒级计算旋转还原角度
- 文本点选验证码 (dx_auth):内置成语与古诗名句语料,支持题干菜名提取与古诗/成语挖空正则求解及小图动态合成
- 短信二次验证 (sms_auth2):结合 sms_url 自动轮询接码链接并 Hex 编码提交官方过验
- 前端交互:增加接码标签、在线查询短信验证码、一键自动短信登录与测试接码链接功能
- 回归测试:新增旋转验证、短信接码流与文本点选测试用例(173 passed)
2026-09-06 13:56:44 +08:00

64 lines
2.3 KiB
Python

"""虎牙旋转验证码 (rotate_auth / xz) 求解与捕获测试。"""
from __future__ import annotations
from pathlib import Path
from core.huya.verification.capture import CaptchaCaptureRecord
from core.huya.verification.solver import HuyaVerificationSolver
def test_rotate_strategy_recognized():
"""验证 rotate_auth.html 能被正确解析为 rotate_auth 类型。"""
url = (
"https://aq.huya.com/p/safe_auth/rotate_auth.html?"
"hideShareButton=1&param=test_param&sceneType=4&appId=5008&mobile=001******5865"
)
solver = HuyaVerificationSolver(page_url=url, account="test_rotate")
solver._parse_strategy(url)
assert solver.auth_type == "rotate_auth"
def test_opencv_rotate_angle_accuracy():
"""验证真实旋转验证码图片能够精准计算出旋转还原角度。"""
sample_dir = Path("data/captcha_captures/20260906_132605_pt_auth_348f71b3")
if not sample_dir.exists():
return
bg_bytes = (sample_dir / "bg_restored.jpg").read_bytes()
puzzle_bytes = (sample_dir / "puzzle.png").read_bytes()
angle = HuyaVerificationSolver._opencv_rotate_angle(bg_bytes, puzzle_bytes)
# 该样本的真值在 142 度左右
assert 138 <= angle <= 146
def test_capture_rotate_data(tmp_path: Path):
"""测试旋转验证码捕获能正确落盘并生成标注图与元数据。"""
sample_dir = Path("data/captcha_captures/20260906_132605_pt_auth_348f71b3")
if not sample_dir.exists():
return
bg_bytes = (sample_dir / "bg_restored.jpg").read_bytes()
puzzle_bytes = (sample_dir / "puzzle.png").read_bytes()
record = CaptchaCaptureRecord(
auth_type="rotate_auth",
account="test_user",
page_url="https://aq.huya.com/p/safe_auth/rotate_auth.html?param=123",
scene_type="4",
output_base_dir=tmp_path,
)
out_dir = record.capture_rotate_data(
code="test_code_1234",
dtu_bytes=bg_bytes,
puzzle_bytes=puzzle_bytes,
restored_bg_bytes=bg_bytes,
angle=142,
raw_data={"code": "test_code_1234", "title": "旋转验证"},
)
assert (out_dir / "annotated.jpg").exists()
assert (out_dir / "meta.json").exists()
assert record.meta["solution"]["angle"] == 142
assert record.meta["auth_type"] == "rotate_auth"