Skip to content

Commit 01aa635

Browse files
committed
test: cleanup QUIC tests and migrate them to mjs
1 parent ddcffa3 commit 01aa635

11 files changed

+544
-602
lines changed

test/common/index.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const {
1616
getBufferSources,
1717
getTTYfd,
1818
hasCrypto,
19+
hasQuic,
1920
hasSQLite,
2021
hasIntl,
2122
hasIPv6,
@@ -66,6 +67,7 @@ export {
6667
getPort,
6768
getTTYfd,
6869
hasCrypto,
70+
hasQuic,
6971
hasSQLite,
7072
hasIntl,
7173
hasIPv6,

test/parallel/test-quic-handshake.js

Lines changed: 0 additions & 50 deletions
This file was deleted.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Flags: --experimental-quic --no-warnings
2+
3+
import { hasQuic, skip } from '../common/index.mjs';
4+
import { ok, partialDeepStrictEqual } from 'node:assert';
5+
import { createPrivateKey } from 'node:crypto';
6+
import { readKey } from '../common/fixtures.mjs';
7+
8+
if (!hasQuic) {
9+
skip('QUIC is not enabled');
10+
}
11+
12+
// Import after the hasQuic check
13+
const { listen, connect } = await import('node:quic');
14+
15+
const keys = createPrivateKey(readKey('agent1-key.pem'));
16+
const certs = readKey('agent1-cert.pem');
17+
18+
const check = {
19+
// The SNI value
20+
servername: 'localhost',
21+
// The selected ALPN protocol
22+
protocol: 'h3',
23+
// The negotiated cipher suite
24+
cipher: 'TLS_AES_128_GCM_SHA256',
25+
cipherVersion: 'TLSv1.3',
26+
};
27+
28+
// The opened promise should resolve when the handshake is complete.
29+
30+
const serverOpened = Promise.withResolvers();
31+
const clientOpened = Promise.withResolvers();
32+
33+
const serverEndpoint = await listen(async (serverSession) => {
34+
const info = await serverSession.opened;
35+
partialDeepStrictEqual(info, check);
36+
serverOpened.resolve();
37+
serverSession.close();
38+
}, { keys, certs });
39+
40+
// The server must have an address to connect to after listen resolves.
41+
ok(serverEndpoint.address !== undefined);
42+
43+
const clientSession = await connect(serverEndpoint.address);
44+
clientSession.opened.then((info) => {
45+
partialDeepStrictEqual(info, check);
46+
clientOpened.resolve();
47+
});
48+
49+
await Promise.all([serverOpened.promise, clientOpened.promise]);
50+
clientSession.close();

test/parallel/test-quic-internal-endpoint-listen-defaults.js

Lines changed: 0 additions & 87 deletions
This file was deleted.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Flags: --expose-internals --experimental-quic --no-warnings
2+
import { hasQuic, skip } from '../common/index.mjs';
3+
4+
import {
5+
ok,
6+
rejects,
7+
strictEqual,
8+
throws,
9+
} from 'node:assert';
10+
import { createPrivateKey } from 'node:crypto';
11+
import { readKey } from '../common/fixtures.mjs';
12+
import { SocketAddress } from 'node:net';
13+
14+
if (!hasQuic) {
15+
skip('QUIC is not enabled');
16+
}
17+
18+
// Import after the hasQuic check
19+
const { listen, QuicEndpoint } = await import('node:quic');
20+
const { kState } = (await import('internal/quic/symbols')).default;
21+
22+
const keys = createPrivateKey(readKey('agent1-key.pem'));
23+
const certs = readKey('agent1-cert.pem');
24+
25+
const endpoint = new QuicEndpoint();
26+
27+
ok(!endpoint[kState].isBound);
28+
ok(!endpoint[kState].isReceiving);
29+
ok(!endpoint[kState].isListening);
30+
31+
strictEqual(endpoint.address, undefined);
32+
33+
await rejects(listen(123, { keys, certs, endpoint }), {
34+
code: 'ERR_INVALID_ARG_TYPE',
35+
});
36+
37+
await rejects(listen(() => {}, 123), {
38+
code: 'ERR_INVALID_ARG_TYPE',
39+
});
40+
41+
await listen(() => {}, { keys, certs, endpoint });
42+
await rejects(listen(() => {}, { keys, certs, endpoint }), {
43+
code: 'ERR_INVALID_STATE',
44+
});
45+
46+
ok(endpoint[kState].isBound);
47+
ok(endpoint[kState].isReceiving);
48+
ok(endpoint[kState].isListening);
49+
50+
const address = endpoint.address;
51+
ok(address instanceof SocketAddress);
52+
53+
strictEqual(address.address, '127.0.0.1');
54+
strictEqual(address.family, 'ipv4');
55+
strictEqual(address.flowlabel, 0);
56+
ok(address.port !== 0);
57+
58+
ok(!endpoint.destroyed);
59+
endpoint.destroy();
60+
strictEqual(endpoint.closed, endpoint.close());
61+
await endpoint.closed;
62+
ok(endpoint.destroyed);
63+
64+
await rejects(listen(() => {}, { keys, certs, endpoint }), {
65+
code: 'ERR_INVALID_STATE',
66+
});
67+
throws(() => { endpoint.busy = true; }, {
68+
code: 'ERR_INVALID_STATE',
69+
});
70+
await endpoint[Symbol.asyncDispose]();
71+
72+
strictEqual(endpoint.address, undefined);

0 commit comments

Comments
 (0)