• 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 events = require('events');
9const fixtures = require('../common/fixtures');
10const { createServer, connect } = require('tls');
11const cert = fixtures.readKey('rsa_cert.crt');
12const key = fixtures.readKey('rsa_private.pem');
13
14events.captureRejections = true;
15
16const server = createServer({ cert, key }, common.mustCall(async (sock) => {
17  server.close();
18
19  const _err = new Error('kaboom');
20  sock.on('error', common.mustCall((err) => {
21    assert.strictEqual(err, _err);
22  }));
23  throw _err;
24}));
25
26server.listen(0, common.mustCall(() => {
27  const sock = connect({
28    port: server.address().port,
29    host: server.address().host,
30    rejectUnauthorized: false
31  });
32
33  sock.on('close', common.mustCall());
34}));
35