node/test/parallel/test-tls-socket-allow-half-open-option.js
Luigi Pinca c3b8e50143 tls: allow client-side sockets to be half-opened
Make `tls.connect()` support an `allowHalfOpen` option which specifies
whether or not to allow the connection to be half-opened when the
`socket` option is not specified.

PR-URL: https://github.com/nodejs/node/pull/27836
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ouyang Yadong <oyydoibh@gmail.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
2019-08-17 06:46:31 +02:00

39 lines
1.1 KiB
JavaScript

'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);
}