11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ciif (!common.hasCrypto)
51cb0ef41Sopenharmony_ci  common.skip('missing crypto');
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ciconst assert = require('assert');
81cb0ef41Sopenharmony_ciconst http2 = require('http2');
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ci// Error if invalid options are passed to createServer.
111cb0ef41Sopenharmony_ciconst invalidOptions = [1, true, 'test', null, Symbol('test')];
121cb0ef41Sopenharmony_ciinvalidOptions.forEach((invalidOption) => {
131cb0ef41Sopenharmony_ci  assert.throws(
141cb0ef41Sopenharmony_ci    () => http2.createServer(invalidOption),
151cb0ef41Sopenharmony_ci    {
161cb0ef41Sopenharmony_ci      name: 'TypeError',
171cb0ef41Sopenharmony_ci      code: 'ERR_INVALID_ARG_TYPE',
181cb0ef41Sopenharmony_ci      message: 'The "options" argument must be of type object.' +
191cb0ef41Sopenharmony_ci               common.invalidArgTypeHelper(invalidOption)
201cb0ef41Sopenharmony_ci    }
211cb0ef41Sopenharmony_ci  );
221cb0ef41Sopenharmony_ci});
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_ci// Error if invalid options.settings are passed to createServer.
251cb0ef41Sopenharmony_ciinvalidOptions.forEach((invalidSettingsOption) => {
261cb0ef41Sopenharmony_ci  assert.throws(
271cb0ef41Sopenharmony_ci    () => http2.createServer({ settings: invalidSettingsOption }),
281cb0ef41Sopenharmony_ci    {
291cb0ef41Sopenharmony_ci      name: 'TypeError',
301cb0ef41Sopenharmony_ci      code: 'ERR_INVALID_ARG_TYPE',
311cb0ef41Sopenharmony_ci      message: 'The "options.settings" property must be of type object.' +
321cb0ef41Sopenharmony_ci               common.invalidArgTypeHelper(invalidSettingsOption)
331cb0ef41Sopenharmony_ci    }
341cb0ef41Sopenharmony_ci  );
351cb0ef41Sopenharmony_ci});
361cb0ef41Sopenharmony_ci
371cb0ef41Sopenharmony_ci// Test that http2.createServer validates input options.
381cb0ef41Sopenharmony_ciObject.entries({
391cb0ef41Sopenharmony_ci  maxSessionInvalidFrames: [
401cb0ef41Sopenharmony_ci    {
411cb0ef41Sopenharmony_ci      val: -1,
421cb0ef41Sopenharmony_ci      err: {
431cb0ef41Sopenharmony_ci        name: 'RangeError',
441cb0ef41Sopenharmony_ci        code: 'ERR_OUT_OF_RANGE',
451cb0ef41Sopenharmony_ci      },
461cb0ef41Sopenharmony_ci    },
471cb0ef41Sopenharmony_ci    {
481cb0ef41Sopenharmony_ci      val: Number.NEGATIVE_INFINITY,
491cb0ef41Sopenharmony_ci      err: {
501cb0ef41Sopenharmony_ci        name: 'RangeError',
511cb0ef41Sopenharmony_ci        code: 'ERR_OUT_OF_RANGE',
521cb0ef41Sopenharmony_ci      },
531cb0ef41Sopenharmony_ci    },
541cb0ef41Sopenharmony_ci  ],
551cb0ef41Sopenharmony_ci  maxSessionRejectedStreams: [
561cb0ef41Sopenharmony_ci    {
571cb0ef41Sopenharmony_ci      val: -1,
581cb0ef41Sopenharmony_ci      err: {
591cb0ef41Sopenharmony_ci        name: 'RangeError',
601cb0ef41Sopenharmony_ci        code: 'ERR_OUT_OF_RANGE',
611cb0ef41Sopenharmony_ci      },
621cb0ef41Sopenharmony_ci    },
631cb0ef41Sopenharmony_ci    {
641cb0ef41Sopenharmony_ci      val: Number.NEGATIVE_INFINITY,
651cb0ef41Sopenharmony_ci      err: {
661cb0ef41Sopenharmony_ci        name: 'RangeError',
671cb0ef41Sopenharmony_ci        code: 'ERR_OUT_OF_RANGE',
681cb0ef41Sopenharmony_ci      },
691cb0ef41Sopenharmony_ci    },
701cb0ef41Sopenharmony_ci  ]
711cb0ef41Sopenharmony_ci}).forEach(([opt, tests]) => {
721cb0ef41Sopenharmony_ci  tests.forEach(({ val, err }) => {
731cb0ef41Sopenharmony_ci    assert.throws(
741cb0ef41Sopenharmony_ci      () => http2.createServer({ [opt]: val }),
751cb0ef41Sopenharmony_ci      err
761cb0ef41Sopenharmony_ci    );
771cb0ef41Sopenharmony_ci  });
781cb0ef41Sopenharmony_ci});
79