Skip to content

Commit f44e828

Browse files
Paul GrahamMylesBorins
Paul Graham
authored andcommitted
test: improves test-tls-client-verify
Swaps var -> const/let assert.equal becomes assert.strictEqual common.mustCall on single-use functions PR-URL: #10051 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent a1e3967 commit f44e828

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

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

+27-27
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
'use strict';
2-
var common = require('../common');
3-
var assert = require('assert');
2+
const common = require('../common');
3+
const assert = require('assert');
44

55
if (!common.hasCrypto) {
66
common.skip('missing crypto');
77
return;
88
}
9-
var tls = require('tls');
9+
const tls = require('tls');
1010

11-
var fs = require('fs');
11+
const fs = require('fs');
1212

13-
var hosterr = /Hostname\/IP doesn\'t match certificate\'s altnames/g;
14-
var testCases =
13+
const hosterr = /Hostname\/IP doesn't match certificate's altnames/g;
14+
const testCases =
1515
[{ ca: ['ca1-cert'],
1616
key: 'agent2-key',
1717
cert: 'agent2-cert',
@@ -52,16 +52,16 @@ function loadPEM(n) {
5252
return fs.readFileSync(filenamePEM(n));
5353
}
5454

55-
var successfulTests = 0;
55+
let successfulTests = 0;
5656

5757
function testServers(index, servers, clientOptions, cb) {
58-
var serverOptions = servers[index];
58+
const serverOptions = servers[index];
5959
if (!serverOptions) {
6060
cb();
6161
return;
6262
}
6363

64-
var ok = serverOptions.ok;
64+
const ok = serverOptions.ok;
6565

6666
if (serverOptions.key) {
6767
serverOptions.key = loadPEM(serverOptions.key);
@@ -71,45 +71,45 @@ function testServers(index, servers, clientOptions, cb) {
7171
serverOptions.cert = loadPEM(serverOptions.cert);
7272
}
7373

74-
var server = tls.createServer(serverOptions, function(s) {
74+
const server = tls.createServer(serverOptions, common.mustCall(function(s) {
7575
s.end('hello world\n');
76-
});
76+
}));
7777

78-
server.listen(0, function() {
79-
var b = '';
78+
server.listen(0, common.mustCall(function() {
79+
let b = '';
8080

8181
console.error('connecting...');
8282
clientOptions.port = this.address().port;
83-
var client = tls.connect(clientOptions, function() {
84-
var authorized = client.authorized ||
85-
hosterr.test(client.authorizationError);
83+
const client = tls.connect(clientOptions, common.mustCall(function() {
84+
const authorized = client.authorized ||
85+
hosterr.test(client.authorizationError);
8686

8787
console.error('expected: ' + ok + ' authed: ' + authorized);
8888

89-
assert.equal(ok, authorized);
89+
assert.strictEqual(ok, authorized);
9090
server.close();
91-
});
91+
}));
9292

9393
client.on('data', function(d) {
9494
b += d.toString();
9595
});
9696

97-
client.on('end', function() {
98-
assert.equal('hello world\n', b);
99-
});
97+
client.on('end', common.mustCall(function() {
98+
assert.strictEqual('hello world\n', b);
99+
}));
100100

101-
client.on('close', function() {
101+
client.on('close', common.mustCall(function() {
102102
testServers(index + 1, servers, clientOptions, cb);
103-
});
104-
});
103+
}));
104+
}));
105105
}
106106

107107

108108
function runTest(testIndex) {
109109
var tcase = testCases[testIndex];
110110
if (!tcase) return;
111111

112-
var clientOptions = {
112+
const clientOptions = {
113113
port: undefined,
114114
ca: tcase.ca.map(loadPEM),
115115
key: loadPEM(tcase.key),
@@ -118,10 +118,10 @@ function runTest(testIndex) {
118118
};
119119

120120

121-
testServers(0, tcase.servers, clientOptions, function() {
121+
testServers(0, tcase.servers, clientOptions, common.mustCall(function() {
122122
successfulTests++;
123123
runTest(testIndex + 1);
124-
});
124+
}));
125125
}
126126

127127

0 commit comments

Comments
 (0)