1'use strict'; 2 3const common = require('../common'); 4if (!common.hasCrypto) 5 common.skip('missing crypto'); 6 7const assert = require('assert'); 8const http2 = require('http2'); 9 10// Error if invalid options are passed to createSecureServer. 11const invalidOptions = [() => {}, 1, 'test', null, Symbol('test')]; 12invalidOptions.forEach((invalidOption) => { 13 assert.throws( 14 () => http2.createSecureServer(invalidOption), 15 { 16 name: 'TypeError', 17 code: 'ERR_INVALID_ARG_TYPE', 18 message: 'The "options" argument must be of type object.' + 19 common.invalidArgTypeHelper(invalidOption) 20 } 21 ); 22}); 23 24// Error if invalid options.settings are passed to createSecureServer. 25invalidOptions.forEach((invalidSettingsOption) => { 26 assert.throws( 27 () => http2.createSecureServer({ settings: invalidSettingsOption }), 28 { 29 name: 'TypeError', 30 code: 'ERR_INVALID_ARG_TYPE', 31 message: 'The "options.settings" property must be of type object.' + 32 common.invalidArgTypeHelper(invalidSettingsOption) 33 } 34 ); 35}); 36 37// Test that http2.createSecureServer validates input options. 38Object.entries({ 39 maxSessionInvalidFrames: [ 40 { 41 val: -1, 42 err: { 43 name: 'RangeError', 44 code: 'ERR_OUT_OF_RANGE', 45 }, 46 }, 47 { 48 val: Number.NEGATIVE_INFINITY, 49 err: { 50 name: 'RangeError', 51 code: 'ERR_OUT_OF_RANGE', 52 }, 53 }, 54 ], 55 maxSessionRejectedStreams: [ 56 { 57 val: -1, 58 err: { 59 name: 'RangeError', 60 code: 'ERR_OUT_OF_RANGE', 61 }, 62 }, 63 { 64 val: Number.NEGATIVE_INFINITY, 65 err: { 66 name: 'RangeError', 67 code: 'ERR_OUT_OF_RANGE', 68 }, 69 }, 70 ], 71}).forEach(([opt, tests]) => { 72 tests.forEach(({ val, err }) => { 73 assert.throws( 74 () => http2.createSecureServer({ [opt]: val }), 75 err 76 ); 77 }); 78}); 79