11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ci// This test ensures that the Http2SecureServer and Http2Server 41cb0ef41Sopenharmony_ci// settings are updated when the setting object is valid. 51cb0ef41Sopenharmony_ci// When the setting object is invalid, this test ensures that 61cb0ef41Sopenharmony_ci// updateSettings throws an exception. 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ciconst common = require('../common'); 91cb0ef41Sopenharmony_ciif (!common.hasCrypto) { common.skip('missing crypto'); } 101cb0ef41Sopenharmony_ciconst assert = require('assert'); 111cb0ef41Sopenharmony_ciconst http2 = require('http2'); 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_citestUpdateSettingsWith({ 141cb0ef41Sopenharmony_ci server: http2.createSecureServer(), 151cb0ef41Sopenharmony_ci newServerSettings: { 161cb0ef41Sopenharmony_ci 'headerTableSize': 1, 171cb0ef41Sopenharmony_ci 'initialWindowSize': 1, 181cb0ef41Sopenharmony_ci 'maxConcurrentStreams': 1, 191cb0ef41Sopenharmony_ci 'maxHeaderListSize': 1, 201cb0ef41Sopenharmony_ci 'maxFrameSize': 16385, 211cb0ef41Sopenharmony_ci 'enablePush': false, 221cb0ef41Sopenharmony_ci 'enableConnectProtocol': true 231cb0ef41Sopenharmony_ci } 241cb0ef41Sopenharmony_ci}); 251cb0ef41Sopenharmony_citestUpdateSettingsWith({ 261cb0ef41Sopenharmony_ci server: http2.createServer(), 271cb0ef41Sopenharmony_ci newServerSettings: { 281cb0ef41Sopenharmony_ci 'enablePush': false 291cb0ef41Sopenharmony_ci } 301cb0ef41Sopenharmony_ci}); 311cb0ef41Sopenharmony_ci 321cb0ef41Sopenharmony_cifunction testUpdateSettingsWith({ server, newServerSettings }) { 331cb0ef41Sopenharmony_ci const oldServerSettings = getServerSettings(server); 341cb0ef41Sopenharmony_ci assert.notDeepStrictEqual(oldServerSettings, newServerSettings); 351cb0ef41Sopenharmony_ci server.updateSettings(newServerSettings); 361cb0ef41Sopenharmony_ci const updatedServerSettings = getServerSettings(server); 371cb0ef41Sopenharmony_ci assert.deepStrictEqual(updatedServerSettings, { ...oldServerSettings, 381cb0ef41Sopenharmony_ci ...newServerSettings }); 391cb0ef41Sopenharmony_ci assert.throws(() => server.updateSettings(''), { 401cb0ef41Sopenharmony_ci message: 'The "settings" argument must be of type object. ' + 411cb0ef41Sopenharmony_ci 'Received type string (\'\')', 421cb0ef41Sopenharmony_ci code: 'ERR_INVALID_ARG_TYPE', 431cb0ef41Sopenharmony_ci name: 'TypeError' 441cb0ef41Sopenharmony_ci }); 451cb0ef41Sopenharmony_ci assert.throws(() => server.updateSettings({ 461cb0ef41Sopenharmony_ci 'maxHeaderListSize': 'foo' 471cb0ef41Sopenharmony_ci }), { 481cb0ef41Sopenharmony_ci message: 'Invalid value for setting "maxHeaderListSize": foo', 491cb0ef41Sopenharmony_ci code: 'ERR_HTTP2_INVALID_SETTING_VALUE', 501cb0ef41Sopenharmony_ci name: 'RangeError' 511cb0ef41Sopenharmony_ci }); 521cb0ef41Sopenharmony_ci} 531cb0ef41Sopenharmony_ci 541cb0ef41Sopenharmony_cifunction getServerSettings(server) { 551cb0ef41Sopenharmony_ci const options = Object 561cb0ef41Sopenharmony_ci .getOwnPropertySymbols(server) 571cb0ef41Sopenharmony_ci .find((s) => s.toString() === 'Symbol(options)'); 581cb0ef41Sopenharmony_ci return server[options].settings; 591cb0ef41Sopenharmony_ci} 60