Files
endorphin-tabularium-docs/scripts/smoke.py
T
codex-bot 9fcfbdb694
Verify and deploy Tabularium / verify-and-deploy (push) Successful in 5m28s
Protect Tabularium with persistent authenticator-code login
2026-10-27 21:48:16 +08:00

42 lines
1.5 KiB
Python

"""Check the public authentication boundary; auth-cli verify checks private content."""
import json
import sys
import urllib.error
import urllib.parse
import urllib.request
class NoRedirect(urllib.request.HTTPRedirectHandler):
def redirect_request(self, req, fp, code, msg, headers, newurl):
return None
def verify(base: str) -> None:
opener = urllib.request.build_opener(NoRedirect())
base = base.rstrip("/")
def get(path):
try:
response = opener.open(base + path, timeout=15)
except urllib.error.HTTPError as error:
response = error
with response:
return response.code, response.headers, response.read()
status, _, health = get("/api/health")
assert status == 200 and json.loads(health) == {"status": "ok"}
status, _, login = get("/login")
assert status == 200 and "输入动态码" in login.decode()
for path in ("/", "/docs/00-endor-concepts-draft", "/figures/endor-architecture.svg"):
status, headers, _ = get(path)
assert status == 307, path
target = urllib.parse.urlparse(urllib.parse.urljoin(base, headers["Location"]))
assert target.netloc == urllib.parse.urlparse(base).netloc and target.path == "/login"
assert "no-store" in headers.get("Cache-Control", "")
assert get("/api/unknown")[0] == 401
print(f"Public auth boundary passed: {base} (login, health, protected pages/SVG/API)", flush=True)
if __name__ == "__main__":
verify(sys.argv[1])