forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtest-quic-server-handshake-with-test-client.mjs
More file actions
63 lines (53 loc) · 1.91 KB
/
Copy pathtest-quic-server-handshake-with-test-client.mjs
File metadata and controls
63 lines (53 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Flags: --experimental-quic
import { hasQuic, isAIX, isWindows, skip } from '../common/index.mjs';
import { partialDeepStrictEqual, ok } from 'node:assert';
import { setTimeout } from 'node:timers/promises';
if (!hasQuic) {
skip('QUIC support is not enabled');
}
if (isAIX) {
// AIX does not support some of the networking features used in the ngtcp2
// example server and client.
skip('QUIC third-party tests are disabled on AIX');
}
if (isWindows) {
// Windows does not support the [Li/U]nix specific headers and system calls
// required by the ngtcp2 example server/client.
skip('QUIC third-party tests are disabled on Windows');
}
// Import after the hasQuic check
const { default: QuicTestClient } = await import('../common/quic/test-client.mjs');
const { listen } = await import('node:quic');
const { readKey } = await import('../common/fixtures.mjs');
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',
};
const serverOpened = Promise.withResolvers();
const server = await listen(async (session) => {
// Wrapping in a mustCall is not necessary here since if this
// function is not called the test will time out and fail.
const info = await session.opened;
partialDeepStrictEqual(info, check);
serverOpened.resolve();
session.destroy();
}, { keys, certs });
// The server must have an address to connect to after listen resolves.
const address = server.address;
ok(address !== undefined);
const client = new QuicTestClient();
client.run(address.address, address.port, undefined, {
stdio: 'ignore',
});
await serverOpened.promise;
await setTimeout(100);
client.stop();
await server.close();