diff --git a/_tests/test_landing_live.py b/_tests/test_landing_live.py new file mode 100644 index 0000000..c3fc1e9 --- /dev/null +++ b/_tests/test_landing_live.py @@ -0,0 +1,84 @@ +# -*- coding: utf-8 -*- +r'''验证线上官网已经是新版。''' +from __future__ import annotations + +import sys +import urllib.error +import urllib.request +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "_build")) +from devssh import run as ssh_run # noqa: E402 + +BASE = "https://relay.xxmxxs.top" +UA = {"User-Agent": "LanRemote/1.8.2"} + +passed = 0 +failed = 0 + + +def check(name, ok, detail=""): + global passed, failed + if ok: + passed += 1 + print(" [PASS] " + name) + else: + failed += 1 + print(" [FAIL] " + name + ((" —— " + str(detail)) if detail else "")) + + +def main() -> int: + print("=" * 56) + print(" 线上官网验证") + print("=" * 56) + + # 先用设备上的本机地址绕开 Cloudflare 缓存看个准的 + _c, local, _e = ssh_run( + "curl -s --max-time 15 -H 'User-Agent: LanRemote/1.8.2' " + "http://127.0.0.1:8080/", timeout=60, quiet=True) + + # 再看公网(可能有最多 60 秒缓存) + req = urllib.request.Request(BASE + "/", headers=UA) + try: + with urllib.request.urlopen(req, timeout=25) as resp: + pub = resp.read().decode("utf-8", "replace") + cc = resp.headers.get("cf-cache-status", "") + ok_pub = True + except Exception as exc: # noqa: BLE001 + pub = "" + cc = "" + ok_pub = False + print(" 公网拉取失败:%s" % exc) + + for label, html in (("本机", local or ""), ("公网", pub)): + if not html: + continue + print() + print(" ---- %s 版本 ----" % label) + check("%s:是新版" % label, "scroll-hint" in html, + "没有 scroll-hint,还是旧版") + check("%s:有数据带" % label, 'class="stats"' in html, "没有") + check("%s:有评价区" % label, 'class="quotes"' in html, "没有") + check("%s:有平台标签行" % label, 'class="plats"' in html, "没有") + check("%s:有滚动淡入脚本" % label, + "IntersectionObserver" in html, "没有") + check("%s:HTML 里没有裸 reveal(没 JS 也可见)" % label, + "reveal\"" not in html.split("