• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common');
4if (!common.hasCrypto)
5  common.skip('missing crypto');
6
7const assert = require('assert');
8const tls = require('tls');
9const net = require('net');
10const { fork } = require('child_process');
11
12const tmpdir = require('../common/tmpdir');
13
14// Run in a child process because the PIPE file descriptor stays open until
15// Node.js completes, blocking the tmpdir and preventing cleanup.
16
17if (process.argv[2] !== 'child') {
18  // Parent
19  tmpdir.refresh();
20
21  // Run test
22  const child = fork(__filename, ['child'], { stdio: 'inherit' });
23  child.on('exit', common.mustCall(function(code) {
24    assert.strictEqual(code, 0);
25  }));
26
27  return;
28}
29
30// Child
31const server = net.createServer((c) => {
32  c.end();
33}).listen(common.PIPE, common.mustCall(() => {
34  let errored = false;
35  tls.connect({ path: common.PIPE })
36    .once('error', common.mustCall((e) => {
37      assert.strictEqual(e.code, 'ECONNRESET');
38      assert.strictEqual(e.path, common.PIPE);
39      assert.strictEqual(e.port, undefined);
40      assert.strictEqual(e.host, undefined);
41      assert.strictEqual(e.localAddress, undefined);
42      server.close();
43      errored = true;
44    }))
45    .on('close', common.mustCall(() => {
46      assert.strictEqual(errored, true);
47    }));
48}));
49