• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common');
4if (!common.hasCrypto)
5  common.skip('missing crypto');
6
7const assert = require('assert');
8const http2 = require('http2');
9const net = require('net');
10const http2util = require('../common/http2');
11const Countdown = require('../common/countdown');
12
13// Test that an unsolicited settings ack is ignored.
14
15const kSettings = new http2util.SettingsFrame();
16const kSettingsAck = new http2util.SettingsFrame(true);
17
18const server = http2.createServer();
19let client;
20
21const countdown = new Countdown(3, () => {
22  client.destroy();
23  server.close();
24});
25
26server.on('stream', common.mustNotCall());
27server.on('session', common.mustCall((session) => {
28  session.on('remoteSettings', common.mustCall(() => countdown.dec()));
29}));
30
31server.listen(0, common.mustCall(() => {
32  client = net.connect(server.address().port);
33
34  // Ensures that the clients settings frames are not sent until the
35  // servers are received, so that the first ack is actually expected.
36  client.once('data', (chunk) => {
37    // The very first chunk of data we get from the server should
38    // be a settings frame.
39    assert.deepStrictEqual(chunk.slice(0, 9), kSettings.data);
40    // The first ack is expected.
41    client.write(kSettingsAck.data, () => countdown.dec());
42    // The second one is not and will be ignored.
43    client.write(kSettingsAck.data, () => countdown.dec());
44  });
45
46  client.on('connect', common.mustCall(() => {
47    client.write(http2util.kClientMagic);
48    client.write(kSettings.data);
49  }));
50}));
51