• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3if (!common.hasCrypto)
4  common.skip('missing crypto');
5
6const fixtures = require('../common/fixtures');
7const makeDuplexPair = require('../common/duplexpair');
8const assert = require('assert');
9const { TLSSocket, connect } = require('tls');
10
11const key = fixtures.readKey('agent1-key.pem');
12const cert = fixtures.readKey('agent1-cert.pem');
13const ca = fixtures.readKey('ca1-cert.pem');
14
15const { clientSide, serverSide } = makeDuplexPair();
16
17const clientTLS = connect({
18  socket: clientSide,
19  ca,
20  host: 'agent1'  // Hostname from certificate
21});
22const serverTLS = new TLSSocket(serverSide, {
23  isServer: true,
24  key,
25  cert,
26  ca
27});
28
29assert.strictEqual(clientTLS.connecting, false);
30assert.strictEqual(serverTLS.connecting, false);
31
32clientTLS.on('secureConnect', common.mustCall(() => {
33  clientTLS.write('foobar', common.mustCall(() => {
34    assert.strictEqual(serverTLS.read().toString(), 'foobar');
35    assert.strictEqual(clientTLS._handle.writeQueueSize, 0);
36  }));
37  assert.ok(clientTLS._handle.writeQueueSize > 0);
38}));
39