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: add test for options validation of createServer #30541

Closed
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
2 changes: 0 additions & 2 deletions lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -2932,7 +2932,6 @@ Object.defineProperty(connect, promisify.custom, {
});

function createSecureServer(options, handler) {
assertIsObject(options, 'options');
return new Http2SecureServer(options, handler);
}

Expand All @@ -2941,7 +2940,6 @@ function createServer(options, handler) {
handler = options;
options = {};
}
assertIsObject(options, 'options');
return new Http2Server(options, handler);
}

Expand Down
22 changes: 0 additions & 22 deletions test/parallel/test-http2-createsecureserver-nooptions.js

This file was deleted.

35 changes: 35 additions & 0 deletions test/parallel/test-http2-createsecureserver-options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'use strict';

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

const assert = require('assert');
const http2 = require('http2');

// Error if invalid options are passed to createSecureServer
const invalidOptions = [() => {}, 1, 'test', null, Symbol('test')];
invalidOptions.forEach((invalidOption) => {
assert.throws(
() => http2.createSecureServer(invalidOption),
{
name: 'TypeError',
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "options" argument must be of type Object. Received ' +
`type ${typeof invalidOption}`
}
);
});

// Error if invalid options.settings are passed to createSecureServer
invalidOptions.forEach((invalidSettingsOption) => {
assert.throws(
() => http2.createSecureServer({ settings: invalidSettingsOption }),
{
name: 'TypeError',
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "options.settings" property must be of type Object. ' +
`Received type ${typeof invalidSettingsOption}`
}
);
});
35 changes: 35 additions & 0 deletions test/parallel/test-http2-createserver-options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'use strict';

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

const assert = require('assert');
const http2 = require('http2');

// Error if invalid options are passed to createServer
const invalidOptions = [1, true, 'test', null, Symbol('test')];
invalidOptions.forEach((invalidOption) => {
assert.throws(
() => http2.createServer(invalidOption),
{
name: 'TypeError',
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "options" argument must be of type Object. Received ' +
`type ${typeof invalidOption}`
}
);
});

// Error if invalid options.settings are passed to createServer
invalidOptions.forEach((invalidSettingsOption) => {
assert.throws(
() => http2.createServer({ settings: invalidSettingsOption }),
{
name: 'TypeError',
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "options.settings" property must be of type Object. ' +
`Received type ${typeof invalidSettingsOption}`
}
);
});