Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http2: refactor state code validation for the http2Stream class #33535

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/internal/http2/core.js
Expand Up @@ -94,7 +94,8 @@ const {
},
hideStackFrames
} = require('internal/errors');
const { validateNumber,
const { validateInteger,
validateNumber,
validateString,
validateUint32,
isUint32,
Expand Down Expand Up @@ -2078,9 +2079,8 @@ class Http2Stream extends Duplex {
// close, it is still possible to queue up PRIORITY and RST_STREAM frames,
// but no DATA and HEADERS frames may be sent.
close(code = NGHTTP2_NO_ERROR, callback) {
validateNumber(code, 'code');
if (code < 0 || code > kMaxInt)
throw new ERR_OUT_OF_RANGE('code', `>= 0 && <= ${kMaxInt}`, code);
validateInteger(code, 'code', 0, kMaxInt);

if (callback !== undefined && typeof callback !== 'function')
throw new ERR_INVALID_CALLBACK(callback);

Expand Down
21 changes: 21 additions & 0 deletions test/parallel/test-http2-invalidargtypes-errors.js
Expand Up @@ -18,6 +18,27 @@ server.on('stream', common.mustCall((stream) => {
"Received type string ('string')"
}
);
assert.throws(
() => stream.close(1.01),
{
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError',
message: 'The value of "code" is out of range. It must be an integer. ' +
'Received 1.01'
}
);
[-1, 2 ** 32].forEach((code) => {
assert.throws(
() => stream.close(code),
{
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError',
message: 'The value of "code" is out of range. ' +
'It must be >= 0 && <= 4294967295. ' +
`Received ${code}`
}
);
});
stream.respond();
stream.end('ok');
}));
Expand Down