Skip to content

Commit

Permalink
test: send a bad record only after connection done
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
sam-github authored and addaleax committed Feb 7, 2019
1 parent ace267b commit 898cf78
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions test/parallel/test-tls-alert-handling.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ server.listen(0, common.mustCall(function() {
sendClient();
}));

server.on('tlsClientError', common.mustNotCall());

server.on('error', common.mustNotCall());

function sendClient() {
const client = tls.connect(server.address().port, {
Expand Down Expand Up @@ -73,8 +76,10 @@ function sendBADTLSRecord() {
socket: socket,
rejectUnauthorized: false
}, common.mustCall(function() {
socket.write(BAD_RECORD);
socket.end();
client.write('x');
client.on('data', (data) => {
socket.end(BAD_RECORD);
});
}));
client.on('error', common.mustCall());
}

0 comments on commit 898cf78

Please sign in to comment.