AtlatestRepositorysigil-http3
sigil-http3 / tree / testtest-continuous-punch-window.mjs
1
// Admission boundaries only; this test never creates a UDP socket/command.2
import assert from 'node:assert/strict';3
import { test } from 'node:test';4
import { existsSync, mkdirSync, writeFileSync, readFileSync } from 'node:fs';5
import { resolve, join } from 'node:path';6
import { requestPrime } from '../scripts/continuous-punch-window.mjs';7
test('control confirmation, valid phase and fresh non-home address precede a single request', () => {8
const directory = resolve('build/continuous-admission-checks');9
mkdirSync(directory, { mode: 0o700 });10
const statePath = join(directory, 'state.json'), rendezvousPath = join(directory, 'rendezvous.json');11
const state = { phase: 'control-ready', bindAddress: '2001:db8:1:2::1', expiresAt: new Date(Date.now() + 60000).toISOString() };12
const good = { cellularOnly: true, phoneIPv6: '2a00:1234:abcd:2345::1', observedAt: new Date().toISOString() };13
const save = (path, value) => writeFileSync(path, JSON.stringify(value), { mode: 0o600 });14
save(statePath, state); save(rendezvousPath, good);15
assert.throws(() => requestPrime(directory, rendezvousPath, false), /control confirmation/);16
save(statePath, { ...state, phase: 'awaiting-firewall' });17
assert.throws(() => requestPrime(directory, rendezvousPath, true), /Control not active/);18
save(statePath, { ...state, expiresAt: new Date(Date.now() - 1000).toISOString() });19
assert.throws(() => requestPrime(directory, rendezvousPath, true), /Control not active/);20
save(statePath, state);21
for (const invalid of [{ ...good, cellularOnly: false },22
{ ...good, phoneIPv6: '2001:db8:1:2::9' },23
{ ...good, observedAt: new Date(Date.now() - 600001).toISOString() }]) {24
save(rendezvousPath, invalid);25
assert.throws(() => requestPrime(directory, rendezvousPath, true));26
}27
assert.equal(existsSync(join(directory, 'prime-request.json')), false);28
save(rendezvousPath, good);29
assert.equal(requestPrime(directory, rendezvousPath, true).seconds, 180);30
assert.equal(JSON.parse(readFileSync(join(directory, 'prime-request.json'))).confirmedControlFailed, true);31
assert.throws(() => requestPrime(directory, rendezvousPath, true), /EEXIST/);32
assert.equal(existsSync(join(directory, 'command.scm')), false);33
});