Files
node/test/parallel/test-quic-handshake.mjs
2026-01-01 23:48:26 +00:00

52 lines
1.5 KiB
JavaScript

// Flags: --experimental-quic --no-warnings
import { hasQuic, skip, mustCall } from '../common/index.mjs';
import assert from 'node:assert';
import * as fixtures from '../common/fixtures.mjs';
if (!hasQuic) {
skip('QUIC is not enabled');
}
// Import after the hasQuic check
const { listen, connect } = await import('node:quic');
const { createPrivateKey } = await import('node:crypto');
const keys = createPrivateKey(fixtures.readKey('agent1-key.pem'));
const certs = fixtures.readKey('agent1-cert.pem');
const check = {
// The SNI value
servername: 'localhost',
// The selected ALPN protocol
protocol: 'h3',
// The negotiated cipher suite
cipher: 'TLS_AES_128_GCM_SHA256',
cipherVersion: 'TLSv1.3',
};
// The opened promise should resolve when the handshake is complete.
const serverOpened = Promise.withResolvers();
const clientOpened = Promise.withResolvers();
const serverEndpoint = await listen(mustCall((serverSession) => {
serverSession.opened.then((info) => {
assert.partialDeepStrictEqual(info, check);
serverOpened.resolve();
serverSession.close();
}).then(mustCall());
}), { keys, certs });
// The server must have an address to connect to after listen resolves.
assert.ok(serverEndpoint.address !== undefined);
const clientSession = await connect(serverEndpoint.address);
clientSession.opened.then((info) => {
assert.partialDeepStrictEqual(info, check);
clientOpened.resolve();
}).then(mustCall());
await Promise.all([serverOpened.promise, clientOpened.promise]);
clientSession.close();