node/test/parallel/test-http2-client-settings-before-connect.js
Trivikram 0089860757 test: http2 client settings invalid callback
PR-URL: https://github.com/nodejs/node/pull/18850
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2018-02-20 07:52:23 -08:00

69 lines
1.8 KiB
JavaScript

'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const h2 = require('http2');
const server = h2.createServer();
// we use the lower-level API here
server.on('stream', common.mustCall((stream, headers, flags) => {
stream.respond();
stream.end('ok');
}));
server.on('session', common.mustCall((session) => {
session.on('remoteSettings', common.mustCall(2));
}));
server.listen(0, common.mustCall(() => {
const client = h2.connect(`http://localhost:${server.address().port}`);
[
['headerTableSize', -1, RangeError],
['headerTableSize', 2 ** 32, RangeError],
['initialWindowSize', -1, RangeError],
['initialWindowSize', 2 ** 32, RangeError],
['maxFrameSize', 1, RangeError],
['maxFrameSize', 2 ** 24, RangeError],
['maxConcurrentStreams', -1, RangeError],
['maxConcurrentStreams', 2 ** 31, RangeError],
['maxHeaderListSize', -1, RangeError],
['maxHeaderListSize', 2 ** 32, RangeError],
['enablePush', 'a', TypeError],
['enablePush', 1, TypeError],
['enablePush', 0, TypeError],
['enablePush', null, TypeError],
['enablePush', {}, TypeError]
].forEach(([name, value, errorType]) =>
common.expectsError(
() => client.settings({ [name]: value }),
{
code: 'ERR_HTTP2_INVALID_SETTING_VALUE',
type: errorType
}
)
);
[1, true, {}, []].forEach((invalidCallback) =>
common.expectsError(
() => client.settings({}, invalidCallback),
{
type: TypeError,
code: 'ERR_INVALID_CALLBACK',
message: 'Callback must be a function'
}
)
);
client.settings({ maxFrameSize: 1234567 });
const req = client.request();
req.on('response', common.mustCall());
req.resume();
req.on('close', common.mustCall(() => {
server.close();
client.close();
}));
}));