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({ 25 allowHalfOpen: false, 26 read() {} 27 }); 28 const socket = new tls.TLSSocket(duplex, { allowHalfOpen: true }); 29 assert.strictEqual(socket.allowHalfOpen, false); 30} 31 32{ 33 const socket = new tls.TLSSocket(); 34 assert.strictEqual(socket.allowHalfOpen, false); 35} 36 37{ 38 // The option is honored when the `socket` argument is not specified. 39 const socket = new tls.TLSSocket(undefined, { allowHalfOpen: true }); 40 assert.strictEqual(socket.allowHalfOpen, true); 41} 42