Files
Dune/tests/random-id.test.ts
T
Quintine 903c7731e2 Package verified Dune checkpoints for TrueNAS and HTTPS proxying
Serve built Workers directly through pinned Miniflare with persistent D1-compatible storage and startup migrations. Build and verify Docker images in CI; publish main checkpoints to GHCR for manual TrueNAS updates on port 33046. Preserve explicit public-origin checks and LAN-compatible cryptographic operation IDs.

Validation: 5,153 offline tests, typecheck, lint and build; 49 HTTP integration cases; HTTPS-origin create/join/chat/seat protection, foreign-origin rejection, exact saved-seat restart and browser asset serving. Independent persistence/proxy review completed. Clean Docker CI and actual NAS installation follow this source checkpoint.
2026-09-21 17:37:50 +10:00

27 lines
1.0 KiB
TypeScript

import test from 'node:test';
import assert from 'node:assert/strict';
import { randomId } from '../lib/random-id';
import { createRoomEntry } from '../lib/room-entry';
void test('LAN HTTP operations work with getRandomValues and no randomUUID', (t) => {
const native = globalThis.crypto;
t.mock.getter(globalThis, 'crypto', () => ({
getRandomValues: native.getRandomValues.bind(native),
}) as Crypto);
assert.equal(typeof globalThis.crypto.randomUUID, 'undefined');
const id = randomId();
assert.match(id, /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/);
assert.notEqual(randomId(), id);
const attempt = createRoomEntry({
name: 'LAN player', faction: 'atreides', advanced: false, expansions: [],
});
assert.ok(attempt);
});
void test('UUID creation fails closed when cryptographic randomness fails', (t) => {
t.mock.getter(globalThis, 'crypto', () => ({
getRandomValues() { throw new Error('Randomness unavailable'); },
}) as unknown as Crypto);
assert.throws(() => randomId(), /Randomness unavailable/);
});