Files
node/test/parallel/test-quic-handshake.mjs
James M Snell 90e12f247c quic: support multiple ALPN negotiation
Signed-off-by: James M Snell <jasnell@gmail.com>
Assisted-by: Opencode:Opus 4.6
PR-URL: https://github.com/nodejs/node/pull/62620
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Tim Perry <pimterry@gmail.com>
2026-04-09 07:10:35 -07:00

60 lines
1.7 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 key = createPrivateKey(fixtures.readKey('agent1-key.pem'));
const cert = fixtures.readKey('agent1-cert.pem');
const check = {
// The SNI value
servername: 'localhost',
// The selected ALPN protocol
protocol: 'quic-test',
// 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());
}), {
sni: { '*': { keys: [key], certs: [cert] } },
alpn: ['quic-test'],
});
// Buffer is not detached.
assert.strictEqual(cert.buffer.detached, false);
// The server must have an address to connect to after listen resolves.
assert.ok(serverEndpoint.address !== undefined);
const clientSession = await connect(serverEndpoint.address, {
alpn: 'quic-test',
});
clientSession.opened.then((info) => {
assert.partialDeepStrictEqual(info, check);
clientOpened.resolve();
}).then(mustCall());
await Promise.all([serverOpened.promise, clientOpened.promise]);
clientSession.close();