From 2e01130415e26e0e466007c221be644a01735230 Mon Sep 17 00:00:00 2001 From: Hutson Betts Date: Thu, 1 Dec 2016 10:27:39 -0600 Subject: [PATCH] test: refactor test-tls-server-verify Refactored `test-tls-server-verify.js` to replace uses of `var` with `const` and `let`. Also replaced uses of `assert.equal` with `assert.strictEqual`. PR-URL: https://github.com/nodejs/node/pull/10076 Reviewed-By: Michael Dawson --- test/parallel/test-tls-server-verify.js | 62 ++++++++++++------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/test/parallel/test-tls-server-verify.js b/test/parallel/test-tls-server-verify.js index 93866d2977414b..52d83e54c5b162 100644 --- a/test/parallel/test-tls-server-verify.js +++ b/test/parallel/test-tls-server-verify.js @@ -1,5 +1,5 @@ 'use strict'; -var common = require('../common'); +const common = require('../common'); if (!common.opensslCli) { common.skip('node compiled without OpenSSL CLI.'); @@ -14,7 +14,7 @@ if (!common.opensslCli) { // - accepted and "unauthorized", or // - accepted and "authorized". -var testCases = +const testCases = [{ title: 'Do not request certs. Everyone is unauthorized.', requestCert: false, rejectUnauthorized: false, @@ -102,12 +102,12 @@ if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var tls = require('tls'); +const tls = require('tls'); -var constants = require('constants'); -var assert = require('assert'); -var fs = require('fs'); -var spawn = require('child_process').spawn; +const constants = require('constants'); +const assert = require('assert'); +const fs = require('fs'); +const spawn = require('child_process').spawn; function filenamePEM(n) { @@ -120,8 +120,8 @@ function loadPEM(n) { } -var serverKey = loadPEM('agent2-key'); -var serverCert = loadPEM('agent2-cert'); +const serverKey = loadPEM('agent2-key'); +const serverCert = loadPEM('agent2-cert'); function runClient(prefix, port, options, cb) { @@ -131,7 +131,7 @@ function runClient(prefix, port, options, cb) { // - Certificate, but not signed by CA. // - Certificate signed by CA. - var args = ['s_client', '-connect', '127.0.0.1:' + port]; + const args = ['s_client', '-connect', '127.0.0.1:' + port]; // for the performance issue in s_client on Windows if (common.isWindows) @@ -182,13 +182,13 @@ function runClient(prefix, port, options, cb) { } // To test use: openssl s_client -connect localhost:8000 - var client = spawn(common.opensslCli, args); + const client = spawn(common.opensslCli, args); - var out = ''; + let out = ''; - var rejected = true; - var authed = false; - var goodbye = false; + let rejected = true; + let authed = false; + let goodbye = false; client.stdout.setEncoding('utf8'); client.stdout.on('data', function(d) { @@ -217,12 +217,12 @@ function runClient(prefix, port, options, cb) { //assert.equal(0, code, prefix + options.name + // ": s_client exited with error code " + code); if (options.shouldReject) { - assert.equal(true, rejected, prefix + options.name + + assert.strictEqual(true, rejected, prefix + options.name + ' NOT rejected, but should have been'); } else { - assert.equal(false, rejected, prefix + options.name + + assert.strictEqual(false, rejected, prefix + options.name + ' rejected, but should NOT have been'); - assert.equal(options.shouldAuth, authed, prefix + + assert.strictEqual(options.shouldAuth, authed, prefix + options.name + ' authed is ' + authed + ' but should have been ' + options.shouldAuth); } @@ -233,19 +233,19 @@ function runClient(prefix, port, options, cb) { // Run the tests -var successfulTests = 0; +let successfulTests = 0; function runTest(port, testIndex) { - var prefix = testIndex + ' '; - var tcase = testCases[testIndex]; + const prefix = testIndex + ' '; + const tcase = testCases[testIndex]; if (!tcase) return; console.error(prefix + "Running '%s'", tcase.title); - var cas = tcase.CAs.map(loadPEM); + const cas = tcase.CAs.map(loadPEM); - var crl = tcase.crl ? loadPEM(tcase.crl) : null; + const crl = tcase.crl ? loadPEM(tcase.crl) : null; - var serverOptions = { + const serverOptions = { key: serverKey, cert: serverCert, ca: cas, @@ -263,8 +263,8 @@ function runTest(port, testIndex) { constants.SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION; } - var renegotiated = false; - var server = tls.Server(serverOptions, function handleConnection(c) { + let renegotiated = false; + const server = tls.Server(serverOptions, function handleConnection(c) { c.on('error', function(e) { // child.kill() leads ECONNRESET errro in the TLS connection of // openssl s_client via spawn(). A Test result is already @@ -299,7 +299,7 @@ function runTest(port, testIndex) { }); function runNextClient(clientIndex) { - var options = tcase.clients[clientIndex]; + const options = tcase.clients[clientIndex]; if (options) { runClient(prefix + clientIndex + ' ', port, options, function() { runNextClient(clientIndex + 1); @@ -319,8 +319,8 @@ function runTest(port, testIndex) { if (tcase.renegotiate) { runNextClient(0); } else { - var clientsCompleted = 0; - for (var i = 0; i < tcase.clients.length; i++) { + let clientsCompleted = 0; + for (let i = 0; i < tcase.clients.length; i++) { runClient(prefix + i + ' ', port, tcase.clients[i], function() { clientsCompleted++; if (clientsCompleted === tcase.clients.length) { @@ -336,11 +336,11 @@ function runTest(port, testIndex) { } -var nextTest = 0; +let nextTest = 0; runTest(0, nextTest++); runTest(0, nextTest++); process.on('exit', function() { - assert.equal(successfulTests, testCases.length); + assert.strictEqual(successfulTests, testCases.length); });