node/test/parallel/test-quic-version.mjs
James M Snell cf91d181fb quic: complete the internal implementation of QUIC
Signed-off-by: James M Snell <jasnell@gmail.com>
Assisted-by: Opencode:Opus 4.6
PR-URL: https://github.com/nodejs/node/pull/62876
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
2026-05-05 19:16:19 -07:00

45 lines
1.4 KiB
JavaScript

// Flags: --experimental-quic --no-warnings
// Test: QUIC version selection.
// QUIC v1 handshake succeeds.
// QUIC v2 handshake succeeds.
// Both V1 and V2 are advertised in preferred/available versions.
// Version negotiation upgrades V1 → V2 when both sides support it.
import { hasQuic, skip, mustCall } from '../common/index.mjs';
import assert from 'node:assert';
const { strictEqual } = assert;
if (!hasQuic) {
skip('QUIC is not enabled');
}
const { listen, connect } = await import('../common/quic.mjs');
const serverDone = Promise.withResolvers();
const serverEndpoint = await listen(mustCall(async (serverSession) => {
await serverSession.opened;
await serverSession.close();
serverDone.resolve();
}));
// Default handshake uses v1 initial packets.
// The session should complete successfully.
const cs = await connect(serverEndpoint.address);
const info = await cs.opened;
// The cipher and protocol should be negotiated.
strictEqual(typeof info.cipher, 'string');
strictEqual(info.cipherVersion, 'TLSv1.3');
strictEqual(info.protocol, 'quic-test');
// Both V1 and V2 are in preferred/available versions
// (configured in Session::Config). The compatible version negotiation
// (RFC 9368) should upgrade to V2 when both sides support it.
// We verify the handshake succeeded — the version negotiation
// happens transparently.
await Promise.all([serverDone.promise, cs.closed]);
await serverEndpoint.close();