Skip to content

Commit 519850f

Browse files
trivikrMylesBorins
authored andcommitted
test: http2 client setNextStreamID errors
Backport-PR-URL: #18848 PR-URL: #18848 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Minwoo Jung <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent f0f31d0 commit 519850f

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

lib/internal/http2/core.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ class Http2Session extends EventEmitter {
948948
if (typeof id !== 'number')
949949
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'id', 'number');
950950
if (id <= 0 || id > kMaxStreams)
951-
throw new errors.RangeError('ERR_OUT_OF_RANGE');
951+
throw new errors.RangeError('ERR_OUT_OF_RANGE', 'id');
952952
this[kHandle].setNextStreamID(id);
953953
}
954954

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
if (!common.hasCrypto)
5+
common.skip('missing crypto');
6+
7+
const http2 = require('http2');
8+
9+
const server = http2.createServer();
10+
server.on('stream', (stream) => {
11+
stream.respond();
12+
stream.end('ok');
13+
});
14+
15+
const types = {
16+
boolean: true,
17+
function: () => {},
18+
number: 1,
19+
object: {},
20+
array: [],
21+
null: null,
22+
symbol: Symbol('test')
23+
};
24+
25+
server.listen(0, common.mustCall(() => {
26+
const client = http2.connect(`http://localhost:${server.address().port}`);
27+
28+
client.on('connect', () => {
29+
const outOfRangeNum = 2 ** 31;
30+
common.expectsError(
31+
() => client.setNextStreamID(outOfRangeNum),
32+
{
33+
type: RangeError,
34+
code: 'ERR_OUT_OF_RANGE',
35+
message: 'The "id" argument is out of range'
36+
}
37+
);
38+
39+
// should throw if something other than number is passed to setNextStreamID
40+
Object.entries(types).forEach(([type, value]) => {
41+
if (type === 'number') {
42+
return;
43+
}
44+
45+
common.expectsError(
46+
() => client.setNextStreamID(value),
47+
{
48+
type: TypeError,
49+
code: 'ERR_INVALID_ARG_TYPE',
50+
message: 'The "id" argument must be of type number'
51+
}
52+
);
53+
});
54+
55+
server.close();
56+
client.close();
57+
});
58+
}));

0 commit comments

Comments
 (0)