smoke_a2.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. """A2 smoke test v2: real endpoints from saz capture.
  2. Tests request_sms against the REAL user-api.996hezi.com endpoint with a
  3. fake phone. Expected good outcomes:
  4. - 101000 (captcha required) → endpoint + protocol CORRECT
  5. - 40001 (phone format) → endpoint alive, validating
  6. - anything except 404 / SSL error → progress
  7. Note: user-api.996hezi.com 的证书链在裸 httpx 下验不过 (缺中间证书),
  8. smoke 模式关 verify; 真跑 A2 时 Box996Login 自带 httpx 客户端同样要处理。
  9. """
  10. import asyncio
  11. import ssl
  12. import sys
  13. from pathlib import Path
  14. _HERE = Path(__file__).resolve().parent
  15. sys.path.insert(0, str(_HERE.parent / "src"))
  16. from cq2_sdk.env_loader import load_env
  17. load_env(_HERE.parent / ".env")
  18. import httpx
  19. from cq2_sdk.login import Box996Login, CaptchaRequiredError, ManualGeetestSolver
  20. from cq2_sdk.login.box_996 import Box996Error
  21. DEVICE_ID = "00:15:5d:0a:04:00"
  22. FAKE_PHONE = "13800138000"
  23. async def main() -> int:
  24. box = Box996Login(geetest=ManualGeetestSolver(), device_id=DEVICE_ID)
  25. # 关证书验证 (只 smoke 用; 证书链问题见文件头注释)
  26. box._client = httpx.AsyncClient(
  27. timeout=15, verify=False,
  28. headers={"User-Agent": "996Box/5.1.1.9007"},
  29. )
  30. print(f"[smoke] request_sms({FAKE_PHONE!r}) against REAL endpoint")
  31. print(f" POST user-api.996hezi.com/v1/UserInfo/get_phone_code")
  32. print()
  33. try:
  34. resp = await box.request_sms(FAKE_PHONE)
  35. print(f"[UNEXPECTED-OK] 200: {resp!r}")
  36. return 0
  37. except CaptchaRequiredError as e:
  38. print(f"[BEST-CASE] 101000 captcha required: {e}")
  39. print(" → endpoint + protocol CORRECT (server processed request)")
  40. print(" → real run prompts geetest here, then resends with _captcha_")
  41. return 0
  42. except Box996Error as e:
  43. print(f"[GOOD] server responded code={e.code}: {e.msg[:80]}")
  44. print(f" endpoint={e.endpoint}")
  45. print(" → endpoint alive, request shape accepted")
  46. return 0
  47. except Exception as e:
  48. print(f"[ERROR] {type(e).__name__}: {str(e)[:150]}")
  49. return 1
  50. if __name__ == "__main__":
  51. sys.exit(asyncio.run(main()))