|
| 1 | +// Flags: --experimental-quic --no-warnings |
| 2 | + |
| 3 | +import { hasQuic, skip, mustCall } from '../common/index.mjs'; |
| 4 | +import assert from 'node:assert'; |
| 5 | +import * as fixtures from '../common/fixtures.mjs'; |
| 6 | + |
| 7 | +if (!hasQuic) { |
| 8 | + skip('QUIC is not enabled'); |
| 9 | +} |
| 10 | + |
| 11 | +const { listen, connect } = await import('node:quic'); |
| 12 | +const { createPrivateKey } = await import('node:crypto'); |
| 13 | + |
| 14 | +const key = createPrivateKey(fixtures.readKey('agent1-key.pem')); |
| 15 | +const cert = fixtures.readKey('agent1-cert.pem'); |
| 16 | + |
| 17 | +// Test h3 ALPN negotiation with Http3ApplicationImpl. |
| 18 | +// Both server and client use the default ALPN (h3). |
| 19 | + |
| 20 | +const serverOpened = Promise.withResolvers(); |
| 21 | +const clientOpened = Promise.withResolvers(); |
| 22 | + |
| 23 | +const serverEndpoint = await listen(mustCall((serverSession) => { |
| 24 | + serverSession.opened.then(mustCall((info) => { |
| 25 | + assert.strictEqual(info.protocol, 'h3'); |
| 26 | + serverOpened.resolve(); |
| 27 | + serverSession.close(); |
| 28 | + })); |
| 29 | +}), { |
| 30 | + sni: { '*': { keys: [key], certs: [cert] } }, |
| 31 | +}); |
| 32 | + |
| 33 | +assert.ok(serverEndpoint.address !== undefined); |
| 34 | + |
| 35 | +const clientSession = await connect(serverEndpoint.address, { |
| 36 | + servername: 'localhost', |
| 37 | +}); |
| 38 | +clientSession.opened.then(mustCall((info) => { |
| 39 | + assert.strictEqual(info.protocol, 'h3'); |
| 40 | + clientOpened.resolve(); |
| 41 | +})); |
| 42 | + |
| 43 | +await Promise.all([serverOpened.promise, clientOpened.promise]); |
| 44 | +clientSession.close(); |
0 commit comments