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: refactor test-tls-ocsp-callback #9970

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
54 changes: 27 additions & 27 deletions test/parallel/test-tls-ocsp-callback.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
var common = require('../common');
const common = require('../common');

if (!process.features.tls_ocsp) {
common.skip('node compiled without OpenSSL or ' +
Expand All @@ -15,33 +15,33 @@ if (!common.hasCrypto) {
common.skip('missing crypto');
return;
}
var tls = require('tls');
const tls = require('tls');

var assert = require('assert');
var fs = require('fs');
var join = require('path').join;
const assert = require('assert');
const fs = require('fs');
const join = require('path').join;

const SSL_OP_NO_TICKET = require('crypto').constants.SSL_OP_NO_TICKET;

var pfx = fs.readFileSync(join(common.fixturesDir, 'keys', 'agent1-pfx.pem'));
const pfx = fs.readFileSync(join(common.fixturesDir, 'keys', 'agent1-pfx.pem'));

function test(testOptions, cb) {

var keyFile = join(common.fixturesDir, 'keys', 'agent1-key.pem');
var certFile = join(common.fixturesDir, 'keys', 'agent1-cert.pem');
var caFile = join(common.fixturesDir, 'keys', 'ca1-cert.pem');
var key = fs.readFileSync(keyFile);
var cert = fs.readFileSync(certFile);
var ca = fs.readFileSync(caFile);
var options = {
const keyFile = join(common.fixturesDir, 'keys', 'agent1-key.pem');
const certFile = join(common.fixturesDir, 'keys', 'agent1-cert.pem');
const caFile = join(common.fixturesDir, 'keys', 'ca1-cert.pem');
const key = fs.readFileSync(keyFile);
const cert = fs.readFileSync(certFile);
const ca = fs.readFileSync(caFile);
const options = {
key: key,
cert: cert,
ca: [ca]
};
var requestCount = 0;
var clientSecure = 0;
var ocspCount = 0;
var ocspResponse;
let requestCount = 0;
let clientSecure = 0;
let ocspCount = 0;
let ocspResponse;

if (testOptions.pfx) {
delete options.key;
Expand All @@ -50,7 +50,7 @@ function test(testOptions, cb) {
options.passphrase = testOptions.passphrase;
}

var server = tls.createServer(options, function(cleartext) {
const server = tls.createServer(options, function(cleartext) {
cleartext.on('error', function(er) {
// We're ok with getting ECONNRESET in this test, but it's
// timing-dependent, and thus unreliable. Any other errors
Expand All @@ -73,7 +73,7 @@ function test(testOptions, cb) {
}, 100);
});
server.listen(0, function() {
var client = tls.connect({
const client = tls.connect({
port: this.address().port,
requestOCSP: testOptions.ocsp !== false,
secureOptions: testOptions.ocsp === false ?
Expand All @@ -94,23 +94,23 @@ function test(testOptions, cb) {

process.on('exit', function() {
if (testOptions.ocsp === false) {
assert.equal(requestCount, clientSecure);
assert.equal(requestCount, 1);
assert.strictEqual(requestCount, clientSecure);
assert.strictEqual(requestCount, 1);
return;
}

if (testOptions.response) {
assert.equal(ocspResponse.toString(), testOptions.response);
assert.strictEqual(ocspResponse.toString(), testOptions.response);
} else {
assert.ok(ocspResponse === null);
assert.strictEqual(ocspResponse, null);
}
assert.equal(requestCount, testOptions.response ? 0 : 1);
assert.equal(clientSecure, requestCount);
assert.equal(ocspCount, 1);
assert.strictEqual(requestCount, testOptions.response ? 0 : 1);
assert.strictEqual(clientSecure, requestCount);
assert.strictEqual(ocspCount, 1);
});
}

var tests = [
const tests = [
{ response: false },
{ response: 'hello world' },
{ ocsp: false }
Expand Down