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

test: http2 ERR_INVALID_ARG_TYPE tests #15766

Closed
wants to merge 1 commit 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 13 additions & 35 deletions test/parallel/test-http2-createsecureserver-nooptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,17 @@ if (!common.hasCrypto)

const http2 = require('http2');

// Error if options are not passed to createSecureServer

common.expectsError(
() => http2.createSecureServer(),
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError
});

common.expectsError(
() => http2.createSecureServer(() => {}),
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError
});
const invalidOptions = [() => {}, 1, 'test', null, undefined];
const invalidArgTypeError = {
type: TypeError,
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "options" argument must be of type object'
};

common.expectsError(
() => http2.createSecureServer(1),
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError
});

common.expectsError(
() => http2.createSecureServer('test'),
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError
});

common.expectsError(
() => http2.createSecureServer(null),
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError
});
// Error if options are not passed to createSecureServer
invalidOptions.forEach((invalidOption) =>
common.expectsError(
() => http2.createSecureServer(invalidOption),
invalidArgTypeError
)
);
43 changes: 43 additions & 0 deletions test/parallel/test-http2-invalidargtypes-errors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
'use strict';

const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const http2 = require('http2');

const server = http2.createServer();

server.on(
'stream',
common.mustCall((stream) => {
const invalidArgTypeError = (param, type) => ({
type: TypeError,
code: 'ERR_INVALID_ARG_TYPE',
message: `The "${param}" argument must be of type ${type}`
});
common.expectsError(
() => stream.session.priority(undefined, {}),
invalidArgTypeError('stream', 'Http2Stream')
);
common.expectsError(
() => stream.session.rstStream(undefined),
invalidArgTypeError('stream', 'Http2Stream')
);
common.expectsError(
() => stream.session.rstStream(stream, 'string'),
invalidArgTypeError('code', 'number')
);
stream.session.destroy();
})
);

server.listen(
0,
common.mustCall(() => {
const client = http2.connect(`http://localhost:${server.address().port}`);
const req = client.request();
req.resume();
req.on('end', common.mustCall(() => server.close()));
req.end();
})
);