• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common');
4if (!common.hasCrypto)
5  common.skip('missing crypto');
6
7if (!common.hasIPv6)
8  common.skip('IPv6 support required');
9
10const initHooks = require('./init-hooks');
11const verifyGraph = require('./verify-graph');
12const tls = require('tls');
13const fixtures = require('../common/fixtures');
14
15const hooks = initHooks();
16hooks.enable();
17
18//
19// Creating server and listening on port
20//
21const server = tls
22  .createServer({
23    cert: fixtures.readKey('rsa_cert.crt'),
24    key: fixtures.readKey('rsa_private.pem')
25  })
26  .on('listening', common.mustCall(onlistening))
27  .on('secureConnection', common.mustCall(onsecureConnection))
28  .listen(0);
29
30function onlistening() {
31  //
32  // Creating client and connecting it to server
33  //
34  tls
35    .connect(server.address().port, { rejectUnauthorized: false })
36    .on('secureConnect', common.mustCall(onsecureConnect));
37}
38
39function onsecureConnection() {}
40
41function onsecureConnect() {
42  // end() client socket, which causes slightly different hook events than
43  // destroy(), but with TLS1.3 destroy() rips the connection down before the
44  // server completes the handshake.
45  this.end();
46
47  // Closing server
48  server.close(common.mustCall(onserverClosed));
49}
50
51function onserverClosed() {}
52
53process.on('exit', onexit);
54
55function onexit() {
56  hooks.disable();
57
58  verifyGraph(
59    hooks,
60    [ { type: 'TCPSERVERWRAP', id: 'tcpserver:1', triggerAsyncId: null },
61      { type: 'TCPWRAP', id: 'tcp:1', triggerAsyncId: 'tcpserver:1' },
62      { type: 'TLSWRAP', id: 'tls:1', triggerAsyncId: 'tcpserver:1' },
63      { type: 'GETADDRINFOREQWRAP',
64        id: 'getaddrinforeq:1', triggerAsyncId: 'tls:1' },
65      { type: 'TCPCONNECTWRAP',
66        id: 'tcpconnect:1', triggerAsyncId: 'tcp:1' },
67      { type: 'TCPWRAP', id: 'tcp:2', triggerAsyncId: 'tcpserver:1' },
68      { type: 'TLSWRAP', id: 'tls:2', triggerAsyncId: 'tcpserver:1' },
69    ]
70  );
71}
72