C12 - Install and Downloads
Purpose: The test cases for installing and upgrading Wraith Box:
wb-download, wb-release-check, the checks wb-hostd makes on what it fetches,
wb setup, and the migrations of state.db and configuration.
Unit tests
Section titled “Unit tests”wb-download
Section titled “wb-download”-
Self-check (S17-03-downloadsS17-03-downloads: DownloadsHow wb-download fetches what an image build needs from the internet.). Confined,
wb-downloadfails to open a file under the home directory, to connect to TCP port 80 and to UDP port 123, and to run/bin/echo. It can connect to port 443 and lists the host’s interfaces withgetifaddrs(TestConfinedincmd/wb-download). It completes a TLS fetch of the channel file on port 443 against the system roots (TestLiveChannel, which needs the internet and runs only withWB_DOWNLOAD_LIVE_TEST=1). The child’s file size limit is the entry’s, soft and hard, and it can’t raise it (TestConfined). -
Self-check, not yet covered. Confined,
wb-downloadfails to reach the Keychain services. The profile allows nomach-lookupbuttrustd’s, so a Keychain call has no service to reach. No probe makes one yet: Go’s standard library calls the Security framework only to check a server’s certificate, throughtrustd, whichTestLiveChannelcovers. A probe needs a Keychain call such asSecItemCopyMatchingthrough cgo. -
Start. An argument, an unknown entry, a program outside a bundle, a file size limit it can’t set, and each descriptor set outside the start interface are refused with their rules (
TestChildStartRefusals,TestChildDescriptors,TestChildLogRefused,TestCheckStart,TestBundlePath). So is a Claude Code output that isn’t empty (TestServeClaudeOutputNotEmpty). A peer of another build version doesn’t get an end record (TestChildVersionRefused,TestServeVersionMismatch). A child that set its limit can’t write past it or raise it (TestSetStopsWritesininternal/platform/filelimit). -
Deny tests. Through a local test server and a fake resolver, feed it each of these, and see each refused with its rule and a refused 4002 record that names it:
- a host outside its entry, and plain HTTP (
download-host-refused); - a redirect (
download-redirect-refused); - a name that resolves to a private address, and a failure to list
the host’s interfaces (
upstream-address-refused); - a server that doesn’t accept the connection
(
download-connect-timeout), one that stops sending (download-idle-timeout), and one that sends past the request’s deadline (download-deadline); - a closed request pipe (
download-cancelled); - a
200to a range request, and a206with anotherContent-Range(download-range-refused); - a short body (
download-short); - a manifest of 1 MiB and one byte (
download-too-large).
The tests are the
TestC12Downloadones ininternal/download. - a host outside its entry, and plain HTTP (
-
Bounds. A body longer than the size is written only up to the size. A write past the entry’s file size limit fails.
-
Proxy. A run with
HTTPS_PROXYset to a local proxy sees the proxy get no connection (TestC12DownloadProxyUnused). -
Runs. A restore run from offset 0, from a partial file, and from a whole one, which sends no
GET. An offset above the size or other than the partial file’s, a request out of order, and a second request are refused withdownload-request-invalid. A channel run and a release run each fill their files (TestServeininternal/download). -
Remote input in a run. A catalog whose image URL names another host, an IP address, a port, a user, or plain HTTP ends the run with
download-catalog-invalid, and no request reaches the image host (TestServeHostileFirmwareURL). A status of600and a response that isn’t HTTP end it withdownload-response-invalid, and failed lookups and connects withupstream-resolve-failedandupstream-connect-failed. Each request is still reported (TestServeRemoteFailures). A catalog error that quotes a megabyte of the catalog is logged bounded (TestServeCatalogErrorBounded), and each restore image left out is logged with its reason (TestParseLeavesOut).
wb-release-check
Section titled “wb-release-check”-
Self-check (S04-05-helper-programsS04-05-helper-programs: Helper ProgramsThe programs that run once for an image build or a store operation: wb-guestadmin, wb-release-check, wb-download and wb-build-ssh., “
wb-release-check”). Confined,wb-release-checkreads its four descriptors and writes a pass record. Its probes then fail to open a file under the home directory or to connect to TCP port 443. Running/bin/echofails too (TestConfinedincmd/wb-release-check). It reads each release file from offset 0, wherever the shared offset is (TestConfined,TestFromStart). -
Start. An argument is refused before confinement (
TestArguments). Each descriptor set outside the start interface is refused withrelease-check-descriptor-invalidafter the deny probe, and the child exits without a record (TestDescriptorRefused,TestLogRefused). Those include an unconnected socket and one whose peer closed, for the channel. A peer of another build version doesn’t get a record (TestVersionRefused). A release key that doesn’t parse refuses the start withrelease-check-key-invalidand no record (TestKeyRefused). A host end closed after the request leaves the record unwritten, logged withrelease-check-record-failed(TestRecordFailed). Each exits 1. A failed check and a request outside the form write the fail record of their rule (TestFailRecords). -
Deny tests (S14-01-installS14-01-install: InstallHow the image build downloads Claude Code on the host, checks it, and installs it in the guest image, and which version a guest runs., “Check”). With a test key, feed the check each of these, and see each refused with its rule:
- a changed manifest byte, a signature by another key, another key
naming the release key’s fingerprint, a v3 signature, a text
signature, two signature packets, and a signature over 64 KiB
(
claude-release-signature-invalid); - an older version under a newer request, and the reverse
(
claude-release-version-mismatch); - versions 2.1.288 and 2.0.999 (
claude-release-below-minimum); - no
darwin-arm64entry (claude-release-no-platform); - another binary name (
claude-release-binary-name); - a short binary, a long one, and another checksum
(
claude-release-binary-mismatch); - a signed manifest that isn’t JSON, and one over 1 MiB
(
claude-release-manifest-invalid); - a request outside the version form
(
release-check-request-invalid).
The test is
TestC12ReleaseCheckininternal/releasecheck. - a changed manifest byte, a signature by another key, another key
naming the release key’s fingerprint, a v3 signature, a text
signature, two signature packets, and a signature over 64 KiB
(
-
The real release. The signed manifest of Claude Code 2.1.311 and its signature, in
internal/releasecheck/testdata, verify with the compiled-in key. A stand-in binary then fails the size check, a changed size fails the signature, and the test key refuses the signature (TestRealRelease). -
Parsers. The manifest parser refuses duplicate keys at each level it reads, values of the wrong type, and checksums and sizes outside their form (
TestParseManifest). The OpenPGP subset refuses each armor, packet, and subpacket outside its one form, including a bare CR in the armor’s body (TestDearmor,TestParseSignatureRefusals,TestParsePublicKeyandTestVerifyRefusalsininternal/releasecheck/pgpsig). The record and request readers refuse each line outside their form, and every record fits inMaxRecord(TestParseRecordRefusals,TestRecordBound,TestRequestininternal/releasecheck/record). The one version form refuses a leading zero and a number with too many digits (TestParseVersion), andwb-download’s request check uses it. -
The agent. The compiled-in key’s fingerprint is
31DD DE24 DDFA B679 F42D 7BD2 BAA9 29FF 1A7E CACE(TestReleaseKeyFingerprintininternal/agent/claude). The guest instructions file is at/Library/Application Support/ClaudeCode/CLAUDE.md, and its text namesxcodebuild, the missing GUI login session, andswift test(TestGuestInstructions).
wb-hostd
Section titled “wb-hostd”-
Result records. Feed it records with each field outside its form, a URL with a port, a user, a query, a fragment, an empty segment and a
..segment, and a 17th request, and see each end the run withdownload-record-form. The checks themselves areTestC12DownloadRecordFormininternal/download/record, whichwb-hostdandwb-downloadshare. -
Restore image. See each refused with its rule:
- a catalog entry below the minimum, with and without
--allow-older-macos(restore-image-below-minimum); - an entry older than the last sealed image, without
--allow-older-macos(restore-image-rollback). With the flag, it is accepted; - less free space than the entry’s file size limit, less the
partial file, plus the floor (
download-no-space); - a file of the right size with another SHA-1
(
restore-image-hash-mismatch).
A partial file that is a symbolic link isn’t opened. A changed entry truncates the partial file.
- a catalog entry below the minimum, with and without
-
Claude Code. A file left in
<data>/downloads/is deleted at the build’s start. A version from outside the build’s input is refused. A channel file over 64 bytes, empty, with two line feeds, or with anything but a version, is refused (claude-channel-invalid). A channel version older than the last sealed Claude Code layer’s is refused (claude-release-rollback), and a sealed parent doesn’t move that floor. The same version from--claude-versionis accepted. With no record any version above the minimum is accepted, and an unreadablestate.dbrefuses the build (claude-release-floor-unknown).wb-release-checkstarts only afterwb-downloadhas exited. -
Audit. A download record that can’t be written cancels the run with
download-audit-failed.
Bundle
Section titled “Bundle”- Entitlement check. Each case of S17-01-bundleS17-01-bundle: The BundleWhat a Wraith Box bundle holds, and how mise run build builds and signs it., “The entitlement
check”, fails the check with the program and the rule in its message.
The tests are the
TestC05BuildCheckones ininternal/appbundle(C05-credentials-and-storeC05-credentials-and-store: Credentials and the Secret StoreThe test cases for the secret store and its callers, the signing setup that gives development builds their Keychain groups, and the credential checks wb-proxyd makes on guest requests and server responses., “Access groups”). - Identity. A
WB_TEAM_IDthat isn’t ten uppercase letters and digits fails the build before anything is built, with a message that names it. A valid one givesnl.wraithbox.dev.<teamid>in lowercase. AWB_BUNDLE_IDthat isn’t reverse-DNS is refused (TestC12BundleIdentity). - Install. Installing two bundles in turn at one temporary
destination leaves the second, with no file of the first and nothing
next to it (
TestC12BundleInstallSwap). A destination with another name, or one that is there and isn’t a bundle, is refused. A copy that doesn’t verify is never renamed in. - Build. CI’s macOS job builds the ad-hoc bundle and runs the check
on it (
mise run app:bundle).
wb setup
Section titled “wb setup”See each refused with its rule, and nothing written:
- a bundle outside both
Applicationsfolders (setup-bundle-location); - a bare
wb, an unstamped one, and one whoseWBBuildVersiondiffers (setup-not-in-bundle); - a regular file, and a link into another directory, at
~/.local/bin/wb(setup-link-exists); - a changed plist with a VM running, with a same-version
wb-hostdthat can’t list its VMs, and with awb-hostdof another build version, whose message names both versions (setup-vms-running); - a Mac without Apple Silicon or with an older macOS
(
setup-host-unsupported), and a Linux or Windows host (setup-host-later).
With an unchanged plist and a loaded agent, it leaves the agent running
and asks wb-hostd nothing. With no wb-hostd listening, it goes on.
It runs /bin/launchctl with only PATH in its environment. The plist
is mode 644, written by rename. An old Wraith Box link is replaced, and
a ~/.local/bin that isn’t on PATH gets the line to add. The
projects root and the probe file are made when missing and left alone
when present. The tests are the TestC12Setup ones in
internal/setup and internal/platform/service, and the reader of
WBBuildVersion is TestReadBuildVersion in internal/appbundle.
Migrations
Section titled “Migrations”A failed backup, a failed migration, a newer database, and a renamed
and an unknown configuration key each put wb-hostd in refusing mode
with their rule, and it starts no daemon. An existing .bak name is
kept. A backup file is mode 600. The tests are the TestC12 ones in
internal/hostd/state, internal/config and internal/hostd/startup.
Fuzzing
Section titled “Fuzzing”Bytes from the internet: Apple’s restore image catalog
(FuzzParse), the Content-Range header (FuzzContentRange), and
the result records wb-hostd reads from wb-download
(FuzzResults). The requests wb-download reads from wb-hostd have
FuzzRequests.
A Claude Code release’s signature and manifest: the armor
(FuzzDearmor) and the signature packet (FuzzParseSignature) in
internal/releasecheck/pgpsig, and the manifest parser
(FuzzParseManifest) in internal/releasecheck. The result record
wb-hostd reads from wb-release-check has FuzzParseRecord, and the
request wb-release-check reads from wb-hostd has FuzzReadRequest,
both in internal/releasecheck/record.
Status: Draft