summaryrefslogtreecommitdiff
path: root/test/parallel/test-tls-socket-allow-half-open-option.js
blob: 36449a6130c6d16ae226d9124f2e99ac3b4a2acc (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');

// Test the `allowHalfOpen` option of the `tls.TLSSocket` constructor.

if (!common.hasCrypto)
  common.skip('missing crypto');

const assert = require('assert');
const net = require('net');
const stream = require('stream');
const tls = require('tls');

{
  // The option is ignored when the `socket` argument is a `net.Socket`.
  const socket = new tls.TLSSocket(new net.Socket(), { allowHalfOpen: true });
  assert.strictEqual(socket.allowHalfOpen, false);
}

{
  // The option is ignored when the `socket` argument is a generic
  // `stream.Duplex`.
  const duplex = new stream.Duplex({ allowHalfOpen: false });
  const socket = new tls.TLSSocket(duplex, { allowHalfOpen: true });
  assert.strictEqual(socket.allowHalfOpen, false);
}

{
  const socket = new tls.TLSSocket();
  assert.strictEqual(socket.allowHalfOpen, false);
}

{
  // The option is honored when the `socket` argument is not specified.
  const socket = new tls.TLSSocket(undefined, { allowHalfOpen: true });
  assert.strictEqual(socket.allowHalfOpen, true);
}