Browse Source

test: refactor test-tls-ocsp-callback

refactor all var to either const/let
change all assert.equal to assert.strictEqual
change all assert.ok(...===...) to assert.strictEqual

PR-URL: https://github.com/nodejs/node/pull/9970
Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
v6.x
k3kathy 8 years ago
committed by Anna Henningsen
parent
commit
cdb803d18b
No known key found for this signature in database GPG Key ID: D8B9F5AEAE84E4CF
  1. 54
      test/parallel/test-tls-ocsp-callback.js

54
test/parallel/test-tls-ocsp-callback.js

@ -1,5 +1,5 @@
'use strict'; 'use strict';
var common = require('../common'); const common = require('../common');
if (!process.features.tls_ocsp) { if (!process.features.tls_ocsp) {
common.skip('node compiled without OpenSSL or ' + common.skip('node compiled without OpenSSL or ' +
@ -15,33 +15,33 @@ if (!common.hasCrypto) {
common.skip('missing crypto'); common.skip('missing crypto');
return; return;
} }
var tls = require('tls'); const tls = require('tls');
var assert = require('assert'); const assert = require('assert');
var fs = require('fs'); const fs = require('fs');
var join = require('path').join; const join = require('path').join;
const SSL_OP_NO_TICKET = require('crypto').constants.SSL_OP_NO_TICKET; 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) { function test(testOptions, cb) {
var keyFile = join(common.fixturesDir, 'keys', 'agent1-key.pem'); const keyFile = join(common.fixturesDir, 'keys', 'agent1-key.pem');
var certFile = join(common.fixturesDir, 'keys', 'agent1-cert.pem'); const certFile = join(common.fixturesDir, 'keys', 'agent1-cert.pem');
var caFile = join(common.fixturesDir, 'keys', 'ca1-cert.pem'); const caFile = join(common.fixturesDir, 'keys', 'ca1-cert.pem');
var key = fs.readFileSync(keyFile); const key = fs.readFileSync(keyFile);
var cert = fs.readFileSync(certFile); const cert = fs.readFileSync(certFile);
var ca = fs.readFileSync(caFile); const ca = fs.readFileSync(caFile);
var options = { const options = {
key: key, key: key,
cert: cert, cert: cert,
ca: [ca] ca: [ca]
}; };
var requestCount = 0; let requestCount = 0;
var clientSecure = 0; let clientSecure = 0;
var ocspCount = 0; let ocspCount = 0;
var ocspResponse; let ocspResponse;
if (testOptions.pfx) { if (testOptions.pfx) {
delete options.key; delete options.key;
@ -50,7 +50,7 @@ function test(testOptions, cb) {
options.passphrase = testOptions.passphrase; options.passphrase = testOptions.passphrase;
} }
var server = tls.createServer(options, function(cleartext) { const server = tls.createServer(options, function(cleartext) {
cleartext.on('error', function(er) { cleartext.on('error', function(er) {
// We're ok with getting ECONNRESET in this test, but it's // We're ok with getting ECONNRESET in this test, but it's
// timing-dependent, and thus unreliable. Any other errors // timing-dependent, and thus unreliable. Any other errors
@ -73,7 +73,7 @@ function test(testOptions, cb) {
}, 100); }, 100);
}); });
server.listen(0, function() { server.listen(0, function() {
var client = tls.connect({ const client = tls.connect({
port: this.address().port, port: this.address().port,
requestOCSP: testOptions.ocsp !== false, requestOCSP: testOptions.ocsp !== false,
secureOptions: testOptions.ocsp === false ? secureOptions: testOptions.ocsp === false ?
@ -94,23 +94,23 @@ function test(testOptions, cb) {
process.on('exit', function() { process.on('exit', function() {
if (testOptions.ocsp === false) { if (testOptions.ocsp === false) {
assert.equal(requestCount, clientSecure); assert.strictEqual(requestCount, clientSecure);
assert.equal(requestCount, 1); assert.strictEqual(requestCount, 1);
return; return;
} }
if (testOptions.response) { if (testOptions.response) {
assert.equal(ocspResponse.toString(), testOptions.response); assert.strictEqual(ocspResponse.toString(), testOptions.response);
} else { } else {
assert.ok(ocspResponse === null); assert.strictEqual(ocspResponse, null);
} }
assert.equal(requestCount, testOptions.response ? 0 : 1); assert.strictEqual(requestCount, testOptions.response ? 0 : 1);
assert.equal(clientSecure, requestCount); assert.strictEqual(clientSecure, requestCount);
assert.equal(ocspCount, 1); assert.strictEqual(ocspCount, 1);
}); });
} }
var tests = [ const tests = [
{ response: false }, { response: false },
{ response: 'hello world' }, { response: 'hello world' },
{ ocsp: false } { ocsp: false }

Loading…
Cancel
Save