From 6da56e91a3bdffa1201b3c1f1074eaafe96c41e2 Mon Sep 17 00:00:00 2001 From: ZYSzys Date: Tue, 19 Nov 2019 15:38:25 +0800 Subject: [PATCH] test: add test for options validation of createServer PR-URL: https://github.com/nodejs/node/pull/30541 Reviewed-By: Luigi Pinca Reviewed-By: Ruben Bridgewater Reviewed-By: Colin Ihrig --- ...test-http2-createsecureserver-nooptions.js | 22 ------------ .../test-http2-createsecureserver-options.js | 35 +++++++++++++++++++ .../test-http2-createserver-options.js | 35 +++++++++++++++++++ 3 files changed, 70 insertions(+), 22 deletions(-) delete mode 100644 test/parallel/test-http2-createsecureserver-nooptions.js create mode 100644 test/parallel/test-http2-createsecureserver-options.js create mode 100644 test/parallel/test-http2-createserver-options.js diff --git a/test/parallel/test-http2-createsecureserver-nooptions.js b/test/parallel/test-http2-createsecureserver-nooptions.js deleted file mode 100644 index 22a7562388c75a..00000000000000 --- a/test/parallel/test-http2-createsecureserver-nooptions.js +++ /dev/null @@ -1,22 +0,0 @@ -'use strict'; - -const common = require('../common'); -if (!common.hasCrypto) - common.skip('missing crypto'); - -const assert = require('assert'); -const http2 = require('http2'); - -// Error if options are not passed to createSecureServer -const invalidOptions = [() => {}, 1, 'test', null]; -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}` - } - ); -}); diff --git a/test/parallel/test-http2-createsecureserver-options.js b/test/parallel/test-http2-createsecureserver-options.js new file mode 100644 index 00000000000000..4ef85a45b5b84b --- /dev/null +++ b/test/parallel/test-http2-createsecureserver-options.js @@ -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}` + } + ); +}); diff --git a/test/parallel/test-http2-createserver-options.js b/test/parallel/test-http2-createserver-options.js new file mode 100644 index 00000000000000..d322506f55e3e0 --- /dev/null +++ b/test/parallel/test-http2-createserver-options.js @@ -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}` + } + ); +});