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_ciconst net = require('net'); 101cb0ef41Sopenharmony_ciconst http2util = require('../common/http2'); 111cb0ef41Sopenharmony_ciconst Countdown = require('../common/countdown'); 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ci// Test that an unsolicited settings ack is ignored. 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ciconst kSettings = new http2util.SettingsFrame(); 161cb0ef41Sopenharmony_ciconst kSettingsAck = new http2util.SettingsFrame(true); 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_ciconst server = http2.createServer(); 191cb0ef41Sopenharmony_cilet client; 201cb0ef41Sopenharmony_ci 211cb0ef41Sopenharmony_ciconst countdown = new Countdown(3, () => { 221cb0ef41Sopenharmony_ci client.destroy(); 231cb0ef41Sopenharmony_ci server.close(); 241cb0ef41Sopenharmony_ci}); 251cb0ef41Sopenharmony_ci 261cb0ef41Sopenharmony_ciserver.on('stream', common.mustNotCall()); 271cb0ef41Sopenharmony_ciserver.on('session', common.mustCall((session) => { 281cb0ef41Sopenharmony_ci session.on('remoteSettings', common.mustCall(() => countdown.dec())); 291cb0ef41Sopenharmony_ci})); 301cb0ef41Sopenharmony_ci 311cb0ef41Sopenharmony_ciserver.listen(0, common.mustCall(() => { 321cb0ef41Sopenharmony_ci client = net.connect(server.address().port); 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_ci // Ensures that the clients settings frames are not sent until the 351cb0ef41Sopenharmony_ci // servers are received, so that the first ack is actually expected. 361cb0ef41Sopenharmony_ci client.once('data', (chunk) => { 371cb0ef41Sopenharmony_ci // The very first chunk of data we get from the server should 381cb0ef41Sopenharmony_ci // be a settings frame. 391cb0ef41Sopenharmony_ci assert.deepStrictEqual(chunk.slice(0, 9), kSettings.data); 401cb0ef41Sopenharmony_ci // The first ack is expected. 411cb0ef41Sopenharmony_ci client.write(kSettingsAck.data, () => countdown.dec()); 421cb0ef41Sopenharmony_ci // The second one is not and will be ignored. 431cb0ef41Sopenharmony_ci client.write(kSettingsAck.data, () => countdown.dec()); 441cb0ef41Sopenharmony_ci }); 451cb0ef41Sopenharmony_ci 461cb0ef41Sopenharmony_ci client.on('connect', common.mustCall(() => { 471cb0ef41Sopenharmony_ci client.write(http2util.kClientMagic); 481cb0ef41Sopenharmony_ci client.write(kSettings.data); 491cb0ef41Sopenharmony_ci })); 501cb0ef41Sopenharmony_ci})); 51