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.
87 lines
3.2 KiB
TypeScript
87 lines
3.2 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
import { mountDashboard } from '../src/dashboard'
|
|
import { ApiError } from '../src/errors'
|
|
import type { ApiClient } from '../src/api-client'
|
|
import type { HostRecord, HostStatus } from '../src/api-schemas'
|
|
|
|
function host(subdomain: string, status: HostStatus): HostRecord {
|
|
return {
|
|
hostId: `id-${subdomain}`,
|
|
accountId: 'acc',
|
|
subdomain,
|
|
agentPubkey: new Uint8Array([1]),
|
|
enrollFpr: `fpr-${subdomain}`,
|
|
status,
|
|
lastSeen: '2026-01-01T00:00:00Z',
|
|
createdAt: '2026-01-01T00:00:00Z',
|
|
revokedAt: status === 'revoked' ? '2026-01-02T00:00:00Z' : null,
|
|
}
|
|
}
|
|
|
|
function fakeApi(listHosts: () => Promise<readonly HostRecord[]>): ApiClient {
|
|
return {
|
|
listHosts,
|
|
getHost: vi.fn(),
|
|
requestPairingCode: vi.fn(),
|
|
hostStatus: vi.fn(),
|
|
issueCapabilityToken: vi.fn(),
|
|
} as unknown as ApiClient
|
|
}
|
|
|
|
describe('mountDashboard (T5)', () => {
|
|
let root: HTMLElement
|
|
beforeEach(() => {
|
|
root = document.createElement('div')
|
|
document.body.append(root)
|
|
})
|
|
|
|
it('renders one card per host with the correct status class', async () => {
|
|
const api = fakeApi(async () => [host('alice', 'online'), host('bob', 'offline'), host('cy', 'draining')])
|
|
const dash = mountDashboard(root, api, { pollMs: 100000 })
|
|
await dash.refresh()
|
|
const cards = root.querySelectorAll('.host-card')
|
|
expect(cards).toHaveLength(3)
|
|
expect(root.querySelector('.status-online')).not.toBeNull()
|
|
expect(root.querySelector('.status-draining')).not.toBeNull()
|
|
dash.dispose()
|
|
})
|
|
|
|
it('revoked host is non-interactive: no open action, shows blocked state (INV12 UI)', async () => {
|
|
const api = fakeApi(async () => [host('gone', 'revoked')])
|
|
const dash = mountDashboard(root, api, { pollMs: 100000 })
|
|
await dash.refresh()
|
|
const card = root.querySelector('[data-status="revoked"]') as HTMLElement
|
|
expect(card.querySelector('.host-open')).toBeNull()
|
|
expect(card.querySelector('.host-blocked')?.textContent).toBe('revoked')
|
|
dash.dispose()
|
|
})
|
|
|
|
it('open action routes with the host_id (no foreign-host input path exists — INV1/INV3)', async () => {
|
|
const onOpen = vi.fn()
|
|
const api = fakeApi(async () => [host('alice', 'online')])
|
|
const dash = mountDashboard(root, api, { pollMs: 100000, onOpen })
|
|
await dash.refresh()
|
|
;(root.querySelector('.host-open') as HTMLButtonElement).click()
|
|
expect(onOpen).toHaveBeenCalledWith('id-alice')
|
|
dash.dispose()
|
|
})
|
|
|
|
it('a listHosts rejection shows an error banner and keeps polling', async () => {
|
|
const api = fakeApi(async () => {
|
|
throw new ApiError('http', 'boom', 500)
|
|
})
|
|
const dash = mountDashboard(root, api, { pollMs: 100000 })
|
|
await dash.refresh()
|
|
expect(root.querySelector('.dashboard-error')?.textContent).toContain('Could not load hosts')
|
|
dash.dispose()
|
|
})
|
|
|
|
it('never issues a request carrying an account_id (INV3) — listHosts is argument-free', async () => {
|
|
const listHosts = vi.fn(async () => [] as HostRecord[])
|
|
const dash = mountDashboard(root, fakeApi(listHosts), { pollMs: 100000 })
|
|
await dash.refresh()
|
|
expect(listHosts).toHaveBeenCalledWith() // no args ⇒ no client-supplied tenant identity
|
|
dash.dispose()
|
|
})
|
|
})
|