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 <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Sam Roberts 2019-02-01 12:02:44 -08:00
parent 1bd42833d7
commit 1f4c5bdbca

View File

@ -48,6 +48,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, {
@ -78,8 +81,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((err) => {
assert.strictEqual(err.code, 'ERR_SSL_TLSV1_ALERT_PROTOCOL_VERSION');