Skip to content

Commit 14c0388

Browse files
Hutson BettsFishrock123
Hutson Betts
authored andcommitted
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: #10076 Reviewed-By: Michael Dawson <[email protected]>
1 parent 36b8dd3 commit 14c0388

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

test/parallel/test-tls-server-verify.js

+30-30
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
2-
var common = require('../common');
2+
const common = require('../common');
33

44
if (!common.opensslCli) {
55
common.skip('node compiled without OpenSSL CLI.');
@@ -14,7 +14,7 @@ if (!common.opensslCli) {
1414
// - accepted and "unauthorized", or
1515
// - accepted and "authorized".
1616

17-
var testCases =
17+
const testCases =
1818
[{ title: 'Do not request certs. Everyone is unauthorized.',
1919
requestCert: false,
2020
rejectUnauthorized: false,
@@ -102,14 +102,14 @@ if (!common.hasCrypto) {
102102
common.skip('missing crypto');
103103
return;
104104
}
105-
var tls = require('tls');
105+
const tls = require('tls');
106106

107107
const SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION =
108108
require('crypto').constants.SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION;
109109

110-
var assert = require('assert');
111-
var fs = require('fs');
112-
var spawn = require('child_process').spawn;
110+
const assert = require('assert');
111+
const fs = require('fs');
112+
const spawn = require('child_process').spawn;
113113

114114

115115
function filenamePEM(n) {
@@ -122,8 +122,8 @@ function loadPEM(n) {
122122
}
123123

124124

125-
var serverKey = loadPEM('agent2-key');
126-
var serverCert = loadPEM('agent2-cert');
125+
const serverKey = loadPEM('agent2-key');
126+
const serverCert = loadPEM('agent2-cert');
127127

128128

129129
function runClient(prefix, port, options, cb) {
@@ -133,7 +133,7 @@ function runClient(prefix, port, options, cb) {
133133
// - Certificate, but not signed by CA.
134134
// - Certificate signed by CA.
135135

136-
var args = ['s_client', '-connect', '127.0.0.1:' + port];
136+
const args = ['s_client', '-connect', '127.0.0.1:' + port];
137137

138138
// for the performance issue in s_client on Windows
139139
if (common.isWindows)
@@ -184,13 +184,13 @@ function runClient(prefix, port, options, cb) {
184184
}
185185

186186
// To test use: openssl s_client -connect localhost:8000
187-
var client = spawn(common.opensslCli, args);
187+
const client = spawn(common.opensslCli, args);
188188

189-
var out = '';
189+
let out = '';
190190

191-
var rejected = true;
192-
var authed = false;
193-
var goodbye = false;
191+
let rejected = true;
192+
let authed = false;
193+
let goodbye = false;
194194

195195
client.stdout.setEncoding('utf8');
196196
client.stdout.on('data', function(d) {
@@ -219,12 +219,12 @@ function runClient(prefix, port, options, cb) {
219219
//assert.equal(0, code, prefix + options.name +
220220
// ": s_client exited with error code " + code);
221221
if (options.shouldReject) {
222-
assert.equal(true, rejected, prefix + options.name +
222+
assert.strictEqual(true, rejected, prefix + options.name +
223223
' NOT rejected, but should have been');
224224
} else {
225-
assert.equal(false, rejected, prefix + options.name +
225+
assert.strictEqual(false, rejected, prefix + options.name +
226226
' rejected, but should NOT have been');
227-
assert.equal(options.shouldAuth, authed, prefix +
227+
assert.strictEqual(options.shouldAuth, authed, prefix +
228228
options.name + ' authed is ' + authed +
229229
' but should have been ' + options.shouldAuth);
230230
}
@@ -235,19 +235,19 @@ function runClient(prefix, port, options, cb) {
235235

236236

237237
// Run the tests
238-
var successfulTests = 0;
238+
let successfulTests = 0;
239239
function runTest(port, testIndex) {
240-
var prefix = testIndex + ' ';
241-
var tcase = testCases[testIndex];
240+
const prefix = testIndex + ' ';
241+
const tcase = testCases[testIndex];
242242
if (!tcase) return;
243243

244244
console.error(prefix + "Running '%s'", tcase.title);
245245

246-
var cas = tcase.CAs.map(loadPEM);
246+
const cas = tcase.CAs.map(loadPEM);
247247

248-
var crl = tcase.crl ? loadPEM(tcase.crl) : null;
248+
const crl = tcase.crl ? loadPEM(tcase.crl) : null;
249249

250-
var serverOptions = {
250+
const serverOptions = {
251251
key: serverKey,
252252
cert: serverCert,
253253
ca: cas,
@@ -265,8 +265,8 @@ function runTest(port, testIndex) {
265265
SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION;
266266
}
267267

268-
var renegotiated = false;
269-
var server = tls.Server(serverOptions, function handleConnection(c) {
268+
let renegotiated = false;
269+
const server = tls.Server(serverOptions, function handleConnection(c) {
270270
c.on('error', function(e) {
271271
// child.kill() leads ECONNRESET errro in the TLS connection of
272272
// openssl s_client via spawn(). A Test result is already
@@ -301,7 +301,7 @@ function runTest(port, testIndex) {
301301
});
302302

303303
function runNextClient(clientIndex) {
304-
var options = tcase.clients[clientIndex];
304+
const options = tcase.clients[clientIndex];
305305
if (options) {
306306
runClient(prefix + clientIndex + ' ', port, options, function() {
307307
runNextClient(clientIndex + 1);
@@ -321,8 +321,8 @@ function runTest(port, testIndex) {
321321
if (tcase.renegotiate) {
322322
runNextClient(0);
323323
} else {
324-
var clientsCompleted = 0;
325-
for (var i = 0; i < tcase.clients.length; i++) {
324+
let clientsCompleted = 0;
325+
for (let i = 0; i < tcase.clients.length; i++) {
326326
runClient(prefix + i + ' ', port, tcase.clients[i], function() {
327327
clientsCompleted++;
328328
if (clientsCompleted === tcase.clients.length) {
@@ -338,11 +338,11 @@ function runTest(port, testIndex) {
338338
}
339339

340340

341-
var nextTest = 0;
341+
let nextTest = 0;
342342
runTest(0, nextTest++);
343343
runTest(0, nextTest++);
344344

345345

346346
process.on('exit', function() {
347-
assert.equal(successfulTests, testCases.length);
347+
assert.strictEqual(successfulTests, testCases.length);
348348
});

0 commit comments

Comments
 (0)