11cb0ef41Sopenharmony_ci// Flags: --expose-internals
21cb0ef41Sopenharmony_ci'use strict';
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ciif (!common.hasCrypto)
51cb0ef41Sopenharmony_ci  common.skip('missing crypto');
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ciconst http2 = require('http2');
81cb0ef41Sopenharmony_ciconst tls = require('tls');
91cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures');
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ciconst serverOptions = {
121cb0ef41Sopenharmony_ci  key: fixtures.readKey('agent1-key.pem'),
131cb0ef41Sopenharmony_ci  cert: fixtures.readKey('agent1-cert.pem')
141cb0ef41Sopenharmony_ci};
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_ciconst server = http2.createSecureServer(serverOptions, (req, res) => {
171cb0ef41Sopenharmony_ci  res.end();
181cb0ef41Sopenharmony_ci});
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_ciserver.listen(0, '127.0.0.1', common.mustCall(() => {
211cb0ef41Sopenharmony_ci  const options = {
221cb0ef41Sopenharmony_ci    ALPNProtocols: ['h2'],
231cb0ef41Sopenharmony_ci    host: '127.0.0.1',
241cb0ef41Sopenharmony_ci    servername: 'localhost',
251cb0ef41Sopenharmony_ci    port: server.address().port,
261cb0ef41Sopenharmony_ci    rejectUnauthorized: false
271cb0ef41Sopenharmony_ci  };
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ci  const socket = tls.connect(options, async () => {
301cb0ef41Sopenharmony_ci    socket.once('readable', () => {
311cb0ef41Sopenharmony_ci      const client = http2.connect(
321cb0ef41Sopenharmony_ci        'https://localhost:' + server.address().port,
331cb0ef41Sopenharmony_ci        { ...options, createConnection: () => socket }
341cb0ef41Sopenharmony_ci      );
351cb0ef41Sopenharmony_ci
361cb0ef41Sopenharmony_ci      client.once('remoteSettings', common.mustCall(() => {
371cb0ef41Sopenharmony_ci        const req = client.request({
381cb0ef41Sopenharmony_ci          ':path': '/'
391cb0ef41Sopenharmony_ci        });
401cb0ef41Sopenharmony_ci        req.on('data', () => req.resume());
411cb0ef41Sopenharmony_ci        req.on('end', common.mustCall(() => {
421cb0ef41Sopenharmony_ci          client.close();
431cb0ef41Sopenharmony_ci          req.close();
441cb0ef41Sopenharmony_ci          server.close();
451cb0ef41Sopenharmony_ci        }));
461cb0ef41Sopenharmony_ci        req.end();
471cb0ef41Sopenharmony_ci      }));
481cb0ef41Sopenharmony_ci    });
491cb0ef41Sopenharmony_ci  });
501cb0ef41Sopenharmony_ci}));
51