Browse Source

test: use const/let and common.mustCall

remove process.on('exit') because all callbacks are
wrapped by common.mustCall.

PR-URL: https://github.com/nodejs/node/pull/9959
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
v6.x
Outsider 8 years ago
committed by Michaël Zasso
parent
commit
bdf633a32e
  1. 36
      test/parallel/test-tls-cnnic-whitelist.js

36
test/parallel/test-tls-cnnic-whitelist.js

@ -1,16 +1,15 @@
'use strict'; 'use strict';
var common = require('../common'); const common = require('../common');
var assert = require('assert');
if (!common.hasCrypto) { if (!common.hasCrypto) {
common.skip('missing crypto'); common.skip('missing crypto');
return; return;
} }
var tls = require('tls'); const assert = require('assert');
var fs = require('fs'); const tls = require('tls');
var path = require('path'); const fs = require('fs');
var finished = 0; const path = require('path');
function filenamePEM(n) { function filenamePEM(n) {
return path.join(common.fixturesDir, 'keys', n + '.pem'); return path.join(common.fixturesDir, 'keys', n + '.pem');
@ -20,7 +19,7 @@ function loadPEM(n) {
return fs.readFileSync(filenamePEM(n)); return fs.readFileSync(filenamePEM(n));
} }
var testCases = [ const testCases = [
{ // Test 0: for the check of a cert not existed in the whitelist. { // Test 0: for the check of a cert not existed in the whitelist.
// agent7-cert.pem is issued by the fake CNNIC root CA so that its // agent7-cert.pem is issued by the fake CNNIC root CA so that its
// hash is not listed in the whitelist. // hash is not listed in the whitelist.
@ -58,27 +57,22 @@ var testCases = [
]; ];
function runTest(tindex) { function runTest(tindex) {
var tcase = testCases[tindex]; const tcase = testCases[tindex];
if (!tcase) return; if (!tcase) return;
var server = tls.createServer(tcase.serverOpts, function(s) { const server = tls.createServer(tcase.serverOpts, (s) => {
s.resume(); s.resume();
}).listen(0, function() { }).listen(0, common.mustCall(function() {
tcase.clientOpts = this.address().port; tcase.clientOpts = this.address().port;
var client = tls.connect(tcase.clientOpts); const client = tls.connect(tcase.clientOpts);
client.on('error', function(e) { client.on('error', common.mustCall((e) => {
assert.strictEqual(e.code, tcase.errorCode); assert.strictEqual(e.code, tcase.errorCode);
server.close(function() { server.close(common.mustCall(() => {
finished++;
runTest(tindex + 1); runTest(tindex + 1);
}); }));
}); }));
}); }));
} }
runTest(0); runTest(0);
process.on('exit', function() {
assert.equal(finished, testCases.length);
});

Loading…
Cancel
Save