• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common');
4if (!common.hasCrypto)
5  common.skip('missing crypto');
6
7const fixtures = require('../common/fixtures');
8const tls = require('tls');
9const net = require('net');
10
11// This test ensures that when tls sockets are created with `allowHalfOpen`,
12// they won't hang.
13const key = fixtures.readKey('agent1-key.pem');
14const cert = fixtures.readKey('agent1-cert.pem');
15const ca = fixtures.readKey('ca1-cert.pem');
16const options = {
17  key,
18  cert,
19  ca: [ca],
20};
21
22const server = tls.createServer(options, common.mustCall((conn) => {
23  conn.write('hello', common.mustCall());
24  conn.on('data', common.mustCall());
25  conn.on('end', common.mustCall());
26  conn.on('data', common.mustCall());
27  conn.on('close', common.mustCall());
28  conn.end();
29})).listen(0, common.mustCall(() => {
30  const netSocket = new net.Socket({
31    allowHalfOpen: true,
32  });
33
34  const socket = tls.connect({
35    socket: netSocket,
36    rejectUnauthorized: false,
37  });
38
39  const { port, address } = server.address();
40
41  // Doing `net.Socket.connect()` after `tls.connect()` will make tls module
42  // wrap the socket in StreamWrap.
43  netSocket.connect({
44    port,
45    address,
46  });
47
48  socket.on('secureConnect', common.mustCall());
49  socket.on('end', common.mustCall());
50  socket.on('data', common.mustCall());
51  socket.on('close', common.mustCall(() => {
52    server.close();
53  }));
54
55  socket.write('hello');
56  socket.end();
57}));
58