11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../common'); 41cb0ef41Sopenharmony_ciif (!common.hasCrypto) 51cb0ef41Sopenharmony_ci common.skip('missing crypto'); 61cb0ef41Sopenharmony_ciconst assert = require('assert'); 71cb0ef41Sopenharmony_ciconst http2 = require('http2'); 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ciconst server = http2.createServer(); 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ciconst types = [ 121cb0ef41Sopenharmony_ci true, 131cb0ef41Sopenharmony_ci {}, 141cb0ef41Sopenharmony_ci [], 151cb0ef41Sopenharmony_ci null, 161cb0ef41Sopenharmony_ci new Date(), 171cb0ef41Sopenharmony_ci]; 181cb0ef41Sopenharmony_ci 191cb0ef41Sopenharmony_ciserver.on('stream', common.mustCall((stream) => { 201cb0ef41Sopenharmony_ci const session = stream.session; 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_ci for (const input of types) { 231cb0ef41Sopenharmony_ci const received = common.invalidArgTypeHelper(input); 241cb0ef41Sopenharmony_ci assert.throws( 251cb0ef41Sopenharmony_ci () => session.goaway(input), 261cb0ef41Sopenharmony_ci { 271cb0ef41Sopenharmony_ci code: 'ERR_INVALID_ARG_TYPE', 281cb0ef41Sopenharmony_ci name: 'TypeError', 291cb0ef41Sopenharmony_ci message: 'The "code" argument must be of type number.' + 301cb0ef41Sopenharmony_ci received 311cb0ef41Sopenharmony_ci } 321cb0ef41Sopenharmony_ci ); 331cb0ef41Sopenharmony_ci assert.throws( 341cb0ef41Sopenharmony_ci () => session.goaway(0, input), 351cb0ef41Sopenharmony_ci { 361cb0ef41Sopenharmony_ci code: 'ERR_INVALID_ARG_TYPE', 371cb0ef41Sopenharmony_ci name: 'TypeError', 381cb0ef41Sopenharmony_ci message: 'The "lastStreamID" argument must be of type number.' + 391cb0ef41Sopenharmony_ci received 401cb0ef41Sopenharmony_ci } 411cb0ef41Sopenharmony_ci ); 421cb0ef41Sopenharmony_ci assert.throws( 431cb0ef41Sopenharmony_ci () => session.goaway(0, 0, input), 441cb0ef41Sopenharmony_ci { 451cb0ef41Sopenharmony_ci code: 'ERR_INVALID_ARG_TYPE', 461cb0ef41Sopenharmony_ci name: 'TypeError', 471cb0ef41Sopenharmony_ci message: 'The "opaqueData" argument must be an instance of Buffer, ' + 481cb0ef41Sopenharmony_ci `TypedArray, or DataView.${received}` 491cb0ef41Sopenharmony_ci } 501cb0ef41Sopenharmony_ci ); 511cb0ef41Sopenharmony_ci } 521cb0ef41Sopenharmony_ci 531cb0ef41Sopenharmony_ci stream.session.destroy(); 541cb0ef41Sopenharmony_ci})); 551cb0ef41Sopenharmony_ci 561cb0ef41Sopenharmony_ciserver.listen( 571cb0ef41Sopenharmony_ci 0, 581cb0ef41Sopenharmony_ci common.mustCall(() => { 591cb0ef41Sopenharmony_ci const client = http2.connect(`http://localhost:${server.address().port}`); 601cb0ef41Sopenharmony_ci const req = client.request(); 611cb0ef41Sopenharmony_ci req.resume(); 621cb0ef41Sopenharmony_ci req.on('close', common.mustCall(() => { 631cb0ef41Sopenharmony_ci client.close(); 641cb0ef41Sopenharmony_ci server.close(); 651cb0ef41Sopenharmony_ci })); 661cb0ef41Sopenharmony_ci }) 671cb0ef41Sopenharmony_ci); 68