mirror of
https://github.com/nodejs/node.git
synced 2026-10-28 10:15:07 +08:00
Signed-off-by: Antoine du Hamel <duhamelantoine1995@gmail.com> PR-URL: https://github.com/nodejs/node/pull/64716 Reviewed-By: Ethan Arrowood <ethan@arrowood.dev> Reviewed-By: Aviv Keller <me@aviv.sh>
54 lines
1.5 KiB
JavaScript
54 lines
1.5 KiB
JavaScript
// Flags: --experimental-quic --no-warnings
|
|
|
|
// Test: endpoint binding options.
|
|
// Binding to specific address.
|
|
// Binding to specific port.
|
|
|
|
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');
|
|
}
|
|
|
|
const { listen, connect, QuicEndpoint } = 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');
|
|
|
|
// Binding to a specific port.
|
|
{
|
|
const endpoint = new QuicEndpoint({
|
|
address: { address: '127.0.0.1', port: 0 },
|
|
});
|
|
|
|
const serverEndpoint = await listen(mustCall(async (serverSession) => {
|
|
await serverSession.closed;
|
|
}), {
|
|
endpoint,
|
|
sni: { '*': { keys: [key], certs: [cert] } },
|
|
alpn: ['quic-test'],
|
|
transportParams: { maxIdleTimeout: 1 },
|
|
});
|
|
|
|
// The address should reflect what we bound to.
|
|
const addr = serverEndpoint.address;
|
|
assert.strictEqual(addr.address, '127.0.0.1');
|
|
assert.strictEqual(addr.family, 'ipv4');
|
|
assert.strictEqual(typeof addr.port, 'number');
|
|
assert.ok(addr.port > 0, 'port should be assigned');
|
|
|
|
// Verify a client can connect to the bound address.
|
|
const clientSession = await connect(serverEndpoint.address, {
|
|
alpn: 'quic-test',
|
|
verifyPeer: 'manual',
|
|
transportParams: { maxIdleTimeout: 1 },
|
|
});
|
|
await clientSession.opened;
|
|
await clientSession.close();
|
|
|
|
await serverEndpoint.close();
|
|
}
|