Skip to content

Commit 898cf78

Browse files
sam-githubaddaleax
authored andcommitted
test: send a bad record only after connection done
Connection is known to be completely setup only after data has exchanged, so wait unil data echo before sending a bad record. Otherwise, the bad record could interrupt completion of the server's handshake, and whether the error is emitted on the connection or server is a matter of timing. Also, assert that server errors do not occur. 'error' would crash node with and unhandled event, but 'tlsClientError' is ignored by default. PR-URL: #25508 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent ace267b commit 898cf78

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

test/parallel/test-tls-alert-handling.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ server.listen(0, common.mustCall(function() {
4343
sendClient();
4444
}));
4545

46+
server.on('tlsClientError', common.mustNotCall());
47+
48+
server.on('error', common.mustNotCall());
4649

4750
function sendClient() {
4851
const client = tls.connect(server.address().port, {
@@ -73,8 +76,10 @@ function sendBADTLSRecord() {
7376
socket: socket,
7477
rejectUnauthorized: false
7578
}, common.mustCall(function() {
76-
socket.write(BAD_RECORD);
77-
socket.end();
79+
client.write('x');
80+
client.on('data', (data) => {
81+
socket.end(BAD_RECORD);
82+
});
7883
}));
7984
client.on('error', common.mustCall());
8085
}

0 commit comments

Comments
 (0)