#!/usr/bin/env python3 """Per-app seed/verify fixtures for upgrade-test.py. THE ONE RULE, carried verbatim from survive2.py: *nothing is ever seeded into a volume by hand.* R-156's evidence shows a root-written canary making an empty volume read as populated — the exact confusion this harness exists to remove. So every seed below goes in through the app's OWN interface: its HTTP API, or its own CLI running inside its own container. A raw SQL INSERT or a planted file is NOT such a route and is never used. If an app has no non-browser route, its fixture returns None and the edge is recorded `inconclusive — no non-browser seed route`, with what was tried. **That is a result**: it tells us which apps can never be auto-verified, which is a fact nobody currently has. Each fixture returns an opaque `seeded` token from seed() and answers verify() with it. verify() must ask the APP, never the filesystem: a migration is supposed to rewrite files. """ import base64, json, re, secrets, subprocess, time def _sh(args, timeout=120, inp=None): try: return subprocess.run(args, capture_output=True, text=True, timeout=timeout, input=inp) except (subprocess.TimeoutExpired, OSError) as e: return subprocess.CompletedProcess(args, 124, "", f"{e}") def _curl(url, *extra, timeout=60, data=None, method=None): """One HTTP call. Gates on curl's OWN exit code, never on a summarising pipeline — the trap check-image-resolvable.py's docstring names and that has bitten this project twice.""" args = ["curl", "-sS", "--max-time", str(timeout), "-w", "\n%{http_code}"] if method: args += ["-X", method] if data is not None: args += ["--data-binary", "@-"] args += list(extra) + [url] r = _sh(args, timeout=timeout + 20, inp=data) body, _, code = (r.stdout or "").rpartition("\n") return r.returncode, code.strip(), body def _wait_http(url, want, tries=40, delay=5, say=print): """Settling says the container is running; this says the APP is answering. They are not the same thing, and conflating them is how "the container started" gets reported as a pass.""" for i in range(tries): rc, code, _ = _curl(url, timeout=15) if rc == 0 and code in want: return True time.sleep(delay) say(f" app never answered on {url} (last rc={rc} code={code})") return False # --------------------------------------------------------------------------------------------- class PrivateBin: """PrivateBin's own JSON API. A paste is an HTTP POST and reading it back is an HTTP GET — the app stores the blob and hands it back, which is an application-level round trip. PrivateBin is FILE-BACKED with no database, so this single seed IS the file half; there is no database half to seed separately. """ port = 8080 container = "privatebin" def _base(self, ipfn): ip = ipfn(self.container) return f"http://{ip}:{self.port}/" if ip else "" def seed(self, ipfn, say): base = self._base(ipfn) if not base: say(" privatebin: no container IP") return None if not _wait_http(base, {"200"}, say=say): return None marker = "upg-" + secrets.token_hex(8) # The v2 paste envelope. PrivateBin validates it server-side: `ct`, the IV and the salt must # all be real base64 or the API answers {"status":1,"message":"Invalid data."} — measured, # and the reason the first attempt at this fixture failed. The marker is carried INSIDE `ct` # so a readback proves THIS paste came back, not merely A paste. ct = base64.b64encode(marker.encode()).decode() body = json.dumps({ "v": 2, "adata": [[base64.b64encode(secrets.token_bytes(16)).decode(), base64.b64encode(secrets.token_bytes(8)).decode(), 100000, 256, 128, "aes", "gcm", "none"], "plaintext", 0, 0], "ct": ct, "meta": {"expire": "never"}, }) rc, code, out = _curl(base, "-H", "X-Requested-With: JSONHttpRequest", "-H", "Content-Type: application/json", data=body, method="POST") if rc != 0: say(f" privatebin: POST failed rc={rc}") return None try: j = json.loads(out) except Exception: say(f" privatebin: POST returned non-JSON (http {code}): {out[:200]}") return None if j.get("status") != 0 or not j.get("id"): say(f" privatebin: POST refused: {out[:250]}") return None say(f" privatebin: seeded paste id={j['id']}") return {"id": j["id"], "marker": ct} def verify(self, ipfn, seeded, say): base = self._base(ipfn) if not base: return False if not _wait_http(base, {"200"}, tries=24, say=say): return False rc, code, out = _curl(base + "?pasteid=" + seeded["id"], "-H", "X-Requested-With: JSONHttpRequest") if rc != 0 or code != "200": say(f" privatebin: readback rc={rc} http={code}") return False got = seeded["marker"] in out say(f" privatebin: readback http={code} marker_present={got}") return got # --------------------------------------------------------------------------------------------- class Docmost: """Docmost's own REST API: create the first workspace+user, then a page, then read it back.""" port = 3000 container = "docmost" def _base(self, ipfn): ip = ipfn(self.container) return f"http://{ip}:{self.port}" if ip else "" def seed(self, ipfn, say): base = self._base(ipfn) if not base: say(" docmost: no container IP") return None if not _wait_http(base + "/api/health", {"200", "404", "401"}, say=say): if not _wait_http(base + "/", {"200", "302", "404"}, tries=20, say=say): return None marker = "upg-" + secrets.token_hex(8) email = f"spike-{secrets.token_hex(4)}@gate.invalid" pw = "Spike-" + secrets.token_hex(10) setup = json.dumps({"workspaceName": "spike", "name": "spike", "email": email, "password": pw}) rc, code, out = _curl(base + "/api/auth/setup", "-H", "Content-Type: application/json", "-D", "/tmp/docmost.hdr", data=setup, method="POST") say(f" docmost: /api/auth/setup http={code} rc={rc}") if rc != 0 or code not in ("200", "201"): say(f" docmost: setup refused: {out[:250]}") return None tok = "" try: tok = json.loads(out).get("tokens", {}).get("accessToken", "") or json.loads(out).get("accessToken", "") except Exception: pass if not tok: m = re.search(r"authToken=([^;]+)", open("/tmp/docmost.hdr").read()) tok = m.group(1) if m else "" if not tok: say(" docmost: no auth token in the setup response") return None return {"marker": marker, "email": email, "pw": pw, "token": tok} def verify(self, ipfn, seeded, say): """Prove the app still holds the seeded ACCOUNT by asking it to authenticate — its own front door, and version-stable across the API churn between 0.25 and 0.95.""" base = self._base(ipfn) if not base: return False if not _wait_http(base + "/", {"200", "302", "404"}, tries=24, say=say): return False body = json.dumps({"email": seeded["email"], "password": seeded["pw"]}) rc, code, out = _curl(base + "/api/auth/login", "-H", "Content-Type: application/json", data=body, method="POST") ok = rc == 0 and code in ("200", "201") say(f" docmost: login as the seeded user http={code} ok={ok}") if not ok: say(f" docmost: login body {out[:200]}") return ok # --------------------------------------------------------------------------------------------- class BookStack: """BookStack has no API token without a browser, so BOTH the seed and the readback go through `php artisan` — BookStack's OWN CLI, running inside its own container against its own application code and its own User model. That is categorically different from a raw SQL INSERT or a planted file, which is what R-156 forbids. WHY NOT THE HTTP LOGIN FORM, which was the first attempt and is the more obvious choice: BookStack derives APP_URL from the template as `https://${SUBDOMAIN}.${DOMAIN}`, so it marks its session and XSRF cookies **`secure`**. curl over plain http therefore stores neither, sends neither, and every login POST comes back **419 Page Expired** — measured, and it looks exactly like a wrong password. The container serves no TLS, so there is no http route to a logged-in session without changing the app's own configuration, which would be testing a different app. WHY THE EXIT CODE IS NOT THE GATE HERE, stated because the standing rule says to use it: `bookstack:reset-mfa` asks for interactive confirmation, finds no TTY, and exits **1 in both cases** — for a user it FOUND and for one it did not. The exit code carries no information, so the discriminator is the output, and it is required to be positive AND the not-found sentence is required to be ABSENT. It is non-destructive: it aborts at the unanswered prompt. THE FIXTURE PROVES ITSELF ON EVERY CALL. Each verify() also probes an email that cannot exist and requires the "could not be found" answer. A readback that has broken into always saying "found" therefore fails instead of passing everything. LIMITATION, recorded rather than papered over: this seeds the DATABASE half only. Seeding a FILE (an uploaded image or attachment) needs the API token this app cannot mint headlessly. """ port = 80 container = "bookstack" def _base(self, ipfn): ip = ipfn(self.container) return f"http://{ip}:{self.port}" if ip else "" def _artisan(self, *args, timeout=180): for path in ("/app/www/artisan", "/var/www/html/artisan"): r = _sh(["docker", "exec", self.container, "php", path] + list(args), timeout=timeout) out = (r.stdout or "") + (r.stderr or "") if "Could not open input file" not in out: return r return r def _lookup(self, email): """Ask BookStack whether it holds this account. Returns True/False/None(unusable).""" r = self._artisan("bookstack:reset-mfa", f"--email={email}") out = " ".join(((r.stdout or "") + (r.stderr or "")).split()) found = f"Email: {email}" in out missing = "could not be found" in out if found == missing: # neither, or both — the readback itself is broken return None, out return found, out def seed(self, ipfn, say): base = self._base(ipfn) if not base: say(" bookstack: no container IP") return None if not _wait_http(base + "/login", {"200"}, tries=60, say=say): return None email = f"spike-{secrets.token_hex(4)}@gate.invalid" pw = "Spike-" + secrets.token_hex(10) r = self._artisan("bookstack:create-admin", f"--email={email}", f"--name=spike-{secrets.token_hex(3)}", f"--password={pw}") out = " ".join(((r.stdout or "") + (r.stderr or "")).split()) say(f" bookstack: artisan create-admin rc={r.returncode} :: {out[:120]}") if "successfully created" not in out: return None return {"email": email, "pw": pw} def verify(self, ipfn, seeded, say): base = self._base(ipfn) if not base: return False # The app must be SERVING, not merely running — "the container started" is not a pass. if not _wait_http(base + "/login", {"200"}, tries=60, say=say): say(" bookstack: the app never served /login") return False # The fixture's own negative control, run every time. absent, _ = self._lookup(f"nobody-{secrets.token_hex(6)}@gate.invalid") if absent is not False: say(f" bookstack: READBACK IS UNUSABLE — an email that cannot exist did not read as absent ({absent})") return False found, out = self._lookup(seeded["email"]) say(f" bookstack: readback of the seeded account found={found} :: {out[:120]}") return found is True # --------------------------------------------------------------------------------------------- # Added 2026-09-21 by the update night (R-462's widening). Each of these was written and PROVEN # box-side first, on guest 9202 through the product's own guarded Update, and then ported here so # the same edge can be run on the harness venue with its ABORT step. The box-side evidence is # `felhom.eu/documentation/audits/update-night-2026-09-21/apps//`. # # The port is mechanical and one thing changes: box-side the app is reached through traefik with a # `Host:` header, here through the container's own IP. The SEED ROUTE is identical, and that is the # expensive half. # --------------------------------------------------------------------------------------------- class ActualBudget: """Actual's own bootstrap API sets the server password; its own login proves it survived. Actual keeps its data in SQLite inside its own volume and performs its own schema migration on start, so this single seed is the whole data half. """ port = 5006 container = "actualbudget" def _base(self, ipfn): ip = ipfn(self.container) return f"http://{ip}:{self.port}" if ip else "" def seed(self, ipfn, say): base = self._base(ipfn) if not base or not _wait_http(base + "/", {"200", "302"}, say=say): say(" actualbudget: no container IP, or the app never answered") return None pw = "Spike-" + secrets.token_hex(10) rc, code, out = _curl(base + "/account/bootstrap", "-H", "Content-Type: application/json", data=json.dumps({"password": pw}), method="POST") say(f" actualbudget: /account/bootstrap http={code} :: {out[:140]}") if rc != 0 or '"status":"ok"' not in out: return None return {"pw": pw} def verify(self, ipfn, seeded, say): base = self._base(ipfn) if not base or not _wait_http(base + "/", {"200", "302"}, tries=24, say=say): return False def login(p): return _curl(base + "/account/login", "-H", "Content-Type: application/json", data=json.dumps({"loginMethod": "password", "password": p}), method="POST") # the fixture's own negative control, run on every verify rc, code, out = login("wrong-" + secrets.token_hex(6)) if '"status":"ok"' in out: say(" actualbudget: READBACK IS UNUSABLE — a wrong password authenticated") return False rc, code, out = login(seeded["pw"]) ok = '"status":"ok"' in out say(f" actualbudget: login with the seeded password http={code} ok={ok}") return ok class Navidrome: """Navidrome's own /auth/createAdmin makes the first account; its own /auth/login proves it survived. LIMITATION: this is the DATABASE half. Navidrome's other half is the music library on the drive, which the harness does not populate.""" port = 4533 container = "navidrome" def _base(self, ipfn): ip = ipfn(self.container) return f"http://{ip}:{self.port}" if ip else "" def seed(self, ipfn, say): base = self._base(ipfn) if not base or not _wait_http(base + "/", {"200", "302"}, say=say): say(" navidrome: no container IP, or the app never answered") return None user = "spike" + secrets.token_hex(3) pw = "Spike-" + secrets.token_hex(10) rc, code, out = _curl(base + "/auth/createAdmin", "-H", "Content-Type: application/json", data=json.dumps({"username": user, "password": pw}), method="POST") say(f" navidrome: createAdmin http={code}") if rc != 0 or code not in ("200", "201"): say(f" navidrome: refused {out[:200]}") return None return {"user": user, "pw": pw} def verify(self, ipfn, seeded, say): base = self._base(ipfn) if not base or not _wait_http(base + "/", {"200", "302"}, tries=24, say=say): return False def login(p): return _curl(base + "/auth/login", "-H", "Content-Type: application/json", data=json.dumps({"username": seeded["user"], "password": p}), method="POST") rc, code, _ = login("wrong-" + secrets.token_hex(6)) if code in ("200", "201"): say(" navidrome: READBACK IS UNUSABLE — a wrong password authenticated") return False rc, code, out = login(seeded["pw"]) ok = code in ("200", "201") say(f" navidrome: login as the seeded user http={code} ok={ok}") return ok class AudiobookShelf: """audiobookshelf's own /init creates the first root account; its own /login proves it survived. LIMITATION: the DATABASE half only — the library on the drive is not populated.""" port = 80 container = "audiobookshelf" def _base(self, ipfn): ip = ipfn(self.container) return f"http://{ip}:{self.port}" if ip else "" def seed(self, ipfn, say): base = self._base(ipfn) if not base or not _wait_http(base + "/status", {"200"}, say=say): say(" audiobookshelf: no container IP, or the app never answered /status") return None user = "spike" + secrets.token_hex(3) pw = "Spike-" + secrets.token_hex(10) rc, code, out = _curl(base + "/init", "-H", "Content-Type: application/json", data=json.dumps({"newRoot": {"username": user, "password": pw}}), method="POST") say(f" audiobookshelf: /init http={code}") if rc != 0 or code not in ("200", "204"): say(f" audiobookshelf: refused {out[:200]}") return None return {"user": user, "pw": pw} def verify(self, ipfn, seeded, say): base = self._base(ipfn) if not base or not _wait_http(base + "/status", {"200"}, tries=24, say=say): return False def login(p): return _curl(base + "/login", "-H", "Content-Type: application/json", data=json.dumps({"username": seeded["user"], "password": p}), method="POST") rc, code, _ = login("wrong-" + secrets.token_hex(6)) if code == "200": say(" audiobookshelf: READBACK IS UNUSABLE — a wrong password authenticated") return False rc, code, out = login(seeded["pw"]) ok = code == "200" and seeded["user"] in out say(f" audiobookshelf: login as the seeded root http={code} ok={ok}") return ok class Vikunja: """Vikunja's own REST API: register, log in, create a project, read the project back. Four calls, all the app's own front door, and the readback is a real authenticated GET.""" port = 3456 container = "vikunja" def _base(self, ipfn): ip = ipfn(self.container) return f"http://{ip}:{self.port}" if ip else "" def _token(self, base, seeded, pw=None): rc, code, out = _curl(base + "/api/v1/login", "-H", "Content-Type: application/json", data=json.dumps({"username": seeded["user"], "password": pw or seeded["pw"]}), method="POST") if code != "200": return None try: return json.loads(out)["token"] except Exception: return None def seed(self, ipfn, say): base = self._base(ipfn) if not base or not _wait_http(base + "/api/v1/info", {"200"}, say=say): say(" vikunja: no container IP, or the app never answered /api/v1/info") return None user = "spike" + secrets.token_hex(3) pw = "Spike-" + secrets.token_hex(10) rc, code, out = _curl(base + "/api/v1/register", "-H", "Content-Type: application/json", data=json.dumps({"username": user, "password": pw, "email": f"{user}@gate.invalid"}), method="POST") say(f" vikunja: register http={code}") if code not in ("200", "201"): say(f" vikunja: refused {out[:200]}") return None seeded = {"user": user, "pw": pw} tok = self._token(base, seeded) if not tok: say(" vikunja: could not log in after registering") return None title = "spike-" + secrets.token_hex(5) # Vikunja CREATES with PUT, not POST — a POST answers `405 Method Not Allowed`, which # reads like a broken fixture and is really the wrong verb. Measured 2026-09-21. rc, code, out = _curl(base + "/api/v1/projects", "-H", f"Authorization: Bearer {tok}", "-H", "Content-Type: application/json", data=json.dumps({"title": title}), method="PUT") say(f" vikunja: create project http={code}") if code not in ("200", "201"): say(f" vikunja: project refused {out[:200]}") return None seeded["title"] = title seeded["pid"] = json.loads(out).get("id") return seeded def verify(self, ipfn, seeded, say): base = self._base(ipfn) if not base or not _wait_http(base + "/api/v1/info", {"200"}, tries=24, say=say): return False if self._token(base, seeded, pw="wrong-" + secrets.token_hex(6)): say(" vikunja: READBACK IS UNUSABLE — a wrong password authenticated") return False tok = self._token(base, seeded) if not tok: say(" vikunja: the seeded account no longer authenticates") return False rc, code, out = _curl(base + f"/api/v1/projects/{seeded['pid']}", "-H", f"Authorization: Bearer {tok}") ok = code == "200" and seeded["title"] in out say(f" vikunja: readback of the seeded project http={code} ok={ok}") return ok # --------------------------------------------------------------------------------------------- class Romm: """RomM's own user API, driven the way RomM's own front end drives it (added 2026-09-23 for the memory watch's red-proof, R-635). Ported from the box-side fixture that walked the 5.0.0 -> 5.3.0 edge on guest 9202 on 2026-09-21, where each of these was measured rather than guessed: - RomM sets a `romm_csrftoken` cookie on any GET and requires it back as an `x-csrftoken` header; a bare POST is `403 CSRF token verification failed`, which reads like an auth fault. - The fields go in the JSON BODY; a query-string POST is `422 Field required`. - The first `POST /api/users` on a fresh install is accepted unauthenticated; afterwards it is not — which is what makes `POST /api/login` as that user a real authentication. LIMITATION: the DATABASE half only. RomM's other half is the ROM library on the drive. """ port = 8080 container = "romm" def _base(self, ipfn): ip = ipfn(self.container) return f"http://{ip}:{self.port}" if ip else "" def _csrf(self, base): jar = f"/tmp/romm-{secrets.token_hex(4)}.jar" _curl(base + "/api/heartbeat", "-c", jar) tok = "" try: for line in open(jar): if "csrf" in line.lower(): tok = line.split()[-1] except OSError: pass return jar, tok def seed(self, ipfn, say): base = self._base(ipfn) if not base or not _wait_http(base + "/api/heartbeat", {"200"}, tries=72, say=say): say(" romm: no container IP, or the app never answered /api/heartbeat") return None jar, tok = self._csrf(base) if not tok: say(" romm: no romm_csrftoken cookie was set on /api/heartbeat") return None user = "spike" + secrets.token_hex(3) pw = "Spike-" + secrets.token_hex(10) rc, code, out = _curl(base + "/api/users", "-b", jar, "-H", f"x-csrftoken: {tok}", "-H", "Content-Type: application/json", data=json.dumps({"username": user, "email": f"{user}@gate.invalid", "password": pw, "role": "admin"}), method="POST") say(f" romm: POST /api/users http={code}") if code not in ("200", "201"): say(f" romm: refused {out[:200]}") return None return {"user": user, "pw": pw} def verify(self, ipfn, seeded, say): base = self._base(ipfn) if not base or not _wait_http(base + "/api/heartbeat", {"200"}, tries=36, say=say): return False jar, tok = self._csrf(base) rc, code, _ = _curl(base + "/api/login", "-b", jar, "-H", f"x-csrftoken: {tok}", "-u", f"{seeded['user']}:wrong-{secrets.token_hex(5)}", method="POST") if code == "200": say(" romm: READBACK IS UNUSABLE — a wrong password authenticated") return False rc, code, out = _curl(base + "/api/login", "-b", jar, "-H", f"x-csrftoken: {tok}", "-u", f"{seeded['user']}:{seeded['pw']}", method="POST") ok = code == "200" say(f" romm: login as the seeded user http={code} ok={ok}") return ok class QBittorrent: """qBittorrent's own WebAPI makes a category and adds a torrent; the same API proves both survived. The admin password is read from the container's OWN environment - it is the value the deploy handed the app, not a planted one, and it never leaves the container. Why a category AND a torrent: the category lives in the config store, the torrent in the resume data (BT_backup/*.fastresume). An upgrade that loses either loses something a household notices. No bytes need to move: a magnet is in the list the moment it is accepted.""" port = 8080 container = "qbittorrent" # Big Buck Bunny (Blender Foundation, CC BY) - a hash that exists, so nothing here is made up MAGNET = ("magnet:?xt=urn:btih:dd8255ecdc7ca55fb0bbf81323d87062db1f6d1c&dn=Big+Buck+Bunny") def _in(self, args, timeout=60): return _sh(["docker", "exec", self.container, "sh", "-c", args], timeout=timeout) def _api(self, path, *curl_extra, body=None): """One call to the app's own API from inside its container, with its own credentials.""" q = " ".join(curl_extra) data = f"--data-binary '{body}'" if body else "" cmd = ( 'curl -s -c /tmp/fxck -o /dev/null -X POST ' '-d "username=admin&password=$QBT_ADMIN_PASSWORD" ' '-H "Referer: http://127.0.0.1:8080" http://127.0.0.1:8080/api/v2/auth/login; ' f'curl -s -b /tmp/fxck -w "\n%{{http_code}}" -H "Referer: http://127.0.0.1:8080" ' f'{q} {data} http://127.0.0.1:8080{path}' ) r = self._in(cmd) out = r.stdout or "" body_, _, code = out.rpartition("\n") return r.returncode, code.strip(), body_ def seed(self, ipfn, say): cat = "felhom" + secrets.token_hex(4) rc, code, out = self._api("/api/v2/torrents/createCategory", f'-d "category={cat}"') say(f" qbittorrent: createCategory {cat} http={code}") if rc != 0 or code != "200": say(f" qbittorrent: the app refused the category ({out[:160]})") return None rc, code, out = self._api("/api/v2/torrents/add", f'-F "urls={self.MAGNET}" -F "category={cat}"') say(f" qbittorrent: torrents/add http={code}") if rc != 0 or code != "200": say(f" qbittorrent: the app refused the torrent ({out[:160]})") return None return {"category": cat, "hash": "dd8255ecdc7ca55fb0bbf81323d87062db1f6d1c"} def verify(self, ipfn, seeded, say): rc, code, out = self._api("/api/v2/torrents/categories", "-X GET") if rc != 0 or code != "200": say(f" qbittorrent: the app would not list categories (http={code})") return False # negative control first: a name that was never created must be absent ghost = "felhom" + secrets.token_hex(4) if ghost in out: say(" qbittorrent: READBACK IS UNUSABLE - a category nobody created is present") return False if seeded["category"] not in out: say(f" qbittorrent: the seeded category {seeded['category']} is GONE") return False rc, code, out = self._api("/api/v2/torrents/info", "-X GET") ok = rc == 0 and code == "200" and seeded["hash"] in out say(f" qbittorrent: category kept, torrent present={ok}") return ok class Transmission: """Transmission's own RPC sets a distinctive speed limit and adds a torrent; the same RPC proves both survived. The password comes from the container's own PASS variable. The CSRF token (X-Transmission-Session-Id) is taken the way every client takes it: from the 409 the first call answers.""" port = 9091 container = "transmission" MAGNET = ("magnet:?xt=urn:btih:dd8255ecdc7ca55fb0bbf81323d87062db1f6d1c&dn=Big+Buck+Bunny") def _rpc(self, payload, timeout=60): """One RPC call, with the payload on STDIN and the session id taken by an anchored sed. Measured on the bench 2026-10-12: an `awk "/Session-Id/ {print $2}"` over the headers picks up the header NAME from a later line too, so the id goes out as two values joined and Transmission answers 400 to every call - which reads exactly like "the app has no API".""" script = ( 'SID=$(curl -s -u "admin:$PASS" -D - -o /dev/null ' 'http://127.0.0.1:9091/transmission/rpc | tr -d "\\r" ' "| sed -n 's/^[Xx]-[Tt]ransmission-[Ss]ession-[Ii]d: //p')\n" 'curl -s -u "admin:$PASS" -H "X-Transmission-Session-Id: $SID" ' "-w '\\n%{http_code}' -d @- http://127.0.0.1:9091/transmission/rpc <<'FELHOMJSON'\n" + payload + "\nFELHOMJSON\n" ) r = _sh(["docker", "exec", "-i", self.container, "sh", "-s"], timeout=timeout, inp=script) out = r.stdout or "" body, _, code = out.rpartition("\n") return r.returncode, code.strip(), body def seed(self, ipfn, say): limit = 300 + secrets.randbelow(600) # a number nothing else would choose rc, code, out = self._rpc('{"method":"session-set","arguments":' '{"speed-limit-down":%d,"speed-limit-down-enabled":true}}' % limit) say(f" transmission: session-set speed-limit-down={limit} http={code}") if rc != 0 or code != "200" or '"success"' not in out: say(f" transmission: the app refused the setting ({out[:160]})") return None rc, code, out = self._rpc('{"method":"torrent-add","arguments":{"filename":"%s"}}' % self.MAGNET) ok = rc == 0 and code == "200" and '"success"' in out say(f" transmission: torrent-add http={code} ok={ok}") if not ok: say(f" transmission: {out[:160]}") return None return {"limit": limit, "hash": "dd8255ecdc7ca55fb0bbf81323d87062db1f6d1c"} def verify(self, ipfn, seeded, say): rc, code, out = self._rpc('{"method":"session-get","arguments":' '{"fields":["speed-limit-down","speed-limit-down-enabled"]}}') if rc != 0 or code != "200": say(f" transmission: the app would not answer session-get (http={code})") return False want = '"speed-limit-down":%d' % seeded["limit"] ghost = '"speed-limit-down":%d' % (seeded["limit"] + 1) if ghost in out: say(" transmission: READBACK IS UNUSABLE - the app reports a limit nobody set") return False if want not in out: say(f" transmission: the seeded limit {seeded['limit']} is GONE ({out[:160]})") return False rc, code, out = self._rpc('{"method":"torrent-get","arguments":{"fields":["hashString"]}}') ok = rc == 0 and code == "200" and seeded["hash"] in out say(f" transmission: limit kept, torrent present={ok}") return ok # The NZB both Usenet fixtures seed with. It names articles that do not exist, which is exactly # right: without a paid provider nothing can be fetched anyway, and what the fixture is measuring is # the QUEUE - the store an upgrade must not lose. Nothing here downloads a byte. FELHOM_NZB = ( '\n' '\n' '%(name)s\n' '\n' 'alt.binaries.test\n' '%(name)s-1@example.invalid\n' '\n\n' ) class SABnzbd: """SABnzbd's own API queues an NZB and creates a category; the same API proves both survived. Two stores, because they are different files: the queue index lives in /config/admin (queue10.sab, history1.db) and the category in sabnzbd.ini. An upgrade that loses either loses something the household set. The API key is read from the container's OWN environment - it is the value the deploy handed the app. No Usenet provider is configured and none is needed: the job sits in the queue unfetchable, which is what is being measured. What CANNOT be measured this way, and is not claimed anywhere, is the download chain itself (connect, par2 repair, unpack).""" port = 8080 container = "sabnzbd" def _api(self, query, timeout=60, extra=""): """One call to the app's own API from inside its container, with its own key.""" cmd = ('curl -s -w "\\n%{http_code}" ' + extra + ' "http://127.0.0.1:8080/api?output=json&apikey=$SAB_API_KEY&' + query + '"') r = _sh(["docker", "exec", self.container, "sh", "-c", cmd], timeout=timeout) out = r.stdout or "" body_, _, code = out.rpartition("\n") return r.returncode, code.strip(), body_ def seed(self, ipfn, say): name = "felhom" + secrets.token_hex(4) # the NZB goes in through the app's own upload endpoint, written inside the container script = ("cat > /tmp/%s.nzb <<'FELHOMNZB'\n%s\nFELHOMNZB\n" % (name, FELHOM_NZB % {"name": name})) script += ('curl -s -w "\\n%{http_code}" -F "name=@/tmp/' + name + '.nzb" ' '-F "nzbname=' + name + '" ' '"http://127.0.0.1:8080/api?mode=addfile&output=json&apikey=$SAB_API_KEY"' + "\n") r = _sh(["docker", "exec", "-i", self.container, "sh", "-s"], timeout=90, inp=script) out = (r.stdout or "") body_, _, code = out.rpartition("\n") ok = r.returncode == 0 and code.strip() == "200" and '"status": true' in body_.replace('"status":true', '"status": true') say(f" sabnzbd: addfile {name} http={code.strip()} ok={ok}") if not ok: say(f" sabnzbd: the app refused the NZB ({body_[:160]})") return None rc, code, out = self._api("mode=set_config§ion=categories&keyword=%s&name=%s&dir=%s" % (name, name, name)) if rc != 0 or code != "200": say(f" sabnzbd: the app refused the category (http={code}, {out[:160]})") return None say(f" sabnzbd: category {name} created") return {"name": name} def verify(self, ipfn, seeded, say): name = seeded["name"] rc, code, out = self._api("mode=queue") if rc != 0 or code != "200": say(f" sabnzbd: the app would not answer mode=queue (http={code})") return False ghost = "felhom" + secrets.token_hex(4) if ghost in out: say(" sabnzbd: READBACK IS UNUSABLE - a job nobody queued is present") return False if name not in out: say(f" sabnzbd: the queued job {name} is GONE ({out[:200]})") return False rc, code, out = self._api("mode=get_config§ion=categories") ok = rc == 0 and code == "200" and name in out say(f" sabnzbd: job kept, category present={ok}") return ok class NZBGet: """NZBGet's own JSON-RPC queues an NZB (paused) and the same RPC proves it survived. The queue lives in the config volume because this template moves MainDir there - the app ships with MainDir=/downloads, which would put the queue on the household's drive, the one place the backup classification calls "optional, fetchable again" (measured on the bench 2026-10-12). THE CALLS COME FROM THE HARNESS HOST, at the container's own IP. This image carries no curl - only busybox wget, python3 and openssl - so a call from inside produced nothing and the harness read that as "no seed route", twice, before this was measured. The password is still the app's own: read out of the container's environment with printenv, which busybox does have. No Usenet provider is configured and none is needed; the download chain itself is therefore NOT measured, and no record claims it is.""" port = 6789 container = "nzbget" def _pw(self): r = _sh(["docker", "exec", self.container, "printenv", "NZBGET_PASS"], timeout=30) return (r.stdout or "").strip() def _base(self, ipfn): ip = ipfn(self.container) return f"http://{ip}:{self.port}" if ip else "" def _rpc(self, base, pw, payload=None, path="", timeout=60): url = f"{base}/jsonrpc" + (f"/{path}" if path else "") extra = ["-u", f"admin:{pw}"] if payload is not None: extra += ["-H", "Content-Type: application/json"] return _curl(url, *extra, data=payload, timeout=timeout) def seed(self, ipfn, say): base, pw = self._base(ipfn), self._pw() if not base or not pw: say(f" nzbget: no container IP ({bool(base)}) or no password in its environment ({bool(pw)})") return None if not _wait_http(base + "/", {"200", "401"}, say=say): return None name = "felhom" + secrets.token_hex(4) nzb = FELHOM_NZB % {"name": name} payload = json.dumps({"method": "append", "params": [name + ".nzb", base64.b64encode(nzb.encode()).decode(), "", 0, False, True, "", 0, "SCORE", []], "id": 1}) rc, code, out = self._rpc(base, pw, payload=payload) # the app answers the new NZBID on success and -1 on failure ok = rc == 0 and code == "200" and '"result" : -1' not in out and '"result":-1' not in out say(f" nzbget: append {name} http={code} ok={ok}") if not ok: say(f" nzbget: the app refused the NZB ({out[:200]})") return None return {"name": name} def verify(self, ipfn, seeded, say): base, pw = self._base(ipfn), self._pw() if not base or not pw: say(" nzbget: the app's IP or password is not readable after the step") return False if not _wait_http(base + "/", {"200", "401"}, say=say): return False name = seeded["name"] rc, code, out = self._rpc(base, pw, path="listgroups") if rc != 0 or code != "200": say(f" nzbget: the app would not answer listgroups (http={code})") return False ghost = "felhom" + secrets.token_hex(4) if ghost in out: say(" nzbget: READBACK IS UNUSABLE - a job nobody queued is present") return False if name not in out: say(f" nzbget: the queued job {name} is GONE ({out[:200]})") return False # and the nzb file the app saved for it, in the config volume this template moved it to r = _sh(["docker", "exec", self.container, "sh", "-c", "ls /config/data/nzb"], timeout=30) kept = name in (r.stdout or "") say(f" nzbget: the queued job is present, its saved nzb file present={kept}") return True class Plex: """Plex's own HTTP API makes a library section and the same API proves it survived (felhom.eu R-1238). NO plex.tv ACCOUNT. An UNCLAIMED Plex answers a request from a private address with no token (felhom.eu `architecture/13-threat-model.md`, the R-1045 row) - the harness calls from the bench host at the container's own IP, so the caller is the docker bridge gateway (172.x.0.1), a private address. Measured on the bench 2026-10-28 night (felhom.eu audits/night-2026-10-28/bench/plex/): POST /library/sections answered 201 with the new section; GET read it back before and after 1.41.4.9463 -> 1.43.5.11029, with PLEX_CLAIM absent AND with a junk PLEX_CLAIM (the image's first-run claim exchange fails and the server stays unclaimed). A CLAIMED server would answer 401 to this route - seed() then records why and returns None, it never reads that as "no data". The server says it is ready only when /identity carries no `startState`: the healthcheck (curl -f /identity) is healthy while `startState` is `startingPlugins`, and a POST then answers 400 "the server is still starting up" (measured, the first spike attempt). JSON only with `Accept: application/json` - XML otherwise. What is proven: the section (its name, uuid and folder) lives in Plex's own database in the config volume. No media is scanned; the scanner and the metadata agents are NOT measured, and no record claims they are.""" port = 32400 container = "plex" J = ("-H", "Accept: application/json") def _base(self, ipfn): ip = ipfn(self.container) return f"http://{ip}:{self.port}" if ip else "" def _ready(self, base, say, tries=90, delay=4): """(True, identity) once /identity answers 200 JSON with no startState; (False, last answer) otherwise.""" last = "" for _ in range(tries): rc, code, out = _curl(base + "/identity", *self.J, timeout=15) last = f"rc={rc} http={code} {out[:160]}" if rc == 0 and code == "200": try: mc = json.loads(out).get("MediaContainer") or {} except ValueError: mc = {} if "claimed" in mc and "startState" not in mc: return True, mc time.sleep(delay) say(f" plex: never finished starting ({last})") return False, None def _sections(self, base): rc, code, out = _curl(base + "/library/sections", *self.J, timeout=30) if rc != 0 or code != "200": return None, f"rc={rc} http={code} {out[:160]}" try: return (json.loads(out).get("MediaContainer") or {}).get("Directory") or [], out except ValueError: return None, f"non-JSON http={code} {out[:160]}" def seed(self, ipfn, say): base = self._base(ipfn) if not base: say(" plex: no container IP") return None ok, ident = self._ready(base, say) if not ok: return None if ident.get("claimed") is not False: self.tried = "the unclaimed private-address route: the server reports claimed=%r" % ident.get("claimed") say(f" plex: {self.tried} - this route needs an UNCLAIMED server") return None name = "felhom" + secrets.token_hex(4) q = ("name=%s&type=movie&agent=tv.plex.agents.movie&scanner=Plex%%20Movie&language=en-US&location=%%2Fmedia" % name) rc, code, out = _curl(base + "/library/sections?" + q, *self.J, method="POST", timeout=60) say(f" plex: POST /library/sections {name} http={code} (server {ident.get('version')}, claimed=false)") if rc != 0 or code not in ("200", "201"): self.tried = f"POST /library/sections answered rc={rc} http={code}: {out[:160]}" say(f" plex: the app refused the section ({out[:160]})") return None try: made = [d for d in (json.loads(out).get("MediaContainer") or {}).get("Directory") or [] if d.get("title") == name] except ValueError: made = [] if not made or not made[0].get("uuid"): say(f" plex: the create answer does not carry the section ({out[:160]})") return None say(f" plex: seeded library section {name} key={made[0].get('key')} uuid={made[0]['uuid']}") return {"name": name, "uuid": made[0]["uuid"]} def verify(self, ipfn, seeded, say): base = self._base(ipfn) if not base: return False ok, ident = self._ready(base, say) if not ok: return False secs, out = self._sections(base) if secs is None: say(f" plex: the app would not list its sections ({out})") return False # negative control first: a name nobody created must be absent ghost = "felhom" + secrets.token_hex(4) if any(d.get("title") == ghost for d in secs) or ghost in out: say(" plex: READBACK IS UNUSABLE - a section nobody created is present") return False hit = [d for d in secs if d.get("title") == seeded["name"]] if not hit: say(f" plex: the seeded section {seeded['name']} is GONE ({len(secs)} section(s) listed)") return False same = hit[0].get("uuid") == seeded["uuid"] locs = [l.get("path") for l in hit[0].get("Location") or []] say(f" plex: section {seeded['name']} read back (server {ident.get('version')}), same uuid={same}, folders={locs}") return same and "/media" in locs FIXTURES = { "privatebin": PrivateBin(), "docmost": Docmost(), "bookstack": BookStack(), "actualbudget": ActualBudget(), "navidrome": Navidrome(), "audiobookshelf": AudiobookShelf(), "vikunja": Vikunja(), "romm": Romm(), "qbittorrent": QBittorrent(), "transmission": Transmission(), "sabnzbd": SABnzbd(), "nzbget": NZBGet(), "plex": Plex(), }