summaryrefslogtreecommitdiff
path: root/test/parallel/test-tls-ocsp-callback.js
diff options
context:
space:
mode:
authorSam Roberts <vieuxtech@gmail.com>2019-03-05 14:17:15 -0800
committerRuben Bridgewater <ruben@bridgewater.de>2019-03-10 00:49:01 +0100
commit78913393fa67fdae7a3a87ccf82093b814edcaf8 (patch)
tree68b6c6b02917199f14ca90c86571b9b48958c7e2 /test/parallel/test-tls-ocsp-callback.js
parente7f58868b5ea1312f7bac4f152f4d928b64e0202 (diff)
downloadandroid-node-v8-78913393fa67fdae7a3a87ccf82093b814edcaf8.tar.gz
android-node-v8-78913393fa67fdae7a3a87ccf82093b814edcaf8.tar.bz2
android-node-v8-78913393fa67fdae7a3a87ccf82093b814edcaf8.zip
test: rewrite ocsp test to run in parallel
Run tests in parallel and use common.mustCall() and mustNotCall() instead of process.exit() to ensure test assertions are run. PR-URL: https://github.com/nodejs/node/pull/26460 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'test/parallel/test-tls-ocsp-callback.js')
-rw-r--r--test/parallel/test-tls-ocsp-callback.js107
1 files changed, 40 insertions, 67 deletions
diff --git a/test/parallel/test-tls-ocsp-callback.js b/test/parallel/test-tls-ocsp-callback.js
index 2670fefd3d..d374ebdf63 100644
--- a/test/parallel/test-tls-ocsp-callback.js
+++ b/test/parallel/test-tls-ocsp-callback.js
@@ -36,21 +36,20 @@ const assert = require('assert');
const SSL_OP_NO_TICKET = require('crypto').constants.SSL_OP_NO_TICKET;
const pfx = fixtures.readKey('agent1.pfx');
+const key = fixtures.readKey('agent1-key.pem');
+const cert = fixtures.readKey('agent1-cert.pem');
+const ca = fixtures.readKey('ca1-cert.pem');
function test(testOptions, cb) {
-
- const key = fixtures.readKey('agent1-key.pem');
- const cert = fixtures.readKey('agent1-cert.pem');
- const ca = fixtures.readKey('ca1-cert.pem');
const options = {
key,
cert,
ca: [ca]
};
- let requestCount = 0;
- let clientSecure = 0;
- let ocspCount = 0;
- let ocspResponse;
+ const requestCount = testOptions.response ? 0 : 1;
+
+ if (!testOptions.ocsp)
+ assert.strictEqual(testOptions.response, undefined);
if (testOptions.pfx) {
delete options.key;
@@ -59,7 +58,7 @@ function test(testOptions, cb) {
options.passphrase = testOptions.passphrase;
}
- const server = tls.createServer(options, function(cleartext) {
+ const server = tls.createServer(options, common.mustCall((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
@@ -67,74 +66,48 @@ function test(testOptions, cb) {
if (er.code !== 'ECONNRESET')
throw er;
});
- ++requestCount;
cleartext.end();
- });
- server.on('OCSPRequest', function(cert, issuer, callback) {
- ++ocspCount;
- assert.ok(Buffer.isBuffer(cert));
- assert.ok(Buffer.isBuffer(issuer));
-
- // Just to check that async really works there
- setTimeout(function() {
- callback(null,
- testOptions.response ? Buffer.from(testOptions.response) : null);
- }, 100);
- });
+ }, requestCount));
+
+ if (!testOptions.ocsp)
+ server.on('OCSPRequest', common.mustNotCall());
+ else
+ server.on('OCSPRequest', common.mustCall((cert, issuer, callback) => {
+ assert.ok(Buffer.isBuffer(cert));
+ assert.ok(Buffer.isBuffer(issuer));
+
+ // Callback a little later to ensure that async really works.
+ return setTimeout(callback, 100, null, testOptions.response ?
+ Buffer.from(testOptions.response) : null);
+ }));
+
server.listen(0, function() {
const client = tls.connect({
port: this.address().port,
- requestOCSP: testOptions.ocsp !== false,
- secureOptions: testOptions.ocsp === false ?
- SSL_OP_NO_TICKET : 0,
+ requestOCSP: testOptions.ocsp,
+ secureOptions: testOptions.ocsp ? 0 : SSL_OP_NO_TICKET,
rejectUnauthorized: false
- }, function() {
- clientSecure++;
- });
- client.on('OCSPResponse', function(resp) {
- ocspResponse = resp;
- if (resp)
+ }, common.mustCall(() => { }, requestCount));
+
+ client.on('OCSPResponse', common.mustCall((resp) => {
+ if (testOptions.response) {
+ assert.strictEqual(resp.toString(), testOptions.response);
client.destroy();
- });
- client.on('close', function() {
- server.close(cb);
- });
- });
+ } else {
+ assert.strictEqual(resp, null);
+ }
+ }, testOptions.ocsp === false ? 0 : 1));
- process.on('exit', function() {
- if (testOptions.ocsp === false) {
- assert.strictEqual(requestCount, clientSecure);
- assert.strictEqual(requestCount, 1);
- return;
- }
-
- if (testOptions.response) {
- assert.strictEqual(ocspResponse.toString(), testOptions.response);
- } else {
- assert.strictEqual(ocspResponse, null);
- }
- assert.strictEqual(requestCount, testOptions.response ? 0 : 1);
- assert.strictEqual(clientSecure, requestCount);
- assert.strictEqual(ocspCount, 1);
+ client.on('close', common.mustCall(() => {
+ server.close(cb);
+ }));
});
}
-const tests = [
- { response: false },
- { response: 'hello world' },
- { ocsp: false }
-];
+test({ ocsp: true, response: false });
+test({ ocsp: true, response: 'hello world' });
+test({ ocsp: false });
if (!common.hasFipsCrypto) {
- tests.push({ pfx: pfx, passphrase: 'sample', response: 'hello pfx' });
+ test({ ocsp: true, response: 'hello pfx', pfx: pfx, passphrase: 'sample' });
}
-
-function runTests(i) {
- if (i === tests.length) return;
-
- test(tests[i], common.mustCall(function() {
- runTests(i + 1);
- }));
-}
-
-runTests(0);