11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciif (!common.hasCrypto)
41cb0ef41Sopenharmony_ci  common.skip('missing crypto');
51cb0ef41Sopenharmony_ciconst { readSync } = require('../common/fixtures');
61cb0ef41Sopenharmony_ciconst net = require('net');
71cb0ef41Sopenharmony_ciconst http2 = require('http2');
81cb0ef41Sopenharmony_ciconst { once } = require('events');
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ciasync function main() {
111cb0ef41Sopenharmony_ci  const blobWithEmptyFrame = readSync('emptyframe.http2');
121cb0ef41Sopenharmony_ci  const server = net.createServer((socket) => {
131cb0ef41Sopenharmony_ci    socket.once('data', () => {
141cb0ef41Sopenharmony_ci      socket.end(blobWithEmptyFrame);
151cb0ef41Sopenharmony_ci    });
161cb0ef41Sopenharmony_ci  }).listen(0);
171cb0ef41Sopenharmony_ci  await once(server, 'listening');
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ci  for (const maxSessionInvalidFrames of [0, 2]) {
201cb0ef41Sopenharmony_ci    const client = http2.connect(`http://localhost:${server.address().port}`, {
211cb0ef41Sopenharmony_ci      maxSessionInvalidFrames
221cb0ef41Sopenharmony_ci    });
231cb0ef41Sopenharmony_ci    const stream = client.request({
241cb0ef41Sopenharmony_ci      ':method': 'GET',
251cb0ef41Sopenharmony_ci      ':path': '/'
261cb0ef41Sopenharmony_ci    });
271cb0ef41Sopenharmony_ci    if (maxSessionInvalidFrames) {
281cb0ef41Sopenharmony_ci      stream.on('error', common.mustNotCall());
291cb0ef41Sopenharmony_ci      client.on('error', common.mustNotCall());
301cb0ef41Sopenharmony_ci    } else {
311cb0ef41Sopenharmony_ci      const expected = {
321cb0ef41Sopenharmony_ci        code: 'ERR_HTTP2_TOO_MANY_INVALID_FRAMES',
331cb0ef41Sopenharmony_ci        message: 'Too many invalid HTTP/2 frames'
341cb0ef41Sopenharmony_ci      };
351cb0ef41Sopenharmony_ci      stream.on('error', common.expectsError(expected));
361cb0ef41Sopenharmony_ci      client.on('error', common.expectsError(expected));
371cb0ef41Sopenharmony_ci    }
381cb0ef41Sopenharmony_ci    stream.resume();
391cb0ef41Sopenharmony_ci    await new Promise((resolve) => {
401cb0ef41Sopenharmony_ci      stream.once('close', resolve);
411cb0ef41Sopenharmony_ci    });
421cb0ef41Sopenharmony_ci    client.close();
431cb0ef41Sopenharmony_ci  }
441cb0ef41Sopenharmony_ci  server.close();
451cb0ef41Sopenharmony_ci}
461cb0ef41Sopenharmony_ci
471cb0ef41Sopenharmony_cimain().then(common.mustCall());
48