Files
FFF_vtt_frozen/tools/tlsdev.mjs
T
SirStone 3c0258ea31 feat: client shell, sign-in and protocol client (#67)
New `client/` package (Vite + TypeScript + PixiJS v8, plain DOM overlay):
the pure reducer seam (no Pixi import), an append-only slice registry
build-time glob, the `proto` 2 WS client with envelope/ack/closing mapping,
the sign-in door (`POST /join`, one "Key not recognised." for wrong and
unknown), the DOM shell/HUD and a minimal Pixi stage created only after a
live `hello`. `hello` resets every slice so a reconnect cannot show stale
state; `proto-mismatch` shows reload; `revoked` returns to the sign-in page
and stops.

The browser e2e moves into the client package (`client/e2e/`, owning
playwright-core) and runs the real Vite build through the TLS/HTTP2 test
nginx: join -> canvas -> hello/roster for GM and player, no data before
join, identical wrong/unknown key refusal, proto mismatch, revoked.
`devbox run client-test` adds the Vitest seam; `devbox run e2e` builds the
client first. The #66 stub dist stays local to `tools/vhost.test.mjs`, so
`devbox run test` still needs no npm install.

Refs #67
2026-11-20 23:57:16 +01:00

46 lines
2.1 KiB
JavaScript

// The test nginx's TLS material (#66, DESIGN 11.1 / TESTING 11.1). A self-signed certificate is
// GENERATED at run time, never committed: browsers only negotiate HTTP/2 over TLS, and the session
// cookie is `Secure`, so the browser e2e and the harnesses have to speak https.
//
// One directory per run (`run/tls`, gitignored) is shared by every harness file in the run: the
// certificate is a trust anchor for the Node side through NODE_EXTRA_CA_CERTS (set by tools/test.sh
// and client/e2e/run.sh), and nginx loads the same pair. The SANs are what a client checks on loopback.
import { spawnSync } from 'node:child_process'
import fs from 'node:fs'
import path from 'node:path'
const SUBJECT = '/CN=fff-vtt test nginx'
const SAN = 'subjectAltName=DNS:localhost,IP:127.0.0.1'
function generate(dir) {
fs.mkdirSync(dir, { recursive: true })
const certPath = path.join(dir, 'cert.pem')
const keyPath = path.join(dir, 'key.pem')
const r = spawnSync('openssl', [
'req', '-x509', '-newkey', 'ec', '-pkeyopt', 'ec_paramgen_curve:prime256v1',
'-nodes', '-sha256', '-days', '3',
'-keyout', keyPath, '-out', certPath,
'-subj', SUBJECT,
// CA:TRUE so the pair is usable as a trust anchor (NODE_EXTRA_CA_CERTS) as well as a leaf;
// serverAuth + digitalSignature so a browser/h2 client accepts it as a TLS server certificate.
'-addext', SAN,
'-addext', 'basicConstraints=critical,CA:TRUE',
'-addext', 'keyUsage=critical,digitalSignature,keyCertSign',
'-addext', 'extendedKeyUsage=serverAuth',
], { encoding: 'utf8' })
if (r.status !== 0) {
throw new Error(`openssl could not generate the test certificate (is the openssl devbox ` +
`package installed?):\n${r.stdout}\n${r.stderr}`)
}
return { certPath, keyPath }
}
// Ensures <dir>/{cert,key}.pem exist and returns their paths. Idempotent: an existing pair is
// reused, so a run's harness files start from the same anchor.
export function ensureDevCert(dir) {
const certPath = path.join(dir, 'cert.pem')
const keyPath = path.join(dir, 'key.pem')
if (fs.existsSync(certPath) && fs.existsSync(keyPath)) return { certPath, keyPath }
return generate(dir)
}