11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ci
41cb0ef41Sopenharmony_ciif (!common.hasCrypto)
51cb0ef41Sopenharmony_ci  common.skip('missing crypto');
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ciconst assert = require('assert');
81cb0ef41Sopenharmony_ciconst tls = require('tls');
91cb0ef41Sopenharmony_ciconst net = require('net');
101cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures');
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_cilet out = '';
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_ciconst server = tls.createServer({
151cb0ef41Sopenharmony_ci  key: fixtures.readKey('agent1-key.pem'),
161cb0ef41Sopenharmony_ci  cert: fixtures.readKey('agent1-cert.pem')
171cb0ef41Sopenharmony_ci}, function(c) {
181cb0ef41Sopenharmony_ci  c.end('hello');
191cb0ef41Sopenharmony_ci}).listen(0, function() {
201cb0ef41Sopenharmony_ci  const socket = new net.Socket();
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_ci  const s = tls.connect({
231cb0ef41Sopenharmony_ci    socket: socket,
241cb0ef41Sopenharmony_ci    rejectUnauthorized: false
251cb0ef41Sopenharmony_ci  }, function() {
261cb0ef41Sopenharmony_ci    s.on('data', function(chunk) {
271cb0ef41Sopenharmony_ci      out += chunk;
281cb0ef41Sopenharmony_ci    });
291cb0ef41Sopenharmony_ci    s.on('end', function() {
301cb0ef41Sopenharmony_ci      s.destroy();
311cb0ef41Sopenharmony_ci      server.close();
321cb0ef41Sopenharmony_ci    });
331cb0ef41Sopenharmony_ci  });
341cb0ef41Sopenharmony_ci
351cb0ef41Sopenharmony_ci  socket.connect(this.address().port);
361cb0ef41Sopenharmony_ci});
371cb0ef41Sopenharmony_ci
381cb0ef41Sopenharmony_ciprocess.on('exit', function() {
391cb0ef41Sopenharmony_ci  assert.strictEqual(out, 'hello');
401cb0ef41Sopenharmony_ci});
41