MCPcopy Index your code
hub / github.com/nodejs/node / test

Function test

test/parallel/test-tls-ocsp-callback.js:43–108  ·  view source on GitHub ↗
(testOptions, cb)

Source from the content-addressed store, hash-verified

41const ca = fixtures.readKey('ca1-cert.pem');
42
43function test(testOptions, cb) {
44 const options = {
45 key,
46 cert,
47 ca: [ca]
48 };
49 const requestCount = testOptions.response ? 0 : 1;
50
51 if (!testOptions.ocsp)
52 assert.strictEqual(testOptions.response, undefined);
53
54 if (testOptions.pfx) {
55 delete options.key;
56 delete options.cert;
57 options.pfx = testOptions.pfx;
58 options.passphrase = testOptions.passphrase;
59 }
60
61 const server = tls.createServer(options, common.mustCall((cleartext) => {
62 cleartext.on('error', function(er) {
63 // We're ok with getting ECONNRESET in this test, but it's
64 // timing-dependent, and thus unreliable. Any other errors
65 // are just failures, though.
66 if (er.code !== 'ECONNRESET')
67 throw er;
68 });
69 cleartext.end();
70 }, requestCount));
71
72 if (!testOptions.ocsp)
73 server.on('OCSPRequest', common.mustNotCall());
74 else
75 server.on('OCSPRequest', common.mustCall((cert, issuer, callback) => {
76 assert.ok(Buffer.isBuffer(cert));
77 assert.ok(Buffer.isBuffer(issuer));
78
79 // Callback a little later to ensure that async really works.
80 return setTimeout(callback, 100, null, testOptions.response ?
81 Buffer.from(testOptions.response) : null);
82 }));
83
84 server.listen(0, common.mustCall(function() {
85 const client = tls.connect({
86 port: this.address().port,
87 requestOCSP: testOptions.ocsp,
88 secureOptions: testOptions.ocsp ? 0 : SSL_OP_NO_TICKET,
89 rejectUnauthorized: false
90 }, common.mustCall(requestCount));
91
92 client.on('OCSPResponse', common.mustCall((resp) => {
93 if (testOptions.response) {
94 if (Buffer.isBuffer(testOptions.response))
95 assert.deepStrictEqual(resp, testOptions.response);
96 else
97 assert.strictEqual(resp.toString(), testOptions.response);
98 client.destroy();
99 } else {
100 assert.strictEqual(resp, null);

Callers 1

Calls 11

listenMethod · 0.80
connectMethod · 0.65
addressMethod · 0.65
closeMethod · 0.65
setTimeoutFunction · 0.50
onMethod · 0.45
endMethod · 0.45
okMethod · 0.45
fromMethod · 0.45
toStringMethod · 0.45
destroyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…