Skip to content

Commit

Permalink
test: refactor test-tls-server-verify
Browse files Browse the repository at this point in the history
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: #10076
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
  • Loading branch information
Hutson Betts authored and MylesBorins committed Feb 1, 2017
1 parent 19907c2 commit 812c636
Showing 1 changed file with 31 additions and 31 deletions.
62 changes: 31 additions & 31 deletions test/parallel/test-tls-server-verify.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
var common = require('../common');
const common = require('../common');

if (!common.opensslCli) {
common.skip('node compiled without OpenSSL CLI.');
Expand All @@ -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,
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand All @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand All @@ -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);
});

0 comments on commit 812c636

Please sign in to comment.