node/test/parallel/test-quic-handshake-ipv6-only.mjs
James M Snell d52cd04591
quic: continue working on quic api bits
PR-URL: https://github.com/nodejs/node/pull/60123
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
2025-10-07 14:04:53 +00:00

68 lines
1.7 KiB
JavaScript

// Flags: --experimental-quic --no-warnings
import { hasQuic, hasIPv6, skip } from '../common/index.mjs';
import { ok, partialDeepStrictEqual } from 'node:assert';
import { readKey } from '../common/fixtures.mjs';
if (!hasQuic) {
skip('QUIC is not enabled');
}
if (!hasIPv6) {
skip('IPv6 is not supported');
}
// Import after the hasQuic check
const { listen, connect } = await import('node:quic');
const { createPrivateKey } = await import('node:crypto');
const keys = createPrivateKey(readKey('agent1-key.pem'));
const certs = 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(async (serverSession) => {
const info = await serverSession.opened;
partialDeepStrictEqual(info, check);
serverOpened.resolve();
serverSession.close();
}, { keys, certs, endpoint: {
address: {
address: '::1',
family: 'ipv6',
},
ipv6Only: true,
} });
// The server must have an address to connect to after listen resolves.
ok(serverEndpoint.address !== undefined);
const clientSession = await connect(serverEndpoint.address, {
endpoint: {
address: {
address: '::',
family: 'ipv6',
},
}
});
clientSession.opened.then((info) => {
partialDeepStrictEqual(info, check);
clientOpened.resolve();
});
await Promise.all([serverOpened.promise, clientOpened.promise]);
clientSession.close();