Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9ad176a

Browse filesBrowse files
oyydMylesBorins
authored andcommitted
test: add a test for tls.Socket with allowHalfOpen
This test ensures that a tls client socket using `StreamWrap` with `allowHalfOpen` option won't hang. PR-URL: #23866 Refs: #23654 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 9aec3e6 commit 9ad176a
Copy full SHA for 9ad176a

File tree

Expand file treeCollapse file tree

1 file changed

+53
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

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

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.