#!/usr/bin/env python3 """Self-test of the iishko sandbox broker (guard rails + optional live job). python prove.py # guard-rail tests only (no credits burned) python prove.py --live URL # + real sandbox job against URL """ import json import sys import time import urllib.error import urllib.request BASE = "http://127.0.0.1:48970" KEY = open("keys_test.txt", encoding="utf-8").read().strip() def call(path, method="GET", body=None, key=KEY): data = json.dumps(body).encode() if body is not None else None req = urllib.request.Request(BASE + path, data=data, method=method, headers={ "x-sandbox-key": key, "content-type": "application/json"}) try: with urllib.request.urlopen(req, timeout=120) as r: return r.status, json.loads(r.read().decode() or "{}") except urllib.error.HTTPError as e: raw = e.read().decode() try: return e.code, json.loads(raw or "{}") except Exception: return e.code, {"raw": raw[:200]} def check(name, cond, detail=""): print(("PASS " if cond else "FAIL ") + name + (" | " + str(detail) if detail else "")) return cond ok = True st, js = call("/healthz", key="") ok &= check("healthz", st == 200 and js.get("ok") is True, js.get("pools")) st, js = call("/v1/limits", key="wrong-key") ok &= check("reject bad key", st == 401, js) st, js = call("/v1/jobs", "POST", {"target": "http://example.com", "instruction": "x"}) ok &= check("reject http target", st == 403 and js.get("reason") == "https_only", js) st, js = call("/v1/jobs", "POST", {"target": "https://127.0.0.1/x", "instruction": "x"}) ok &= check("reject local host", st == 403 and js.get("reason") in ("private_or_local_host", "https_only"), js) st, js = call("/v1/jobs", "POST", {"target": "https://api.reformboss.com", "instruction": "x"}) ok &= check("reject our host", st == 403 and js.get("reason") == "denied_host", js) st, js = call("/v1/jobs", "POST", {"target": "https://example.com", "instruction": "use key sk-abcdefghijklmnopqrstuvwxyz123456"}) ok &= check("reject secret in instruction", st == 403 and js.get("reason") == "credential_material_in_instruction", js) st, js = call("/v1/limits") ok &= check("limits endpoint", st == 200 and "used_today_micros" in js, js) if "--live" in sys.argv: target = sys.argv[sys.argv.index("--live") + 1] st, js = call("/v1/jobs", "POST", { "target": target, "instruction": "Enumerate exposed paths and response headers, report missing security headers with evidence. Stay on this host.", "budget_micros": 200000}) print("live launch:", st, json.dumps(js)[:400]) if st in (200, 202): jid = js["id"] for _ in range(60): time.sleep(15) st, jj = call("/v1/jobs/" + jid) print("status", jj.get("status"), "spent", jj.get("spent_micros")) if str(jj.get("status")).lower() in ("completed", "failed", "cancelled", "canceled"): print(json.dumps(jj, ensure_ascii=False)[:2000]) break else: ok = False print("RESULT:", "OK" if ok else "FAILURES") sys.exit(0 if ok else 1)