Files
web-terminal/control-plane/test/audit.test.ts
Yaojia Wang 2af57e6686 feat(relay): rendezvous-relay service — 7 packages + plans (contracts/transport/agent/control-plane/e2e/auth/web)
Multi-tenant reverse-tunnel service ("ngrok for Claude Code" with E2E): a
host-agent dials OUT to an operator-run relay; external devices reach the host
THROUGH the relay, routed by per-tenant subdomain, forwarding ciphertext only
(the relay never sees plaintext). Lets a customer reach their own self-hosted
web-terminal from anywhere with zero networking setup.

Packages — all tsc-strict + vitest green (656 tests), cross-package integration verified:
- relay-contracts: frozen shared contracts (mux frame codec, data model,
  capability token, E2E envelope, pairing) — the src/types.ts analog
- term-relay:   native WS mux + stateless data plane (subdomain routing, ciphertext forward)
- agent:        host-agent (pairing, per-host Ed25519 + mTLS dial-out, forwards to 127.0.0.1:3000)
- control-plane: accounts/hosts registry, pairing-code flow, routing table, provisioning
- relay-e2e:    browser<->agent E2E (X25519 ECDH through relay, AEAD, anti-replay, recoverable replay key)
- relay-auth:   Passkey/WebAuthn, capability tokens, per-host certs, deny-by-default tenant isolation
- relay-web:    browser login + Web Crypto E2E + client-side preview rendering

Security invariants INV1-15 enforced; cross-tenant isolation CI tripwire live
(.github/workflows/relay-tripwire.yml). Design + implementation-level plans in
docs/PLAN_RELAY_*.md and docs/EXPLORE_RELAY_SERVICE.md.

NOTE: generated autonomously per the reviewed plans. The security-critical
packages (relay-e2e, relay-auth) REQUIRE expert security audit before any real
deployment — passing tests prove self-consistency, not resistance to attackers.
Base app (src/, public/) unchanged; concurrent desktop work left uncommitted.
2026-07-02 06:10:16 +02:00

62 lines
2.7 KiB
TypeScript
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { describe, test, expect } from 'vitest'
import { createMemoryStores } from '../src/store/memory.js'
import { createAuditLog, MAX_META_VALUE_LEN } from '../src/audit/log.js'
import { createAccountRegistry } from '../src/registry/accounts.js'
import { createHostRegistry } from '../src/registry/hosts.js'
import { fingerprint } from '../src/ca/fingerprint.js'
import { generateEd25519 } from '../src/util/crypto.js'
describe('T14 audit log (INV10 zero payload)', () => {
test('rejects a meta value carrying control/ANSI bytes (terminal payload guard)', async () => {
const { audit } = createMemoryStores()
const log = createAuditLog(audit)
await expect(
log.writeAuditEvent({
action: 'attach',
principalId: 'p',
accountId: 'a',
hostId: null,
ts: new Date().toISOString(),
meta: { out: 'ls\r\noutput' }, // looks like shell output
}),
).rejects.toThrow(/payload guard/)
})
test('rejects an over-long meta value', async () => {
const { audit } = createMemoryStores()
const log = createAuditLog(audit)
await expect(
log.writeAuditEvent({
action: 'manage',
principalId: 'p',
accountId: 'a',
hostId: null,
ts: new Date().toISOString(),
meta: { blob: 'x'.repeat(MAX_META_VALUE_LEN + 1) },
}),
).rejects.toThrow(/payload guard/)
})
test('append-only: entries are queryable, no update/delete surface exists', async () => {
const { audit } = createMemoryStores()
const log = createAuditLog(audit)
await log.writeAuditEvent({ action: 'kill', principalId: 'p', accountId: 'acct', hostId: 'h', ts: new Date().toISOString(), meta: {} })
const rows = await log.queryAudit('acct', '1970-01-01T00:00:00.000Z', '2999-01-01T00:00:00.000Z')
expect(rows.length).toBe(1)
expect(Object.keys(log)).not.toContain('update')
expect(Object.keys(log)).not.toContain('delete')
})
test('control-plane mutations emit audit entries (create + bind)', async () => {
const stores = createMemoryStores()
const log = createAuditLog(stores.audit)
const accounts = createAccountRegistry({ accounts: stores.accounts, audit: log })
const hosts = createHostRegistry({ hosts: stores.hosts, audit: log })
const acct = await accounts.createAccount('pro')
const { publicKeyRaw } = generateEd25519()
await hosts.bindHost({ accountId: acct.accountId, subdomain: 'alice', agentPubkey: publicKeyRaw, enrollFpr: fingerprint(publicKeyRaw) })
const rows = await log.queryAudit(acct.accountId, '1970-01-01T00:00:00.000Z', '2999-01-01T00:00:00.000Z')
expect(rows.map((r) => r.action).sort()).toEqual(['account.create', 'host.bind'])
})
})