test: improves test-tls-client-verify
Swaps var -> const/let assert.equal becomes assert.strictEqual common.mustCall on single-use functions PR-URL: https://github.com/nodejs/node/pull/10051 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
parent
83d9cd80bf
commit
fd6999ef6c
@ -1,17 +1,17 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
var common = require('../common');
|
const common = require('../common');
|
||||||
var assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
if (!common.hasCrypto) {
|
if (!common.hasCrypto) {
|
||||||
common.skip('missing crypto');
|
common.skip('missing crypto');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var tls = require('tls');
|
const tls = require('tls');
|
||||||
|
|
||||||
var fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
var hosterr = /Hostname\/IP doesn't match certificate's altnames/g;
|
const hosterr = /Hostname\/IP doesn't match certificate's altnames/g;
|
||||||
var testCases =
|
const testCases =
|
||||||
[{ ca: ['ca1-cert'],
|
[{ ca: ['ca1-cert'],
|
||||||
key: 'agent2-key',
|
key: 'agent2-key',
|
||||||
cert: 'agent2-cert',
|
cert: 'agent2-cert',
|
||||||
@ -52,16 +52,16 @@ function loadPEM(n) {
|
|||||||
return fs.readFileSync(filenamePEM(n));
|
return fs.readFileSync(filenamePEM(n));
|
||||||
}
|
}
|
||||||
|
|
||||||
var successfulTests = 0;
|
let successfulTests = 0;
|
||||||
|
|
||||||
function testServers(index, servers, clientOptions, cb) {
|
function testServers(index, servers, clientOptions, cb) {
|
||||||
var serverOptions = servers[index];
|
const serverOptions = servers[index];
|
||||||
if (!serverOptions) {
|
if (!serverOptions) {
|
||||||
cb();
|
cb();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var ok = serverOptions.ok;
|
const ok = serverOptions.ok;
|
||||||
|
|
||||||
if (serverOptions.key) {
|
if (serverOptions.key) {
|
||||||
serverOptions.key = loadPEM(serverOptions.key);
|
serverOptions.key = loadPEM(serverOptions.key);
|
||||||
@ -71,37 +71,37 @@ function testServers(index, servers, clientOptions, cb) {
|
|||||||
serverOptions.cert = loadPEM(serverOptions.cert);
|
serverOptions.cert = loadPEM(serverOptions.cert);
|
||||||
}
|
}
|
||||||
|
|
||||||
var server = tls.createServer(serverOptions, function(s) {
|
const server = tls.createServer(serverOptions, common.mustCall(function(s) {
|
||||||
s.end('hello world\n');
|
s.end('hello world\n');
|
||||||
});
|
}));
|
||||||
|
|
||||||
server.listen(0, function() {
|
server.listen(0, common.mustCall(function() {
|
||||||
var b = '';
|
let b = '';
|
||||||
|
|
||||||
console.error('connecting...');
|
console.error('connecting...');
|
||||||
clientOptions.port = this.address().port;
|
clientOptions.port = this.address().port;
|
||||||
var client = tls.connect(clientOptions, function() {
|
const client = tls.connect(clientOptions, common.mustCall(function() {
|
||||||
var authorized = client.authorized ||
|
const authorized = client.authorized ||
|
||||||
hosterr.test(client.authorizationError);
|
hosterr.test(client.authorizationError);
|
||||||
|
|
||||||
console.error('expected: ' + ok + ' authed: ' + authorized);
|
console.error('expected: ' + ok + ' authed: ' + authorized);
|
||||||
|
|
||||||
assert.equal(ok, authorized);
|
assert.strictEqual(ok, authorized);
|
||||||
server.close();
|
server.close();
|
||||||
});
|
}));
|
||||||
|
|
||||||
client.on('data', function(d) {
|
client.on('data', function(d) {
|
||||||
b += d.toString();
|
b += d.toString();
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on('end', function() {
|
client.on('end', common.mustCall(function() {
|
||||||
assert.equal('hello world\n', b);
|
assert.strictEqual('hello world\n', b);
|
||||||
});
|
}));
|
||||||
|
|
||||||
client.on('close', function() {
|
client.on('close', common.mustCall(function() {
|
||||||
testServers(index + 1, servers, clientOptions, cb);
|
testServers(index + 1, servers, clientOptions, cb);
|
||||||
});
|
}));
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -109,7 +109,7 @@ function runTest(testIndex) {
|
|||||||
var tcase = testCases[testIndex];
|
var tcase = testCases[testIndex];
|
||||||
if (!tcase) return;
|
if (!tcase) return;
|
||||||
|
|
||||||
var clientOptions = {
|
const clientOptions = {
|
||||||
port: undefined,
|
port: undefined,
|
||||||
ca: tcase.ca.map(loadPEM),
|
ca: tcase.ca.map(loadPEM),
|
||||||
key: loadPEM(tcase.key),
|
key: loadPEM(tcase.key),
|
||||||
@ -118,10 +118,10 @@ function runTest(testIndex) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
testServers(0, tcase.servers, clientOptions, function() {
|
testServers(0, tcase.servers, clientOptions, common.mustCall(function() {
|
||||||
successfulTests++;
|
successfulTests++;
|
||||||
runTest(testIndex + 1);
|
runTest(testIndex + 1);
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user