test_s3_cron_entry.py
1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python3
"""S3 RED test: Verify cron.html job cards link to /cron/<job_id>."""
import subprocess, sys, os
os.chdir(os.path.expanduser("~/wechat-viewer"))
BASE = "http://127.0.0.1:5000"
FAIL = 0
r = subprocess.run(["curl", "-s", f"{BASE}/cron"], capture_output=True, text=True, timeout=10)
html = r.stdout
def check(desc, test_fn):
global FAIL
ok = test_fn()
status = "PASS" if ok else "FAIL"
if not ok:
FAIL += 1
print(f"[{status}] {desc}")
# 1. Cron page loads
check("GET /cron returns 200", lambda: r.returncode == 0 and len(html) > 100)
# 2. Job card onclick redirects to /cron/<job_id>
check("onclick uses window.location=/cron/",
lambda: "/cron/" in html and "location" in html)
# 3. NOT using old viewLogs in onclick
check("NOT using viewLogs in onclick",
lambda: 'onclick="viewLogs' not in html and "onclick='viewLogs" not in html)
# 4. Has href-like navigation
check("Contains /cron/ path in script",
lambda: "/cron/" in html)
# 5. Jinja2 escape check
check("No Jinja2 script escapes", lambda: 'onclick=\\"' not in html)
print(f"\nResult: {FAIL} failures")
sys.exit(min(FAIL, 1))