Skip to content

Commit 3165b8c

Browse files
committed
quic: bring back & extend test for client uni streams over H3
Signed-off-by: Tim Perry <pimterry@gmail.com>
1 parent b03f8ef commit 3165b8c

1 file changed

Lines changed: 71 additions & 0 deletions

File tree

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Flags: --experimental-quic --no-warnings --expose-internals
2+
3+
// Test: client-created unidirectional streams on an HTTP/3 connection, which
4+
// are not valid HTTP/3 request streams, are handled internally by nghttp3.
5+
6+
import { hasQuic, skip, mustCall, mustNotCall } from '../common/index.mjs';
7+
import * as fixtures from '../common/fixtures.mjs';
8+
9+
if (!hasQuic) {
10+
skip('QUIC is not enabled');
11+
}
12+
13+
const { createPrivateKey } = await import('node:crypto');
14+
const { listen, connect, QuicSession } = await import('node:quic');
15+
const { createRequire } = await import('node:module');
16+
const require = createRequire(import.meta.url);
17+
const { createApplicationStream } = require('internal/quic/quic');
18+
const { internalBinding } = require('internal/test/binding');
19+
const { STREAM_DIRECTION_UNIDIRECTIONAL } = internalBinding('quic');
20+
21+
const key = createPrivateKey(fixtures.readKey('agent1-key.pem'));
22+
const cert = fixtures.readKey('agent1-cert.pem');
23+
24+
// A stream of an unknown type, here from a client speaking raw QUIC over the h3
25+
// ALPN, is ignored: never exposed as a request, and the connection stays up.
26+
{
27+
const endpoint = await listen(mustCall((session) => {
28+
session.onstream = mustNotCall();
29+
}), {
30+
alpn: ['h3'],
31+
sni: { '*': { keys: [key], certs: [cert] } },
32+
});
33+
const connection = await connect(endpoint.address, {
34+
alpn: 'h3',
35+
autoStart: false,
36+
servername: 'localhost',
37+
verifyPeer: 'manual',
38+
});
39+
const client = QuicSession.start(connection);
40+
41+
const stream = await client.createUnidirectionalStream();
42+
// 0x21 is a reserved stream type (RFC 9114 section 6.2.3).
43+
stream.writer.writeSync(new Uint8Array([0x21, 0x61, 0x62]));
44+
stream.writer.endSync();
45+
// Resolves once the server has acknowledged all of it:
46+
await stream.closed;
47+
48+
await client.close();
49+
await endpoint.close();
50+
}
51+
52+
// Regression test for https://github.com/nodejs/node/issues/65408.
53+
// A raw unidirectional stream created on an HTTP/3 connection is never sent,
54+
// so it stays open, and must not crash during process teardown.
55+
const endpoint = await listen(mustNotCall(), {
56+
alpn: ['h3'],
57+
sni: { '*': { keys: [key], certs: [cert] } },
58+
});
59+
60+
const session = await connect(endpoint.address, {
61+
alpn: 'h3',
62+
servername: 'localhost',
63+
verifyPeer: 'manual',
64+
});
65+
66+
const stream = await createApplicationStream(
67+
session.connection, STREAM_DIRECTION_UNIDIRECTIONAL);
68+
stream.writer.writeSync('x');
69+
70+
endpoint.destroy();
71+
await endpoint.closed;

0 commit comments

Comments
 (0)