From 898cf782f8994e6f326c3d4fb69622c9a817d961 Mon Sep 17 00:00:00 2001 From: Sam Roberts Date: Fri, 1 Feb 2019 12:02:44 -0800 Subject: [PATCH] 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: https://github.com/nodejs/node/pull/25508 Reviewed-By: Anna Henningsen Reviewed-By: James M Snell --- test/parallel/test-tls-alert-handling.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-tls-alert-handling.js b/test/parallel/test-tls-alert-handling.js index c686d68a182e3d..e88453b115e0ea 100644 --- a/test/parallel/test-tls-alert-handling.js +++ b/test/parallel/test-tls-alert-handling.js @@ -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, { @@ -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()); }