Mock vault
The throwaway vault server used by unit and UI tests: endpoints, fixed fixtures, control endpoints and the scripted drive.

The mock vault implements just enough of the vault server API for the app's remote vault code to connect, sync and fail in controlled ways. It encrypts with the app's own crypto functions, so the envelope and state formats it serves are the ones the app must read.

Files

File

Role

tools/mock-vault/routes.ts

handle(req): every route under /vault/. Returns null for other paths

tools/mock-vault/serve.ts

Standalone fallback that serves only the vault routes on port 4790. Its comment calls it a fallback "until the lead mounts routes.ts"; the test server now mounts them, so it is not needed for normal runs

tools/mock-vault/drive.mjs

A scripted drive of the built app through the whole vault flow, with screenshots

The vault URL a test types is http://127.0.0.1:4790/vault.

Fixed fixtures

Defined at the top of routes.ts L14-L25. All are test bytes, not secrets:

Name

Value

Credential secret

32 bytes of 11

DEK (data encryption key)

64 bytes of 12

credentialId

fixture-device

userId

fixture-user

State after reset

One account remote-alice (seed 32 bytes of 3, createTime 123), server version 1

API endpoints

Method and path

Behaviour

GET /vault/connect

An HTML approval page with one Approve button. It reads token from the URL fragment and posts it to /vault/__test/approve

GET /vault/api/vault-connect/<id>

The one time mailbox. <id> is base64url of SHA-256 of the token. Returns {found: true, payload} once and deletes it; otherwise 404 {found: false}

GET /vault/api/vault

Needs Authorization: Bearer <buildBearerAuth(credentialId, secret)>, else 401. With ?knownVersion=<current> answers {unchanged: true}; otherwise {version, encryptedData, credentials: [{kind: "secret", credentialId, wrappedDEK}]}

POST /vault/api/vault

Same auth. Body {version, encryptedData}. A stale version answers 409 remote vault write conflict. On success the state is decrypted, stored and the version incremented

DELETE /vault/api/credentials/secret/<id>

Same auth. {success: true}

The mailbox payload is JSON {vaultUrl, userId, credentialId, secret} encrypted with the 32 byte connect token (routes.ts L65-L78). See Vault: connect ceremony and Vault: API and sync.

Control endpoints

All are POST with a JSON body, under /vault/__test/:

Path

Body

Effect

reset

{}

Restores the reset state, clears conflicts, counters and mailboxes

configure

{"conflicts": n}

The next n uploads answer 409 and bump the version

configure

{"corruptDEK": true}

Wraps the DEK with a wrong key (32 bytes of 99) and bumps the version, so the app refetches and fails to unwrap

approve

{"token": "<b64url>", "vaultUrl"?: "...", "wrongKey"?: true}

Puts an encrypted approval in the mailbox. wrongKey encrypts with random bytes; vaultUrl tests the URL mismatch refusal. A token that is not 32 bytes answers 400

remote-add

{}

Adds account remote-bob (seed 32 bytes of 4) and bumps the version, as another device would

state

any

{names, version, writes, reads} for assertions. reads and writes count authenticated GET and POST on /vault/api/vault

Who uses it

    vault.test.ts (27 tests): replaces globalThis.fetch with a function that calls handle directly and throws on any other URL, then resets before each test. It covers connect, wrong mailbox key, URL mismatch, retry after an aborted reply, three conflicts, corrupt DEK, tombstones, lock and logout.

    vault.test.contract (3 tests): local state, an invalid URL, and a pending connection that warns after clock + 6000 with fetches failing and expires after clock + 900000. Contract request steps take literal JSON only, so a test cannot pass the generated token to approve; approval is left to the drive.

    drive.mjs: completes the approval by reading the token out of the app's connect link.

The scripted drive

bun exact.mjs test web # builds target/web-dist bun tools/mock-vault/drive.mjs web # or ios; needs the test server on 4790

It imports open and textOf from Exact's scripts/agent.mjs (EXACT env, default ~/Code/exact), opens the app at /me/vault on fresh storage with seed: 42, and runs two sessions:

    Local mode, connect and cancel, connect and approve, remote identities visible in Me, one forced 409 with a local import uploaded (writes >= 2), background sync paused while visibility-state is hidden across clock +30000, a remote addition appearing, a corrupt DEK error and recovery, lock, unlock, back to local.

    A wrong mailbox key ("Failed to decrypt vault connect payload."), retry, and confirmed logout.

Screenshots in light and dark go to ~/.local/state/seed-mobile-exact/screenshots/vault/<host>-<name>-<scheme>.png.

Do you like what you are reading? Subscribe to receive updates.

Unsubscribe anytime

Comments