11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ci// Test asynchronous SNI+OCSP on TLSSocket created with `server` set to
41cb0ef41Sopenharmony_ci// `net.Server` instead of `tls.Server`
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ciconst common = require('../common');
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ciif (!common.hasCrypto)
91cb0ef41Sopenharmony_ci  common.skip('missing crypto');
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ciconst assert = require('assert');
121cb0ef41Sopenharmony_ciconst net = require('net');
131cb0ef41Sopenharmony_ciconst tls = require('tls');
141cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures');
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_ciconst key = fixtures.readKey('agent1-key.pem');
171cb0ef41Sopenharmony_ciconst cert = fixtures.readKey('agent1-cert.pem');
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ciconst server = net.createServer(common.mustCall((s) => {
201cb0ef41Sopenharmony_ci  const tlsSocket = new tls.TLSSocket(s, {
211cb0ef41Sopenharmony_ci    isServer: true,
221cb0ef41Sopenharmony_ci    server: server,
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_ci    secureContext: tls.createSecureContext({ key, cert }),
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_ci    SNICallback: common.mustCall((hostname, callback) => {
271cb0ef41Sopenharmony_ci      assert.strictEqual(hostname, 'test.test');
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ci      callback(null, null);
301cb0ef41Sopenharmony_ci    })
311cb0ef41Sopenharmony_ci  });
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_ci  tlsSocket.on('secure', common.mustCall(() => {
341cb0ef41Sopenharmony_ci    tlsSocket.end();
351cb0ef41Sopenharmony_ci    server.close();
361cb0ef41Sopenharmony_ci  }));
371cb0ef41Sopenharmony_ci})).listen(0, () => {
381cb0ef41Sopenharmony_ci  const opts = {
391cb0ef41Sopenharmony_ci    servername: 'test.test',
401cb0ef41Sopenharmony_ci    port: server.address().port,
411cb0ef41Sopenharmony_ci    rejectUnauthorized: false,
421cb0ef41Sopenharmony_ci    requestOCSP: true
431cb0ef41Sopenharmony_ci  };
441cb0ef41Sopenharmony_ci
451cb0ef41Sopenharmony_ci  tls.connect(opts, function() {
461cb0ef41Sopenharmony_ci    this.end();
471cb0ef41Sopenharmony_ci  });
481cb0ef41Sopenharmony_ci});
49