From 29b89badb50d990b85644e5bc0c5024c6b2b5f19 Mon Sep 17 00:00:00 2001 From: Sam Roberts Date: Thu, 10 Jan 2019 15:20:02 -0800 Subject: [PATCH] test: check for tls renegotiation errors Check that the return value and callback error for tls.renegotiate() does not indicate a failure. Also, remove unnecessary line wrapping and indentation. PR-URL: https://github.com/nodejs/node/pull/25437 Reviewed-By: Colin Ihrig Reviewed-By: Luigi Pinca Reviewed-By: Anna Henningsen --- .../test-tls-disable-renegotiation.js | 46 +++++++++---------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/test/parallel/test-tls-disable-renegotiation.js b/test/parallel/test-tls-disable-renegotiation.js index b688079a58af50..f43276460910f7 100644 --- a/test/parallel/test-tls-disable-renegotiation.js +++ b/test/parallel/test-tls-disable-renegotiation.js @@ -12,7 +12,7 @@ const tls = require('tls'); const options = { key: fixtures.readKey('agent1-key.pem'), - cert: fixtures.readKey('agent1-cert.pem') + cert: fixtures.readKey('agent1-cert.pem'), }; const server = tls.Server(options, common.mustCall((socket) => { @@ -45,28 +45,26 @@ server.listen(0, common.mustCall(() => { rejectUnauthorized: false, port }; - const client = - tls.connect(options, common.mustCall(() => { - client.write(''); - // Negotiation is still permitted for this first - // attempt. This should succeed. - client.renegotiate( - { rejectUnauthorized: false }, - common.mustCall(() => { - // Once renegotiation completes, we write some - // data to the socket, which triggers the on - // data event on the server. After that data - // is received, disableRenegotiation is called. - client.write('data', common.mustCall(() => { - client.write(''); - // This second renegotiation attempt should fail - // and the callback should never be invoked. The - // server will simply drop the connection after - // emitting the error. - client.renegotiate( - { rejectUnauthorized: false }, - common.mustNotCall()); - })); - })); + const client = tls.connect(options, common.mustCall(() => { + client.write(''); + // Negotiation is still permitted for this first + // attempt. This should succeed. + let ok = client.renegotiate(options, common.mustCall((err) => { + assert.ifError(err); + // Once renegotiation completes, we write some + // data to the socket, which triggers the on + // data event on the server. After that data + // is received, disableRenegotiation is called. + client.write('data', common.mustCall(() => { + client.write(''); + // This second renegotiation attempt should fail + // and the callback should never be invoked. The + // server will simply drop the connection after + // emitting the error. + ok = client.renegotiate(options, common.mustNotCall()); + assert.strictEqual(ok, true); + })); })); + assert.strictEqual(ok, true); + })); }));