• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common');
4
5// Test the `allowHalfOpen` option of the `tls.TLSSocket` constructor.
6
7if (!common.hasCrypto)
8  common.skip('missing crypto');
9
10const assert = require('assert');
11const net = require('net');
12const stream = require('stream');
13const tls = require('tls');
14
15{
16  // The option is ignored when the `socket` argument is a `net.Socket`.
17  const socket = new tls.TLSSocket(new net.Socket(), { allowHalfOpen: true });
18  assert.strictEqual(socket.allowHalfOpen, false);
19}
20
21{
22  // The option is ignored when the `socket` argument is a generic
23  // `stream.Duplex`.
24  const duplex = new stream.Duplex({ allowHalfOpen: false });
25  const socket = new tls.TLSSocket(duplex, { allowHalfOpen: true });
26  assert.strictEqual(socket.allowHalfOpen, false);
27}
28
29{
30  const socket = new tls.TLSSocket();
31  assert.strictEqual(socket.allowHalfOpen, false);
32}
33
34{
35  // The option is honored when the `socket` argument is not specified.
36  const socket = new tls.TLSSocket(undefined, { allowHalfOpen: true });
37  assert.strictEqual(socket.allowHalfOpen, true);
38}
39