diff --git a/CLAUDE.md b/CLAUDE.md index 3c24cce..9420cfa 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -71,6 +71,7 @@ Never modify: `~/Documents/Apps/Nacre` (the original Python Nacre, reference onl | `SMOKE_SIZE=1400x900 tools/smoke.sh tests/smoke/backgrounds.txt` | every new tab background with the pointer, Customize panel dark/light, image + blur, GIF frames; `perf-*-a/b.json` `frames` (median/max draw ms, `drawn` count) per background at Lots/Fast, hidden tab, still, Motion off. Selftest `pointer x y`, `customize`; `@PAGESDIR@` = path of tests/smoke/pages | now (S018) | | `tools/smoke.sh tests/smoke/settings.txt` (+ `SMOKE_SIZE=1280x1100`) | every settings section and sub-page dark and light, search results (`nacre://settings/?search=…`), narrow width; `settings-write.txt` (hidden, `SMOKE_SIZE=1280x1100`, fresh outdir) taps controls with selftest `tap x y`, then check `home/.config/nacre-servo/Default/settings.json` (expected values in its header) | now (S019) | | `SMOKE_SIZE=1280x1600 tools/smoke.sh tests/smoke/sliders.txt` | controls hold still (R1-21): Interface size drag (value label while held, applied on release), Contrast live, Style chip pick; `SMOKE_VISIBLE=1 tools/smoke.sh tests/smoke/sliders-visible.txt` the same plus scrolling for the user's window (~772 px). Selftest `press`/`drag`/`release`, `scroll x y dy`; read the PNGs | now (R1-21) | +| `python3 tests/smoke/net/server.py &` + `tools/smoke.sh tests/smoke/net-{privacy,adblock,downloads}.txt` | network pass, offline: secure DNS through a local DoH stub (`*.nacre.test` → 127.0.0.1), HTTPS-only + certificate warning, tracking params, ad blocker with a local list, downloads + download manager stubs; the server's `/log` has requests, DNS names, Range headers, manager calls. `cache-restart.txt` with `SMOKE_HOME=/home`: disk cache. `net-real.txt` needs internet. `@HOME@` in scripts = the throwaway home | now (S007) | | `python tools/icons.py` | rebuilds the icon font subset and `src/ui/icons.rs` from `tools/icons.txt` (needs fontTools and Arch's ttf-material-symbols-variable) | now (S015) | | appimagetool, wine + Inno Setup, VM "Windows 10" | packaging and Windows checks | see the user's global CLAUDE.md "Building" | diff --git a/src/selftest.rs b/src/selftest.rs index 5ae6e5d..0ec2e71 100644 --- a/src/selftest.rs +++ b/src/selftest.rs @@ -19,7 +19,8 @@ //! do a shortcut action by its settings key, e.g. `do new_tab` //! cmd [arg] back, forward, reload, bookmark, install_app, pip, exitpip, free_memory, //! update_lists, check_updates, close_tab, select , zoom , -//! find , download , navigate , mute, pin +//! find , download , pause_download|resume_download|cancel_download [id] (newest), +//! navigate , mute, pin //! js + + +""" + +FILTER_LIST = b"""! Title: Nacre network smoke test list (S007) +! Served by tests/smoke/net/server.py; every rule names something only the test pages use. +/ads/banner.js +/ads/pixel.gif +nacre.test,127.0.0.1##.nacre-ad +###nacre-generic-ad +""" + +GIF = bytes.fromhex("47494638396101000100800000ffffff00000021f90401000000002c00000000010001000002024401003b") + + +class Handler(BaseHTTPRequestHandler): + protocol_version = "HTTP/1.1" + + def do_GET(self): + url = urlsplit(self.path) + path = url.path + record("paths", self.path) + if path == "/dns-query": + import base64 + wire = parse_qs(url.query).get("dns", [""])[0] + query = base64.urlsafe_b64decode(wire + "=" * (-len(wire) % 4)) + return self.reply(dns_answer(query), "application/dns-message") + if path == "/log": + with lock: + return self.reply(json.dumps(log).encode(), "application/json") + if path == "/": + scheme = "https" if isinstance(self.connection, ssl.SSLSocket) else "http" + links = '

zip attachment report' + return self.reply(f"Net test {scheme}

Net test over {scheme}{links}".encode(), "text/html") + if path == "/echo": + return self.reply(f"Echo {url.query}

{url.query}".encode(), "text/html") + if path == "/ads.html": + return self.reply(ADS_PAGE, "text/html") + if path == "/ads/banner.js": + return self.reply(b"window.adScript = true;", "text/javascript") + if path == "/ads/pixel.gif": + return self.reply(GIF, "image/gif") + if path == "/list.txt": + return self.reply(FILTER_LIST, "text/plain") + if path == "/file.zip": + return self.reply(b"PK\x05\x06" + b"\x00" * 18, "application/zip") + if path in ("/attachment", "/report"): + return self.reply(b"attachment body\n", "application/octet-stream", {"Content-Disposition": 'attachment; filename="report.txt"'}) + if path == "/big.bin": + return self.big() + self.reply(b"not found", "text/plain", status=404) + + def do_HEAD(self): + url = urlsplit(self.path) + record("paths", "HEAD " + self.path) + if url.path in ("/attachment", "/report"): + self.send_response(200) + self.send_header("Content-Type", "application/octet-stream") + self.send_header("Content-Disposition", 'attachment; filename="report.txt"') + self.send_header("Content-Length", "16") + self.end_headers() + else: + self.send_response(200) + self.send_header("Content-Type", "text/html") + self.send_header("Content-Length", "0") + self.end_headers() + + def do_POST(self): + length = int(self.headers.get("Content-Length") or 0) + body = self.rfile.read(length).decode("utf-8", "replace") + path = urlsplit(self.path).path + record("paths", "POST " + self.path) + if path == "/jsonrpc": + call = json.loads(body) + record("dlm", {"manager": "aria2", "method": call.get("method"), "params": call.get("params")}) + result = {"version": "1.37.0"} if call.get("method") == "aria2.getVersion" else "2089b05ecca3d829" + return self.reply(json.dumps({"id": call.get("id"), "jsonrpc": "2.0", "result": result}).encode(), "application/json") + if path == "/add": + record("dlm", {"manager": "abdm", "body": json.loads(body)}) + return self.reply(b"OK", "text/plain") + if path in ("/flashgot", "/flash/add"): + record("dlm", {"manager": "jdownloader", "path": path, "form": parse_qs(body)}) + return self.reply(b"success\r\n", "text/plain") + self.reply(b"not found", "text/plain", status=404) + + def big(self): + start = 0 + wanted = self.headers.get("Range") + if wanted: + record("ranges", wanted) + start = int(wanted.split("=")[1].split("-")[0]) + self.send_response(206 if start else 200) + self.send_header("Content-Type", "application/octet-stream") + self.send_header("Accept-Ranges", "bytes") + self.send_header("Content-Length", str(BIG - start)) + if start: + self.send_header("Content-Range", f"bytes {start}-{BIG - 1}/{BIG}") + self.end_headers() + chunk = 64 * 1024 + sent = start + try: + while sent < BIG: + # Byte i of the file is i % 251, so a resumed file can be checked end to end. + n = min(chunk, BIG - sent) + self.wfile.write(bytes((sent + i) % 251 for i in range(n))) + sent += n + time.sleep(0.11) + except (BrokenPipeError, ConnectionResetError, ssl.SSLError): + pass + + def reply(self, body, kind, headers=None, status=200): + self.send_response(status) + self.send_header("Content-Type", kind) + self.send_header("Content-Length", str(len(body))) + self.send_header("Cache-Control", "no-store") + for name, value in (headers or {}).items(): + self.send_header(name, value) + self.end_headers() + self.wfile.write(body) + + def log_message(self, *args): + pass + + +class Sniffing(ThreadingHTTPServer): + """Plain HTTP and TLS on one port: a TLS connection starts with a handshake record (0x16).""" + daemon_threads = True + tls = None + + def finish_request(self, request, client_address): + if self.tls is not None: + request.settimeout(10) + try: + first = request.recv(1, socket.MSG_PEEK) + except OSError: + return + if first == b"\x16": + with lock: + log["tls"] += 1 + try: + request = self.tls.wrap_socket(request, server_side=True) + except (ssl.SSLError, OSError): + return # the browser refused the certificate + request.settimeout(None) + super().finish_request(request, client_address) + + +both = Sniffing(("127.0.0.1", 8766), Handler) +both.tls = make_cert() +plain = Sniffing(("127.0.0.1", 8767), Handler) +threading.Thread(target=plain.serve_forever, daemon=True).start() +both.serve_forever() diff --git a/tools/smoke.sh b/tools/smoke.sh index 1597afa..c5ee72f 100755 --- a/tools/smoke.sh +++ b/tools/smoke.sh @@ -23,7 +23,8 @@ # Script commands (src/selftest.rs has the full list): wait , waitload [s], open , newtab , # page , shot , status , set , flyout , do , # cmd [arg], js