summaryrefslogtreecommitdiff
path: root/test/parallel/test-tls-socket-allow-half-open-option.js
diff options
context:
space:
mode:
authorLuigi Pinca <luigipinca@gmail.com>2019-05-23 11:48:52 +0200
committerLuigi Pinca <luigipinca@gmail.com>2019-08-17 06:46:31 +0200
commitc3b8e5014369561d86e32338f622034020c9c79f (patch)
treec8a86853a06d71d52a84198fae8597413ea31110 /test/parallel/test-tls-socket-allow-half-open-option.js
parentf25bbf12556eb5478ea876db825c230d1b1c650c (diff)
downloadandroid-node-v8-c3b8e5014369561d86e32338f622034020c9c79f.tar.gz
android-node-v8-c3b8e5014369561d86e32338f622034020c9c79f.tar.bz2
android-node-v8-c3b8e5014369561d86e32338f622034020c9c79f.zip
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>
Diffstat (limited to 'test/parallel/test-tls-socket-allow-half-open-option.js')
-rw-r--r--test/parallel/test-tls-socket-allow-half-open-option.js38
1 files changed, 38 insertions, 0 deletions
diff --git a/test/parallel/test-tls-socket-allow-half-open-option.js b/test/parallel/test-tls-socket-allow-half-open-option.js
new file mode 100644
index 0000000000..36449a6130
--- /dev/null
+++ b/test/parallel/test-tls-socket-allow-half-open-option.js
@@ -0,0 +1,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);
+}