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 http2 = require('http2'); 81cb0ef41Sopenharmony_ciconst net = require('net'); 91cb0ef41Sopenharmony_ciconst http2util = require('../common/http2'); 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ci// Test that ping flooding causes the session to be torn down 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ciconst kSettings = new http2util.SettingsFrame(); 141cb0ef41Sopenharmony_ciconst kPingAck = new http2util.PingFrame(true); 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ciconst server = http2.createServer(); 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_ciserver.on('stream', common.mustNotCall()); 191cb0ef41Sopenharmony_ciserver.on('session', common.mustCall((session) => { 201cb0ef41Sopenharmony_ci session.on('error', common.expectsError({ 211cb0ef41Sopenharmony_ci code: 'ERR_HTTP2_ERROR', 221cb0ef41Sopenharmony_ci message: 'Protocol error' 231cb0ef41Sopenharmony_ci })); 241cb0ef41Sopenharmony_ci session.on('close', common.mustCall(() => server.close())); 251cb0ef41Sopenharmony_ci})); 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ciserver.listen(0, common.mustCall(() => { 281cb0ef41Sopenharmony_ci const client = net.connect(server.address().port); 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_ci client.on('connect', common.mustCall(() => { 311cb0ef41Sopenharmony_ci client.write(http2util.kClientMagic, () => { 321cb0ef41Sopenharmony_ci client.write(kSettings.data); 331cb0ef41Sopenharmony_ci // Send an unsolicited ping ack 341cb0ef41Sopenharmony_ci client.write(kPingAck.data); 351cb0ef41Sopenharmony_ci }); 361cb0ef41Sopenharmony_ci })); 371cb0ef41Sopenharmony_ci 381cb0ef41Sopenharmony_ci // An error event may or may not be emitted, depending on operating system 391cb0ef41Sopenharmony_ci // and timing. We do not really care if one is emitted here or not, as the 401cb0ef41Sopenharmony_ci // error on the server side is what we are testing for. Do not make this 411cb0ef41Sopenharmony_ci // a common.mustCall() and there's no need to check the error details. 421cb0ef41Sopenharmony_ci client.on('error', () => {}); 431cb0ef41Sopenharmony_ci})); 44