-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]> Reviewed-By: James M Snell <[email protected]>
- Loading branch information
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
if (!common.hasCrypto) | ||
common.skip('missing crypto'); | ||
|
||
const fixtures = require('../common/fixtures'); | ||
const tls = require('tls'); | ||
const net = require('net'); | ||
|
||
// This test ensures that when tls sockets are created with `allowHalfOpen`, | ||
// they won't hang. | ||
const key = fixtures.readKey('agent1-key.pem'); | ||
const cert = fixtures.readKey('agent1-cert.pem'); | ||
const ca = fixtures.readKey('ca1-cert.pem'); | ||
const options = { | ||
key, | ||
cert, | ||
ca: [ca], | ||
}; | ||
|
||
const server = tls.createServer(options, common.mustCall((conn) => { | ||
conn.write('hello'); | ||
conn.on('data', common.mustCall()); | ||
conn.end(); | ||
})).listen(0, common.mustCall(() => { | ||
const netSocket = new net.Socket({ | ||
allowHalfOpen: true, | ||
}); | ||
|
||
const socket = tls.connect({ | ||
socket: netSocket, | ||
rejectUnauthorized: false, | ||
}); | ||
|
||
const { port, address } = server.address(); | ||
|
||
// Doing `net.Socket.connect()` after `tls.connect()` will make tls module | ||
// wrap the socket in StreamWrap. | ||
netSocket.connect({ | ||
port, | ||
address, | ||
}); | ||
|
||
socket.on('end', common.mustCall()); | ||
socket.on('data', common.mustCall()); | ||
socket.on('close', common.mustCall(() => { | ||
server.close(); | ||
})); | ||
|
||
socket.write('hello'); | ||
socket.end(); | ||
})); |