"""Boot a staged vpac image and test rejection, install and upgrade using the guest binary.""" import argparse import hashlib import os import shutil import subprocess import sys from pathlib import Path def run(args): work = args.work work.mkdir() arch = args.arch tests = Path(__file__).resolve().parent pin = args.fingerprint.read_text().strip() trust = work / "client-keys" repo = args.repo client = work / "client" image = work / "image" def log(name, argv, **options): with (work / (name + ".log")).open("x") as output: subprocess.run(argv, stdout=output, stderr=subprocess.STDOUT, check=True, **options) log("trust", ["feed", "trust", trust, repo / "test-signer.asc", pin]) log("install", ["feed", "install", trust, repo, arch, client, "--fakeroot", "vpac", "busybox-init", "vinix-keyring", "vinix-accounts", "vinix-filesystem"]) log("stage", [sys.executable, tests.parent / "tools/stage-image.py", arch, client, repo, image, args.auditor, pin]) # The updater receives a second complete signed index. Only its changed files # have to be added to the guest image alongside the first verified snapshot. root = image / "root" initial = root / "var/lib/vinix/repository" / arch old = initial / "ca-certificates-bundle-20261020-2-any.pkg.tar.zst" if not old.is_file() or not list(initial.glob("netbase-*.pkg.tar.zst")): raise ValueError("initial feed needs CA bundle release 2 and netbase") digest, filename = args.update_receipt.read_text().strip().split() if filename != "ca-certificates-bundle-20261020-3-any.pkg.tar.zst": raise ValueError("expected CA bundle release 3 in the update receipt") new = args.update_receipt.parent / filename with new.open("rb") as stream: if hashlib.file_digest(stream, "sha256").hexdigest() != digest: raise ValueError("update archive differs from its build receipt") update = work / "update" siblings = sorted(path for path in initial.glob("*.pkg.tar.zst") if path != old) log("publish-update", ["feed", "publish", args.keys, update, arch, new, *siblings]) delta = root / "var/lib/vinix/test-update" delta.mkdir() for base in ("vinix.db", "vinix.files", new.name): for name in (base, base + ".sig"): shutil.copyfile(update / arch / name, delta / name) fixture = work / "fixture.sh" fixture.write_bytes(f"VPAC_TEST_SCENARIO={args.scenario}\n".encode() + (tests / "userland/vpac.sh").read_bytes()) disk = work / "disk" env = os.environ.copy() env.setdefault("VINIX_QEMU_TIMEOUT", "720") log("boot", [sys.executable, tests / "disk-root.py", arch, root, fixture, args.iso, args.boot, disk], env=env) files = sorted(work.glob("*.log")) + [fixture, disk / "guest/serial.log", disk / "receipts.sha256"] with (work / "receipts.sha256").open("x") as report: for file in files: with file.open("rb") as stream: report.write(f"{hashlib.file_digest(stream, 'sha256').hexdigest()} {file.relative_to(work)}\n") if __name__ == "__main__": parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("arch", choices=("x86_64", "aarch64")) parser.add_argument("--scenario", choices=("all", "install", "upgrade"), default="all") for option in ("repo", "keys", "fingerprint", "update_receipt", "auditor", "boot", "iso", "work"): parser.add_argument(option, type=lambda path: Path(path).resolve()) run(parser.parse_args())