• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3if (!common.hasCrypto)
4  common.skip('missing crypto');
5const fixtures = require('../common/fixtures');
6const assert = require('assert');
7const tls = require('tls');
8
9const options = {
10  key: fixtures.readKey('agent1-key.pem'),
11
12  // NOTE: Certificate Common Name is 'agent1'
13  cert: fixtures.readKey('agent1-cert.pem'),
14
15  // NOTE: TLS 1.3 creates new session ticket **after** handshake so
16  // `getSession()` output will be different even if the session was reused
17  // during the handshake.
18  secureProtocol: 'TLSv1_2_method'
19};
20
21const server = tls.createServer(options, common.mustCall((socket) => {
22  socket.end();
23})).listen(0, common.mustCall(() => {
24  let connected = false;
25  let session = null;
26
27  const client = tls.connect({
28    rejectUnauthorized: false,
29    port: server.address().port,
30  }, common.mustCall(() => {
31    assert(!connected);
32    assert(!session);
33
34    connected = true;
35  }));
36
37  client.on('session', common.mustCall((newSession) => {
38    assert(connected);
39    assert(!session);
40
41    session = newSession;
42
43    client.end();
44    server.close();
45  }));
46}));
47