summaryrefslogtreecommitdiff
path: root/test/parallel/test-tls-generic-stream.js
blob: d4e5427acae11093f1fcb937a4ca94b09de465da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
'use strict';
const common = require('../common');
if (!common.hasCrypto)
  common.skip('missing crypto');

const fixtures = require('../common/fixtures');
const makeDuplexPair = require('../common/duplexpair');
const assert = require('assert');
const { TLSSocket, connect } = require('tls');

const key = fixtures.readKey('agent1-key.pem');
const cert = fixtures.readKey('agent1-cert.pem');
const ca = fixtures.readKey('ca1-cert.pem');

const { clientSide, serverSide } = makeDuplexPair();

const clientTLS = connect({
  socket: clientSide,
  ca,
  host: 'agent1'  // Hostname from certificate
});
const serverTLS = new TLSSocket(serverSide, {
  isServer: true,
  key,
  cert,
  ca
});

assert.strictEqual(clientTLS.connecting, false);
assert.strictEqual(serverTLS.connecting, false);

clientTLS.on('secureConnect', common.mustCall(() => {
  clientTLS.write('foobar', common.mustCall(() => {
    assert.strictEqual(serverTLS.read().toString(), 'foobar');
    assert.strictEqual(clientTLS._handle.writeQueueSize, 0);
  }));
  assert.ok(clientTLS._handle.writeQueueSize > 0);
}));