Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: replace var with const/let and use common.mustCall for cb #9959

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 15 additions & 21 deletions test/parallel/test-tls-cnnic-whitelist.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
'use strict';
var common = require('../common');
var assert = require('assert');
const common = require('../common');

if (!common.hasCrypto) {
common.skip('missing crypto');
return;
}

var tls = require('tls');
var fs = require('fs');
var path = require('path');
var finished = 0;
const assert = require('assert');
const tls = require('tls');
const fs = require('fs');
const path = require('path');

function filenamePEM(n) {
return path.join(common.fixturesDir, 'keys', n + '.pem');
Expand All @@ -20,7 +19,7 @@ function loadPEM(n) {
return fs.readFileSync(filenamePEM(n));
}

var testCases = [
const testCases = [
{ // 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
// hash is not listed in the whitelist.
Expand Down Expand Up @@ -58,27 +57,22 @@ var testCases = [
];

function runTest(tindex) {
var tcase = testCases[tindex];
const tcase = testCases[tindex];

if (!tcase) return;

var server = tls.createServer(tcase.serverOpts, function(s) {
const server = tls.createServer(tcase.serverOpts, (s) => {
s.resume();
}).listen(0, function() {
}).listen(0, common.mustCall(function() {
tcase.clientOpts = this.address().port;
var client = tls.connect(tcase.clientOpts);
client.on('error', function(e) {
const client = tls.connect(tcase.clientOpts);
client.on('error', common.mustCall((e) => {
assert.strictEqual(e.code, tcase.errorCode);
server.close(function() {
finished++;
server.close(common.mustCall(() => {
runTest(tindex + 1);
});
});
});
}));
}));
}));
}

runTest(0);

process.on('exit', function() {
assert.equal(finished, testCases.length);
});