11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ciif (!common.hasCrypto)
51cb0ef41Sopenharmony_ci  common.skip('missing crypto');
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ciconst assert = require('assert');
81cb0ef41Sopenharmony_ciconst net = require('net');
91cb0ef41Sopenharmony_ciconst tls = require('tls');
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ciconst server = net.createServer((c) => {
121cb0ef41Sopenharmony_ci  c.end();
131cb0ef41Sopenharmony_ci}).listen(common.mustCall(() => {
141cb0ef41Sopenharmony_ci  const port = server.address().port;
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_ci  const socket = new net.Socket();
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_ci  let errored = false;
191cb0ef41Sopenharmony_ci  tls.connect({ socket })
201cb0ef41Sopenharmony_ci    .once('error', common.mustCall((e) => {
211cb0ef41Sopenharmony_ci      assert.strictEqual(e.code, 'ECONNRESET');
221cb0ef41Sopenharmony_ci      assert.strictEqual(e.path, undefined);
231cb0ef41Sopenharmony_ci      assert.strictEqual(e.host, undefined);
241cb0ef41Sopenharmony_ci      assert.strictEqual(e.port, undefined);
251cb0ef41Sopenharmony_ci      assert.strictEqual(e.localAddress, undefined);
261cb0ef41Sopenharmony_ci      errored = true;
271cb0ef41Sopenharmony_ci      server.close();
281cb0ef41Sopenharmony_ci    }))
291cb0ef41Sopenharmony_ci    .on('close', common.mustCall(() => {
301cb0ef41Sopenharmony_ci      assert.strictEqual(errored, true);
311cb0ef41Sopenharmony_ci    }));
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_ci  socket.connect(port);
341cb0ef41Sopenharmony_ci}));
35