11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci// Test the `allowHalfOpen` option of the `tls.TLSSocket` constructor.
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ciif (!common.hasCrypto)
81cb0ef41Sopenharmony_ci  common.skip('missing crypto');
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ciconst assert = require('assert');
111cb0ef41Sopenharmony_ciconst net = require('net');
121cb0ef41Sopenharmony_ciconst stream = require('stream');
131cb0ef41Sopenharmony_ciconst tls = require('tls');
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ci{
161cb0ef41Sopenharmony_ci  // The option is ignored when the `socket` argument is a `net.Socket`.
171cb0ef41Sopenharmony_ci  const socket = new tls.TLSSocket(new net.Socket(), { allowHalfOpen: true });
181cb0ef41Sopenharmony_ci  assert.strictEqual(socket.allowHalfOpen, false);
191cb0ef41Sopenharmony_ci}
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ci{
221cb0ef41Sopenharmony_ci  // The option is ignored when the `socket` argument is a generic
231cb0ef41Sopenharmony_ci  // `stream.Duplex`.
241cb0ef41Sopenharmony_ci  const duplex = new stream.Duplex({
251cb0ef41Sopenharmony_ci    allowHalfOpen: false,
261cb0ef41Sopenharmony_ci    read() {}
271cb0ef41Sopenharmony_ci  });
281cb0ef41Sopenharmony_ci  const socket = new tls.TLSSocket(duplex, { allowHalfOpen: true });
291cb0ef41Sopenharmony_ci  assert.strictEqual(socket.allowHalfOpen, false);
301cb0ef41Sopenharmony_ci}
311cb0ef41Sopenharmony_ci
321cb0ef41Sopenharmony_ci{
331cb0ef41Sopenharmony_ci  const socket = new tls.TLSSocket();
341cb0ef41Sopenharmony_ci  assert.strictEqual(socket.allowHalfOpen, false);
351cb0ef41Sopenharmony_ci}
361cb0ef41Sopenharmony_ci
371cb0ef41Sopenharmony_ci{
381cb0ef41Sopenharmony_ci  // The option is honored when the `socket` argument is not specified.
391cb0ef41Sopenharmony_ci  const socket = new tls.TLSSocket(undefined, { allowHalfOpen: true });
401cb0ef41Sopenharmony_ci  assert.strictEqual(socket.allowHalfOpen, true);
411cb0ef41Sopenharmony_ci}
42