mirror of
https://github.com/nodejs/node.git
synced 2026-12-03 18:03:02 -05:00
test: ensure assertions are reached on more tests
PR-URL: https://github.com/nodejs/node/pull/60728 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
1 parent
420b6277bd
commit
ef6b8cc3c3
83 files changed
+429
-465
No files matched your search
@@ -197,7 +197,7 @@ export default [
|
||||
Array.from({ length: 4 }, (_, i) => String.fromCharCode(0x61 + i, 42)).join(',')
|
||||
},${
|
||||
// 0x61 is code for 'a', this generates a string enumerating latin letters: 'z*,y*,…'
|
||||
Array.from({ length: 5 }, (_, i) => String.fromCharCode(0x61 + 25 - i, 42)).join(',')
|
||||
Array.from({ length: 7 }, (_, i) => String.fromCharCode(0x61 + 25 - i, 42)).join(',')
|
||||
}}.{js,mjs,cjs}`,
|
||||
],
|
||||
rules: {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Flags: --expose-internals
|
||||
'use strict';
|
||||
require('../common');
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
const { internalBinding } = require('internal/test/binding');
|
||||
const {
|
||||
@@ -17,7 +17,7 @@ function makeConnection() {
|
||||
const err = client.connect(req, '127.0.0.1', this.address().port);
|
||||
assert.strictEqual(err, 0);
|
||||
|
||||
req.oncomplete = function(status, client_, req_, readable, writable) {
|
||||
req.oncomplete = common.mustCall((status, client_, req_, readable, writable) => {
|
||||
assert.strictEqual(status, 0);
|
||||
assert.strictEqual(client_, client);
|
||||
assert.strictEqual(req_, req);
|
||||
@@ -28,14 +28,14 @@ function makeConnection() {
|
||||
const err = client.shutdown(shutdownReq);
|
||||
assert.strictEqual(err, 0);
|
||||
|
||||
shutdownReq.oncomplete = function(status, client_, error) {
|
||||
shutdownReq.oncomplete = common.mustCall((status, client_, error) => {
|
||||
assert.strictEqual(status, 0);
|
||||
assert.strictEqual(client_, client);
|
||||
assert.strictEqual(error, undefined);
|
||||
shutdownCount++;
|
||||
client.close();
|
||||
};
|
||||
};
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
let connectCount = 0;
|
||||
|
||||
@@ -24,7 +24,7 @@ server.getsockname(port);
|
||||
|
||||
server.listen(128);
|
||||
|
||||
server.onconnection = (err, client) => {
|
||||
server.onconnection = common.mustCall((err, client) => {
|
||||
assert.strictEqual(client.writeQueueSize, 0);
|
||||
console.log('got connection');
|
||||
|
||||
@@ -82,7 +82,7 @@ server.onconnection = (err, client) => {
|
||||
maybeCloseClient();
|
||||
}
|
||||
}, 2);
|
||||
};
|
||||
});
|
||||
|
||||
const net = require('net');
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ process.once('uncaughtException', common.mustCall((err, errorOrigin) => {
|
||||
|
||||
const d1 = domain.create();
|
||||
d1.once('error', common.expectsError(errObj));
|
||||
d1.once('error', () => assert.strictEqual(stage, 0));
|
||||
d1.once('error', common.mustCall(() => assert.strictEqual(stage, 0)));
|
||||
|
||||
const run = common.mustCall((callStage) => {
|
||||
assert(callStage >= stage);
|
||||
|
||||
@@ -196,7 +196,7 @@ const { setInterval } = timerPromises;
|
||||
const { signal } = controller;
|
||||
const delay = 10;
|
||||
let totalIterations = 0;
|
||||
const timeoutLoop = runInterval(async (iterationNumber) => {
|
||||
const timeoutLoop = runInterval(common.mustCallAtLeast(async (iterationNumber) => {
|
||||
await setPromiseTimeout(delay * 4);
|
||||
if (iterationNumber <= 2) {
|
||||
assert.strictEqual(signal.aborted, false);
|
||||
@@ -210,7 +210,7 @@ const { setInterval } = timerPromises;
|
||||
if (iterationNumber > totalIterations) {
|
||||
totalIterations = iterationNumber;
|
||||
}
|
||||
}, delay, signal);
|
||||
}, 0), delay, signal);
|
||||
|
||||
timeoutLoop.catch(common.mustCall(() => {
|
||||
assert.ok(totalIterations >= 3, `iterations was ${totalIterations} < 3`);
|
||||
|
||||
@@ -4,11 +4,7 @@ const common = require('../common');
|
||||
|
||||
const { scheduler } = require('timers/promises');
|
||||
const { setTimeout } = require('timers');
|
||||
const {
|
||||
strictEqual,
|
||||
rejects,
|
||||
throws,
|
||||
} = require('assert');
|
||||
const assert = require('assert');
|
||||
|
||||
async function testYield() {
|
||||
await scheduler.yield();
|
||||
@@ -23,7 +19,7 @@ async function testWait() {
|
||||
let value = 0;
|
||||
setTimeout(() => value++, 10);
|
||||
await scheduler.wait(15);
|
||||
strictEqual(value, 1);
|
||||
assert.strictEqual(value, 1);
|
||||
}
|
||||
|
||||
testWait().then(common.mustCall());
|
||||
@@ -32,7 +28,7 @@ async function testCancelableWait1() {
|
||||
const ac = new AbortController();
|
||||
const wait = scheduler.wait(1e6, { signal: ac.signal });
|
||||
ac.abort();
|
||||
await rejects(wait, {
|
||||
await assert.rejects(wait, {
|
||||
code: 'ABORT_ERR',
|
||||
message: 'The operation was aborted',
|
||||
});
|
||||
@@ -42,7 +38,7 @@ testCancelableWait1().then(common.mustCall());
|
||||
|
||||
async function testCancelableWait2() {
|
||||
const wait = scheduler.wait(10000, { signal: AbortSignal.abort() });
|
||||
await rejects(wait, {
|
||||
await assert.rejects(wait, {
|
||||
code: 'ABORT_ERR',
|
||||
message: 'The operation was aborted',
|
||||
});
|
||||
@@ -50,6 +46,6 @@ async function testCancelableWait2() {
|
||||
|
||||
testCancelableWait2().then(common.mustCall());
|
||||
|
||||
throws(() => new scheduler.constructor(), {
|
||||
assert.throws(() => new scheduler.constructor(), {
|
||||
code: 'ERR_ILLEGAL_CONSTRUCTOR',
|
||||
});
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
const common = require('../common');
|
||||
|
||||
const { strictEqual, throws } = require('assert');
|
||||
const assert = require('assert');
|
||||
const { setUnrefTimeout } = require('internal/timers');
|
||||
|
||||
// Schedule the unrefed cases first so that the later case keeps the event loop
|
||||
@@ -24,16 +24,16 @@ const { setUnrefTimeout } = require('internal/timers');
|
||||
// This relies on implicit timers handle sorting within libuv.
|
||||
|
||||
setTimeout(common.mustCall(() => {
|
||||
strictEqual(called, false, 'unref()\'d timer returned before check');
|
||||
assert.strictEqual(called, false);
|
||||
}), 1);
|
||||
|
||||
strictEqual(timer.refresh(), timer);
|
||||
assert.strictEqual(timer.refresh(), timer);
|
||||
}
|
||||
|
||||
// Should throw with non-functions
|
||||
{
|
||||
[null, true, false, 0, 1, NaN, '', 'foo', {}, Symbol()].forEach((cb) => {
|
||||
throws(
|
||||
assert.throws(
|
||||
() => setUnrefTimeout(cb),
|
||||
{
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
@@ -50,10 +50,10 @@ const { setUnrefTimeout } = require('internal/timers');
|
||||
}), 1);
|
||||
|
||||
setUnrefTimeout(common.mustCall(() => {
|
||||
strictEqual(called, false, 'unref pooled timer returned before check');
|
||||
assert.strictEqual(called, false);
|
||||
}), 1);
|
||||
|
||||
strictEqual(timer.refresh(), timer);
|
||||
assert.strictEqual(timer.refresh(), timer);
|
||||
}
|
||||
|
||||
// regular timer
|
||||
@@ -64,10 +64,10 @@ const { setUnrefTimeout } = require('internal/timers');
|
||||
}), 1);
|
||||
|
||||
setTimeout(common.mustCall(() => {
|
||||
strictEqual(called, false, 'pooled timer returned before check');
|
||||
assert.strictEqual(called, false);
|
||||
}), 1);
|
||||
|
||||
strictEqual(timer.refresh(), timer);
|
||||
assert.strictEqual(timer.refresh(), timer);
|
||||
}
|
||||
|
||||
// regular timer
|
||||
@@ -78,7 +78,7 @@ const { setUnrefTimeout } = require('internal/timers');
|
||||
called = true;
|
||||
process.nextTick(common.mustCall(() => {
|
||||
timer.refresh();
|
||||
strictEqual(timer.hasRef(), true);
|
||||
assert.strictEqual(timer.hasRef(), true);
|
||||
}));
|
||||
}
|
||||
}, 2), 1);
|
||||
@@ -95,8 +95,8 @@ const { setUnrefTimeout } = require('internal/timers');
|
||||
}, 2), 1);
|
||||
|
||||
setTimeout(common.mustCall(() => {
|
||||
strictEqual(called, 0, 'pooled timer returned before check');
|
||||
assert.strictEqual(called, 0);
|
||||
}), 1);
|
||||
|
||||
strictEqual(timer.refresh(), timer);
|
||||
assert.strictEqual(timer.refresh(), timer);
|
||||
}
|
||||
@@ -9,11 +9,11 @@ process.once('uncaughtException', common.mustCall((err) => {
|
||||
}));
|
||||
|
||||
let called = false;
|
||||
const t = setTimeout(() => {
|
||||
const t = setTimeout(common.mustCall(() => {
|
||||
assert(!called);
|
||||
called = true;
|
||||
t.ref();
|
||||
throw new Error('Timeout Error');
|
||||
}, 1).unref();
|
||||
}), 1).unref();
|
||||
|
||||
setTimeout(common.mustCall(), 1);
|
||||
@@ -25,12 +25,12 @@ const common = require('../common');
|
||||
}
|
||||
|
||||
{
|
||||
const testInterval = (...args) => {
|
||||
const testInterval = common.mustCall((...args) => {
|
||||
const fn = common.mustCall(() => { clearInterval(interval); });
|
||||
fn.call = 'not a function';
|
||||
fn.apply = 'also not a function';
|
||||
const interval = setInterval(fn, 1, ...args);
|
||||
};
|
||||
}, 5);
|
||||
|
||||
testInterval();
|
||||
testInterval('oneArg');
|
||||
|
||||
@@ -22,7 +22,7 @@ const serverOptions = {
|
||||
|
||||
let connections = 0;
|
||||
|
||||
const server = tls.createServer(serverOptions, (c) => {
|
||||
const server = tls.createServer(serverOptions, common.mustCall((c) => {
|
||||
if (++connections === 3) {
|
||||
server.close();
|
||||
}
|
||||
@@ -31,7 +31,7 @@ const server = tls.createServer(serverOptions, (c) => {
|
||||
return;
|
||||
}
|
||||
assert.strictEqual(c.authorized, true);
|
||||
});
|
||||
}, 3));
|
||||
|
||||
const secureContext = {
|
||||
key: loadPEM('agent1-key'),
|
||||
|
||||
@@ -235,7 +235,7 @@ function TestALPNCallback() {
|
||||
ALPNProtocols: ['a'],
|
||||
}];
|
||||
|
||||
runTest(clientsOptions, serverOptions, function(results) {
|
||||
runTest(clientsOptions, serverOptions, common.mustCall((results) => {
|
||||
// Callback picks 2nd preference => picks 'b'
|
||||
checkResults(results[0],
|
||||
{ server: { ALPN: 'b' },
|
||||
@@ -247,7 +247,7 @@ function TestALPNCallback() {
|
||||
assert.ok(allowedErrors.includes(results[1].client.error.code), `'${results[1].client.error.code}' was not one of ${allowedErrors}.`);
|
||||
|
||||
TestBadALPNCallback();
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
function TestBadALPNCallback() {
|
||||
@@ -264,14 +264,14 @@ function TestBadALPNCallback() {
|
||||
assert.strictEqual(error.code, 'ERR_TLS_ALPN_CALLBACK_INVALID_RESULT');
|
||||
}));
|
||||
|
||||
runTest(clientsOptions, serverOptions, function(results) {
|
||||
runTest(clientsOptions, serverOptions, common.mustCall((results) => {
|
||||
// Callback returns 'http/5' => doesn't match client ALPN => error & reset
|
||||
assert.strictEqual(results[0].server, undefined);
|
||||
const allowedErrors = ['ECONNRESET', 'ERR_SSL_TLSV1_ALERT_NO_APPLICATION_PROTOCOL'];
|
||||
assert.ok(allowedErrors.includes(results[0].client.error.code), `'${results[0].client.error.code}' was not one of ${allowedErrors}.`);
|
||||
|
||||
TestALPNOptionsCallback();
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
function TestALPNOptionsCallback() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
'use strict';
|
||||
require('../common');
|
||||
const common = require('../common');
|
||||
const fixtures = require('../common/fixtures');
|
||||
|
||||
// Check cert chain is received by client, and is completed with the ca cert
|
||||
@@ -25,8 +25,7 @@ connect({
|
||||
key: keys.agent6.key,
|
||||
ca: agent6Middle,
|
||||
},
|
||||
}, function(err, pair, cleanup) {
|
||||
assert.ifError(err);
|
||||
}, common.mustSucceed((pair, cleanup) => {
|
||||
|
||||
const peer = pair.client.conn.getPeerCertificate();
|
||||
debug('peer:\n', peer);
|
||||
@@ -42,4 +41,4 @@ connect({
|
||||
assert.match(root.serialNumber, /4AB16C8DFD6A7D0D2DFCABDF9C4B0E92C6AD0229/i);
|
||||
|
||||
return cleanup();
|
||||
});
|
||||
}));
|
||||
@@ -18,9 +18,9 @@ function doCheck(arg, expression, check) {
|
||||
.on('error', common.mustNotCall())
|
||||
.stdout.on('data', function(chunk) {
|
||||
out += chunk;
|
||||
}).on('end', function() {
|
||||
}).on('end', common.mustCall(() => {
|
||||
assert.strictEqual(out.trim(), check);
|
||||
}).on('error', common.mustNotCall());
|
||||
})).on('error', common.mustNotCall());
|
||||
}
|
||||
|
||||
// Test the default unmodified version
|
||||
|
||||
@@ -8,7 +8,7 @@ const assert = require('assert');
|
||||
const child_process = require('child_process');
|
||||
|
||||
const args = ['--tls-min-v1.3', '--tls-max-v1.2', '-p', 'process.version'];
|
||||
child_process.execFile(process.argv[0], args, (err) => {
|
||||
child_process.execFile(process.argv[0], args, common.mustCall((err) => {
|
||||
assert(err);
|
||||
assert.match(err.message, /not both/);
|
||||
});
|
||||
}));
|
||||
@@ -47,10 +47,9 @@ connect({
|
||||
ca: client.ca,
|
||||
requestCert: true,
|
||||
},
|
||||
}, function(err, pair, cleanup) {
|
||||
assert.ifError(err);
|
||||
}, common.mustSucceed((pair, cleanup) => {
|
||||
return cleanup();
|
||||
});
|
||||
}));
|
||||
|
||||
// As above, but without requesting client's cert.
|
||||
connect({
|
||||
@@ -63,10 +62,9 @@ connect({
|
||||
cert: server.cert,
|
||||
ca: client.ca,
|
||||
},
|
||||
}, function(err, pair, cleanup) {
|
||||
assert.ifError(err);
|
||||
}, common.mustSucceed((pair, cleanup) => {
|
||||
return cleanup();
|
||||
});
|
||||
}));
|
||||
|
||||
// Request cert from TLS1.2 client that doesn't have one.
|
||||
connect({
|
||||
@@ -81,7 +79,7 @@ connect({
|
||||
ca: client.ca,
|
||||
requestCert: true,
|
||||
},
|
||||
}, function(err, pair, cleanup) {
|
||||
}, common.mustCall((err, pair, cleanup) => {
|
||||
assert.strictEqual(pair.server.err.code,
|
||||
'ERR_SSL_PEER_DID_NOT_RETURN_A_CERTIFICATE');
|
||||
const expectedErr = hasOpenSSL(3, 2) ?
|
||||
@@ -89,7 +87,7 @@ connect({
|
||||
assert.strictEqual(pair.client.err.code,
|
||||
expectedErr);
|
||||
return cleanup();
|
||||
});
|
||||
}));
|
||||
|
||||
// Request cert from TLS1.3 client that doesn't have one.
|
||||
if (tls.DEFAULT_MAX_VERSION === 'TLSv1.3') connect({
|
||||
@@ -103,7 +101,7 @@ if (tls.DEFAULT_MAX_VERSION === 'TLSv1.3') connect({
|
||||
ca: client.ca,
|
||||
requestCert: true,
|
||||
},
|
||||
}, function(err, pair, cleanup) {
|
||||
}, common.mustCall((err, pair, cleanup) => {
|
||||
assert.strictEqual(pair.server.err.code,
|
||||
'ERR_SSL_PEER_DID_NOT_RETURN_A_CERTIFICATE');
|
||||
|
||||
@@ -115,7 +113,7 @@ if (tls.DEFAULT_MAX_VERSION === 'TLSv1.3') connect({
|
||||
assert.strictEqual(err.code, 'ERR_SSL_TLSV13_ALERT_CERTIFICATE_REQUIRED');
|
||||
cleanup();
|
||||
}));
|
||||
});
|
||||
}));
|
||||
|
||||
// Typical configuration error, incomplete cert chains sent, we have to know the
|
||||
// peer's subordinate CAs in order to verify the peer.
|
||||
@@ -132,10 +130,9 @@ connect({
|
||||
ca: [client.ca, client.subca],
|
||||
requestCert: true,
|
||||
},
|
||||
}, function(err, pair, cleanup) {
|
||||
assert.ifError(err);
|
||||
}, common.mustSucceed((pair, cleanup) => {
|
||||
return cleanup();
|
||||
});
|
||||
}));
|
||||
|
||||
// Like above, but provide root CA and subordinate CA as multi-PEM.
|
||||
connect({
|
||||
@@ -151,10 +148,9 @@ connect({
|
||||
ca: client.ca + '\n' + client.subca,
|
||||
requestCert: true,
|
||||
},
|
||||
}, function(err, pair, cleanup) {
|
||||
assert.ifError(err);
|
||||
}, common.mustSucceed((pair, cleanup) => {
|
||||
return cleanup();
|
||||
});
|
||||
}));
|
||||
|
||||
// Like above, but provide multi-PEM in an array.
|
||||
connect({
|
||||
@@ -170,10 +166,9 @@ connect({
|
||||
ca: [client.ca + '\n' + client.subca],
|
||||
requestCert: true,
|
||||
},
|
||||
}, function(err, pair, cleanup) {
|
||||
assert.ifError(err);
|
||||
}, common.mustSucceed((pair, cleanup) => {
|
||||
return cleanup();
|
||||
});
|
||||
}));
|
||||
|
||||
// Fail to complete server's chain
|
||||
connect({
|
||||
@@ -185,10 +180,10 @@ connect({
|
||||
key: server.key,
|
||||
cert: server.single,
|
||||
},
|
||||
}, function(err, pair, cleanup) {
|
||||
}, common.mustCall((err, pair, cleanup) => {
|
||||
assert.strictEqual(err.code, 'UNABLE_TO_VERIFY_LEAF_SIGNATURE');
|
||||
return cleanup();
|
||||
});
|
||||
}));
|
||||
|
||||
// Fail to complete client's chain.
|
||||
connect({
|
||||
@@ -204,12 +199,12 @@ connect({
|
||||
ca: client.ca,
|
||||
requestCert: true,
|
||||
},
|
||||
}, function(err, pair, cleanup) {
|
||||
}, common.mustCall((err, pair, cleanup) => {
|
||||
assert.ifError(pair.client.error);
|
||||
assert.ifError(pair.server.error);
|
||||
assert.strictEqual(err.code, 'ECONNRESET');
|
||||
return cleanup();
|
||||
});
|
||||
}));
|
||||
|
||||
// Fail to find CA for server.
|
||||
connect({
|
||||
@@ -220,10 +215,10 @@ connect({
|
||||
key: server.key,
|
||||
cert: server.cert,
|
||||
},
|
||||
}, function(err, pair, cleanup) {
|
||||
}, common.mustCall((err, pair, cleanup) => {
|
||||
assert.strictEqual(err.code, 'UNABLE_TO_GET_ISSUER_CERT_LOCALLY');
|
||||
return cleanup();
|
||||
});
|
||||
}));
|
||||
|
||||
// Server sent their CA, but CA cannot be trusted if it is not locally known.
|
||||
connect({
|
||||
@@ -234,10 +229,10 @@ connect({
|
||||
key: server.key,
|
||||
cert: server.cert + '\n' + server.ca,
|
||||
},
|
||||
}, function(err, pair, cleanup) {
|
||||
}, common.mustCall((err, pair, cleanup) => {
|
||||
assert.strictEqual(err.code, 'SELF_SIGNED_CERT_IN_CHAIN');
|
||||
return cleanup();
|
||||
});
|
||||
}));
|
||||
|
||||
// Server sent their CA, wrongly, but its OK since we know the CA locally.
|
||||
connect({
|
||||
@@ -249,10 +244,9 @@ connect({
|
||||
key: server.key,
|
||||
cert: server.cert + '\n' + server.ca,
|
||||
},
|
||||
}, function(err, pair, cleanup) {
|
||||
assert.ifError(err);
|
||||
}, common.mustSucceed((pair, cleanup) => {
|
||||
return cleanup();
|
||||
});
|
||||
}));
|
||||
|
||||
// Fail to complete client's chain.
|
||||
connect({
|
||||
@@ -268,10 +262,10 @@ connect({
|
||||
ca: client.ca,
|
||||
requestCert: true,
|
||||
},
|
||||
}, function(err, pair, cleanup) {
|
||||
}, common.mustCall((err, pair, cleanup) => {
|
||||
assert.strictEqual(err.code, 'ECONNRESET');
|
||||
return cleanup();
|
||||
});
|
||||
}));
|
||||
|
||||
// Fail to find CA for client.
|
||||
connect({
|
||||
@@ -286,10 +280,10 @@ connect({
|
||||
cert: server.cert,
|
||||
requestCert: true,
|
||||
},
|
||||
}, function(err, pair, cleanup) {
|
||||
}, common.mustCall((err, pair, cleanup) => {
|
||||
assert.strictEqual(err.code, 'ECONNRESET');
|
||||
return cleanup();
|
||||
});
|
||||
}));
|
||||
|
||||
// Confirm support for "BEGIN TRUSTED CERTIFICATE".
|
||||
connect({
|
||||
@@ -305,10 +299,9 @@ connect({
|
||||
ca: client.ca,
|
||||
requestCert: true,
|
||||
},
|
||||
}, function(err, pair, cleanup) {
|
||||
assert.ifError(err);
|
||||
}, common.mustSucceed((pair, cleanup) => {
|
||||
return cleanup();
|
||||
});
|
||||
}));
|
||||
|
||||
// Confirm support for "BEGIN TRUSTED CERTIFICATE".
|
||||
connect({
|
||||
@@ -324,10 +317,9 @@ connect({
|
||||
ca: client.ca.replace(/CERTIFICATE/g, 'TRUSTED CERTIFICATE'),
|
||||
requestCert: true,
|
||||
},
|
||||
}, function(err, pair, cleanup) {
|
||||
assert.ifError(err);
|
||||
}, common.mustSucceed((pair, cleanup) => {
|
||||
return cleanup();
|
||||
});
|
||||
}));
|
||||
|
||||
// Confirm support for "BEGIN X509 CERTIFICATE".
|
||||
connect({
|
||||
@@ -343,10 +335,9 @@ connect({
|
||||
ca: client.ca,
|
||||
requestCert: true,
|
||||
},
|
||||
}, function(err, pair, cleanup) {
|
||||
assert.ifError(err);
|
||||
}, common.mustSucceed((pair, cleanup) => {
|
||||
return cleanup();
|
||||
});
|
||||
}));
|
||||
|
||||
// Confirm support for "BEGIN X509 CERTIFICATE".
|
||||
connect({
|
||||
@@ -362,7 +353,6 @@ connect({
|
||||
ca: client.ca.replace(/CERTIFICATE/g, 'X509 CERTIFICATE'),
|
||||
requestCert: true,
|
||||
},
|
||||
}, function(err, pair, cleanup) {
|
||||
assert.ifError(err);
|
||||
}, common.mustSucceed((pair, cleanup) => {
|
||||
return cleanup();
|
||||
});
|
||||
}));
|
||||
@@ -36,12 +36,12 @@ function test(size, err, next) {
|
||||
conn.end();
|
||||
});
|
||||
|
||||
server.on('close', function(isException) {
|
||||
server.on('close', common.mustCall(function(isException) {
|
||||
assert(!isException);
|
||||
if (next) next();
|
||||
});
|
||||
}));
|
||||
|
||||
server.listen(0, function() {
|
||||
server.listen(0, common.mustCall(function() {
|
||||
// Client set minimum DH parameter size to 2048 or 3072 bits
|
||||
// so that it fails when it makes a connection to the tls
|
||||
// server where is too small. This depends on the openssl
|
||||
@@ -57,13 +57,13 @@ function test(size, err, next) {
|
||||
server.close();
|
||||
});
|
||||
if (err) {
|
||||
client.on('error', function(e) {
|
||||
client.on('error', common.mustCall((e) => {
|
||||
nerror++;
|
||||
assert.strictEqual(e.code, 'ERR_TLS_DH_PARAM_SIZE');
|
||||
server.close();
|
||||
});
|
||||
}));
|
||||
}
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
// A client connection fails with an error when a client has an
|
||||
|
||||
@@ -26,9 +26,7 @@ connect({
|
||||
key: server.key,
|
||||
cert: server.cert,
|
||||
},
|
||||
}, function(err, pair, cleanup) {
|
||||
assert.ifError(err);
|
||||
|
||||
}, common.mustSucceed((pair, cleanup) => {
|
||||
const client = pair.client.conn;
|
||||
|
||||
assert.strictEqual(client.getProtocol(), 'TLSv1.3');
|
||||
@@ -46,4 +44,4 @@ connect({
|
||||
}));
|
||||
|
||||
assert.strictEqual(ok, false);
|
||||
});
|
||||
}));
|
||||
@@ -57,16 +57,16 @@ function test(next) {
|
||||
key: fixtures.readKey('rsa_private.pem'),
|
||||
};
|
||||
|
||||
const server = tls.createServer(options, (conn) => {
|
||||
conn.on('error', (err) => {
|
||||
const server = tls.createServer(options, common.mustCall((conn) => {
|
||||
conn.on('error', common.mustCall((err) => {
|
||||
console.error(`Caught exception: ${err}`);
|
||||
assert.match(err.message, /TLS session renegotiation attack/);
|
||||
conn.destroy();
|
||||
});
|
||||
}));
|
||||
conn.pipe(conn);
|
||||
});
|
||||
}));
|
||||
|
||||
server.listen(0, () => {
|
||||
server.listen(0, common.mustCall(() => {
|
||||
const options = {
|
||||
host: server.address().host,
|
||||
port: server.address().port,
|
||||
@@ -76,30 +76,27 @@ function test(next) {
|
||||
|
||||
let renegs = 0;
|
||||
|
||||
client.on('close', () => {
|
||||
client.on('close', common.mustCall(() => {
|
||||
assert.strictEqual(renegs, tls.CLIENT_RENEG_LIMIT + 1);
|
||||
server.close();
|
||||
process.nextTick(next);
|
||||
});
|
||||
}));
|
||||
|
||||
client.on('error', (err) => {
|
||||
console.log('CLIENT ERR', err);
|
||||
throw err;
|
||||
});
|
||||
client.on('error', common.mustNotCall('CLIENT ERR'));
|
||||
|
||||
client.on('close', (hadErr) => {
|
||||
client.on('close', common.mustCall((hadErr) => {
|
||||
assert.strictEqual(hadErr, false);
|
||||
});
|
||||
}));
|
||||
|
||||
// Simulate renegotiation attack
|
||||
function spam() {
|
||||
client.write('');
|
||||
client.renegotiate({}, (err) => {
|
||||
client.renegotiate({}, common.mustCallAtLeast((err) => {
|
||||
assert.ifError(err);
|
||||
assert.ok(renegs <= tls.CLIENT_RENEG_LIMIT);
|
||||
spam();
|
||||
});
|
||||
}, 0));
|
||||
renegs++;
|
||||
}
|
||||
});
|
||||
}));
|
||||
}
|
||||
@@ -75,10 +75,10 @@ server.listen(0, common.mustCall(function() {
|
||||
console.log('client1 session#', ++sessions);
|
||||
});
|
||||
|
||||
client1.on('close', () => {
|
||||
client1.on('close', common.mustCall(() => {
|
||||
console.log('client1 close');
|
||||
assert.strictEqual(sessions, tls13 ? 2 : 1);
|
||||
});
|
||||
}));
|
||||
|
||||
function reconnect() {
|
||||
assert(sessionx);
|
||||
|
||||
@@ -26,11 +26,11 @@ function test() {
|
||||
const server = tls.createServer({
|
||||
key: fixtures.readKey('agent1-key.pem'),
|
||||
cert: fixtures.readKey('agent1-cert.pem')
|
||||
}, (c) => {
|
||||
}, common.mustCall((c) => {
|
||||
c.on('close', common.mustCall(() => server.close()));
|
||||
sconn = c;
|
||||
test();
|
||||
}).listen(0, common.mustCall(function() {
|
||||
})).listen(0, common.mustCall(function() {
|
||||
tls.connect(this.address().port, {
|
||||
rejectUnauthorized: false
|
||||
}, common.mustCall(function() {
|
||||
|
||||
@@ -34,12 +34,12 @@ const { ShutdownWrap } = internalBinding('stream_wrap');
|
||||
const server = tls.createServer({
|
||||
key: fixtures.readKey('agent1-key.pem'),
|
||||
cert: fixtures.readKey('agent1-cert.pem')
|
||||
}, function(c) {
|
||||
}, common.mustCall((c) => {
|
||||
// Ensure that we receive 'end' event anyway.
|
||||
c.on('end', common.mustCall(function() {
|
||||
server.close();
|
||||
}));
|
||||
}).listen(0, common.mustCall(function() {
|
||||
})).listen(0, common.mustCall(function() {
|
||||
const c = tls.connect(this.address().port, {
|
||||
rejectUnauthorized: false
|
||||
}, common.mustCall(function() {
|
||||
|
||||
@@ -59,11 +59,11 @@ server.listen(0, common.mustCall(() => {
|
||||
socket.on('end', common.mustCall(() => {
|
||||
assert.strictEqual(message, 'Hello');
|
||||
|
||||
setTimeout(() => {
|
||||
setTimeout(common.mustCall(() => {
|
||||
assert(socket.writable);
|
||||
assert(socket.write('Bye'));
|
||||
socket.end();
|
||||
}, 50);
|
||||
}), 50);
|
||||
}));
|
||||
|
||||
socket.write('Hello');
|
||||
|
||||
@@ -58,9 +58,9 @@ const gcListener = { ongc() { collected = true; } };
|
||||
|
||||
function done(sock) {
|
||||
globalThis.gc();
|
||||
setImmediate(() => {
|
||||
setImmediate(common.mustCall(() => {
|
||||
assert.strictEqual(collected, true);
|
||||
sock.end();
|
||||
server.close();
|
||||
});
|
||||
}));
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
'use strict';
|
||||
require('../common');
|
||||
const common = require('../common');
|
||||
|
||||
// Verify connection with explicitly created client SecureContext.
|
||||
|
||||
const fixtures = require('../common/fixtures');
|
||||
const {
|
||||
assert, connect, keys, tls
|
||||
connect, keys, tls
|
||||
} = require(fixtures.path('tls-connect'));
|
||||
|
||||
connect({
|
||||
@@ -19,10 +19,9 @@ connect({
|
||||
cert: keys.agent1.cert,
|
||||
key: keys.agent1.key,
|
||||
},
|
||||
}, function(err, pair, cleanup) {
|
||||
assert.ifError(err);
|
||||
}, common.mustSucceed((pair, cleanup) => {
|
||||
return cleanup();
|
||||
});
|
||||
}));
|
||||
|
||||
connect({
|
||||
client: {
|
||||
@@ -47,7 +46,6 @@ connect({
|
||||
cert: keys.agent1.cert,
|
||||
key: keys.agent1.key,
|
||||
},
|
||||
}, function(err, pair, cleanup) {
|
||||
assert.ifError(err);
|
||||
}, common.mustSucceed((pair, cleanup) => {
|
||||
return cleanup();
|
||||
});
|
||||
}));
|
||||
@@ -42,7 +42,7 @@ const server = tls.Server(options, common.mustCall(function(socket) {
|
||||
}
|
||||
}, 2));
|
||||
|
||||
server.listen(0, function() {
|
||||
server.listen(0, common.mustCall(function() {
|
||||
const client1options = {
|
||||
port: this.address().port,
|
||||
rejectUnauthorized: false
|
||||
@@ -59,4 +59,4 @@ server.listen(0, function() {
|
||||
client2.on('secureConnect', common.mustCall(function() {
|
||||
client2.end();
|
||||
}));
|
||||
});
|
||||
}));
|
||||
@@ -44,7 +44,7 @@ const options = {
|
||||
};
|
||||
|
||||
const server = net.createServer(common.mustCall((c) => {
|
||||
setTimeout(function() {
|
||||
setTimeout(common.mustCall(() => {
|
||||
const s = new tls.TLSSocket(c, {
|
||||
isServer: true,
|
||||
secureContext: tls.createSecureContext(options)
|
||||
@@ -58,7 +58,7 @@ const server = net.createServer(common.mustCall((c) => {
|
||||
server.close();
|
||||
s.destroy();
|
||||
}));
|
||||
}, 200);
|
||||
}), 200);
|
||||
})).listen(0, common.mustCall(() => {
|
||||
const c = tls.connect(server.address().port, {
|
||||
rejectUnauthorized: false
|
||||
|
||||
@@ -22,22 +22,22 @@ const tlsServer = tls.createServer(
|
||||
cert: fixtures.readKey('rsa_cert.crt'),
|
||||
ca: [fixtures.readKey('rsa_ca.crt')],
|
||||
},
|
||||
(socket) => {
|
||||
common.mustCall((socket) => {
|
||||
socket.on('close', common.mustCall());
|
||||
socket.write(CONTENT);
|
||||
socket.destroy();
|
||||
|
||||
socket.on('error', (err) => {
|
||||
socket.on('error', common.mustCallAtLeast((err) => {
|
||||
// destroy() is sync, write() is async, whether write completes depends
|
||||
// on the protocol, it is not guaranteed by stream API.
|
||||
if (err.code === 'ERR_STREAM_DESTROYED')
|
||||
return;
|
||||
assert.ifError(err);
|
||||
});
|
||||
},
|
||||
}, 0));
|
||||
}),
|
||||
);
|
||||
|
||||
const server = net.createServer((conn) => {
|
||||
const server = net.createServer(common.mustCall((conn) => {
|
||||
conn.on('error', common.mustNotCall());
|
||||
// Assume that we want to use data to determine what to do with connections.
|
||||
conn.once('data', common.mustCall((chunk) => {
|
||||
@@ -61,17 +61,17 @@ const server = net.createServer((conn) => {
|
||||
|
||||
tlsServer.emit('connection', serverSide);
|
||||
}));
|
||||
});
|
||||
}));
|
||||
|
||||
server.listen(0, () => {
|
||||
server.listen(0, common.mustCall(() => {
|
||||
const port = server.address().port;
|
||||
const conn = tls.connect({ port, rejectUnauthorized: false }, () => {
|
||||
const conn = tls.connect({ port, rejectUnauthorized: false }, common.mustCall(() => {
|
||||
// Whether the server's write() completed before its destroy() is
|
||||
// indeterminate, but if data was written, we should receive it correctly.
|
||||
conn.on('data', (data) => {
|
||||
conn.on('data', common.mustCallAtLeast((data) => {
|
||||
assert.strictEqual(data.toString('utf8'), CONTENT);
|
||||
});
|
||||
}, 0));
|
||||
conn.on('error', common.mustNotCall());
|
||||
conn.on('close', common.mustCall(() => server.close()));
|
||||
});
|
||||
});
|
||||
}));
|
||||
}));
|
||||
@@ -34,11 +34,11 @@ let clientError = null;
|
||||
const server = tls.createServer({
|
||||
cert: fixtures.readKey('agent1-cert.pem'),
|
||||
key: fixtures.readKey('agent1-key.pem'),
|
||||
}, common.mustNotCall()).on('tlsClientError', function(err, conn) {
|
||||
}, common.mustNotCall()).on('tlsClientError', common.mustCall(function(err, conn) {
|
||||
assert(!clientError && conn);
|
||||
clientError = err;
|
||||
server.close();
|
||||
}).listen(0, function() {
|
||||
})).listen(0, function() {
|
||||
net.connect(this.address().port, function() {
|
||||
// Destroy the socket once it is connected, so the server sees ECONNRESET.
|
||||
this.destroy();
|
||||
|
||||
@@ -92,11 +92,11 @@ const server = net.createServer(common.mustCall((s) => {
|
||||
tlsSocket.end();
|
||||
server.close();
|
||||
}));
|
||||
})).listen(0, () => {
|
||||
})).listen(0, common.mustCall(() => {
|
||||
const opts = {
|
||||
port: server.address().port,
|
||||
rejectUnauthorized: false
|
||||
};
|
||||
|
||||
tls.connect(opts, common.mustCall(function() { this.end(); }));
|
||||
});
|
||||
}));
|
||||
@@ -37,7 +37,7 @@ let gotChunk = false;
|
||||
let gotDrain = false;
|
||||
|
||||
function onconnection(conn) {
|
||||
conn.on('data', function(c) {
|
||||
conn.on('data', common.mustCall(function(c) {
|
||||
if (!gotChunk) {
|
||||
gotChunk = true;
|
||||
console.log('ok - got chunk');
|
||||
@@ -49,7 +49,7 @@ function onconnection(conn) {
|
||||
|
||||
if (gotDrain)
|
||||
process.exit(0);
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
server.listen(0, function() {
|
||||
|
||||
@@ -38,7 +38,7 @@ if (!process.features.openssl_is_boringssl) {
|
||||
}
|
||||
|
||||
const server = tls.createServer(serverConfig, common.mustCall(clientConfigs.length))
|
||||
.listen(0, common.localhostIPv4, function() {
|
||||
.listen(0, common.localhostIPv4, common.mustCall(function() {
|
||||
let connected = 0;
|
||||
for (const v of clientConfigs) {
|
||||
tls.connect({
|
||||
@@ -57,4 +57,4 @@ const server = tls.createServer(serverConfig, common.mustCall(clientConfigs.leng
|
||||
server.close();
|
||||
}));
|
||||
}
|
||||
});
|
||||
}));
|
||||
@@ -59,8 +59,8 @@ const b = tls.createServer(options, function(socket) {
|
||||
socket.end(body);
|
||||
});
|
||||
|
||||
a.listen(0, function() {
|
||||
b.listen(0, function() {
|
||||
a.listen(0, common.mustCall(function() {
|
||||
b.listen(0, common.mustCall(function() {
|
||||
const myOptions = {
|
||||
host: '127.0.0.1',
|
||||
port: a.address().port,
|
||||
@@ -82,5 +82,5 @@ a.listen(0, function() {
|
||||
a.close();
|
||||
b.close();
|
||||
}));
|
||||
});
|
||||
});
|
||||
}));
|
||||
}));
|
||||
@@ -48,9 +48,9 @@ const server = tls.createServer(options, function(c) {
|
||||
});
|
||||
}).listen(0, common.mustCall(function() {
|
||||
const connectOpts = { rejectUnauthorized: false };
|
||||
const c = tls.connect(this.address().port, connectOpts, function() {
|
||||
const c = tls.connect(this.address().port, connectOpts, common.mustCall(function() {
|
||||
c.write('some client data');
|
||||
c.on('readable', function() {
|
||||
c.on('readable', common.mustCallAtLeast(() => {
|
||||
let data = c.read();
|
||||
if (data === null)
|
||||
return;
|
||||
@@ -65,8 +65,8 @@ const server = tls.createServer(options, function(c) {
|
||||
server.close();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}));
|
||||
}));
|
||||
}));
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
const { throws } = require('assert');
|
||||
const assert = require('assert');
|
||||
|
||||
if (!common.hasCrypto)
|
||||
common.skip('missing crypto');
|
||||
@@ -10,7 +10,7 @@ const tls = require('tls');
|
||||
|
||||
// Verify that passing an IP address the the servername option
|
||||
// throws an error.
|
||||
throws(() => tls.connect({
|
||||
assert.throws(() => tls.connect({
|
||||
port: 1234,
|
||||
servername: '127.0.0.1',
|
||||
}, common.mustNotCall()), {
|
||||
|
||||
@@ -19,7 +19,7 @@ const server = net.createServer(function(s) {
|
||||
});
|
||||
});
|
||||
|
||||
server.listen(0, function() {
|
||||
server.listen(0, common.mustCall(function() {
|
||||
const req = https.request({ port: this.address().port });
|
||||
req.end();
|
||||
|
||||
@@ -31,4 +31,4 @@ server.listen(0, function() {
|
||||
assert(expectedErrorMessage.test(err.message));
|
||||
server.close();
|
||||
}));
|
||||
});
|
||||
}));
|
||||
@@ -15,7 +15,7 @@ const server = tls.createServer({
|
||||
// version, so force a specific one:
|
||||
minVersion: 'TLSv1.3',
|
||||
maxVersion: 'TLSv1.3',
|
||||
}).listen(() => {
|
||||
}).listen(common.mustCall(() => {
|
||||
const client = tls.connect({
|
||||
port: server.address().port,
|
||||
rejectUnauthorized: false,
|
||||
@@ -33,4 +33,4 @@ const server = tls.createServer({
|
||||
server.close();
|
||||
client.end();
|
||||
});
|
||||
});
|
||||
}));
|
||||
@@ -41,7 +41,7 @@ const invalidArgumentError = {
|
||||
const server = tls.createServer({
|
||||
key: fixtures.readKey('agent1-key.pem'),
|
||||
cert: fixtures.readKey('agent1-cert.pem')
|
||||
}, function(c) {
|
||||
}, common.mustCall((c) => {
|
||||
|
||||
// No size is passed.
|
||||
assert.throws(() => c.setMaxSendFragment(), invalidArgumentError);
|
||||
@@ -68,14 +68,14 @@ const server = tls.createServer({
|
||||
assert(c.setMaxSendFragment(maxChunk));
|
||||
|
||||
c.end(buf);
|
||||
}).listen(0, common.mustCall(function() {
|
||||
})).listen(0, common.mustCall(function() {
|
||||
const c = tls.connect(this.address().port, {
|
||||
rejectUnauthorized: false
|
||||
}, common.mustCall(function() {
|
||||
c.on('data', function(chunk) {
|
||||
c.on('data', common.mustCallAtLeast((chunk) => {
|
||||
assert(chunk.length <= maxChunk);
|
||||
received += chunk.length;
|
||||
});
|
||||
}));
|
||||
|
||||
// Ensure that we receive 'end' event anyway
|
||||
c.on('end', common.mustCall(function() {
|
||||
|
||||
@@ -153,8 +153,8 @@ function test(options) {
|
||||
ciphers: 'ECDHE-ECDSA-AES256-GCM-SHA384',
|
||||
rejectUnauthorized: true,
|
||||
ca: clientTrustRoots,
|
||||
checkServerIdentity: (_, c) => assert.strictEqual(c.subject.CN, eccCN),
|
||||
maxVersion: 'TLSv1.2'
|
||||
checkServerIdentity: common.mustCall((_, c) => assert.strictEqual(c.subject.CN, eccCN)),
|
||||
maxVersion: 'TLSv1.2',
|
||||
}, common.mustCall(function() {
|
||||
assert.deepStrictEqual(ecdsa.getCipher(), {
|
||||
name: 'ECDHE-ECDSA-AES256-GCM-SHA384',
|
||||
@@ -174,7 +174,7 @@ function test(options) {
|
||||
ciphers: 'ECDHE-RSA-AES256-GCM-SHA384',
|
||||
rejectUnauthorized: true,
|
||||
ca: clientTrustRoots,
|
||||
checkServerIdentity: (_, c) => assert.strictEqual(c.subject.CN, rsaCN),
|
||||
checkServerIdentity: common.mustCallAtLeast((_, c) => assert.strictEqual(c.subject.CN, rsaCN)),
|
||||
maxVersion: 'TLSv1.2',
|
||||
}, common.mustCall(function() {
|
||||
assert.deepStrictEqual(rsa.getCipher(), {
|
||||
|
||||
@@ -21,7 +21,7 @@ const ciphers = [];
|
||||
|
||||
const server = tls.createServer(options, function(conn) {
|
||||
conn.end('ok');
|
||||
}).listen(0, function() {
|
||||
}).listen(0, common.mustCall(function() {
|
||||
const ecdsa = tls.connect(this.address().port, {
|
||||
ciphers: 'ECDHE-ECDSA-AES256-GCM-SHA384',
|
||||
maxVersion: 'TLSv1.2',
|
||||
@@ -39,7 +39,7 @@ const server = tls.createServer(options, function(conn) {
|
||||
server.close();
|
||||
}));
|
||||
}));
|
||||
});
|
||||
}));
|
||||
|
||||
process.on('exit', function() {
|
||||
assert.deepStrictEqual(ciphers, [{
|
||||
|
||||
@@ -38,14 +38,14 @@ function mkServer(lib, tcp, cb) {
|
||||
}
|
||||
|
||||
function testLib(lib, cb) {
|
||||
mkServer(lib, true, (tcpServer) => {
|
||||
mkServer(lib, false, (unixServer) => {
|
||||
mkServer(lib, true, common.mustCall((tcpServer) => {
|
||||
mkServer(lib, false, common.mustCall((unixServer) => {
|
||||
const client = lib.connect({
|
||||
path: unixServer.address(),
|
||||
port: tcpServer.address().port,
|
||||
host: 'localhost',
|
||||
rejectUnauthorized: false
|
||||
}, () => {
|
||||
}, common.mustCall(() => {
|
||||
const bufs = [];
|
||||
client.on('data', common.mustCall((d) => {
|
||||
bufs.push(d);
|
||||
@@ -57,9 +57,9 @@ function testLib(lib, cb) {
|
||||
unixServer.close();
|
||||
cb();
|
||||
}));
|
||||
});
|
||||
});
|
||||
});
|
||||
}));
|
||||
}));
|
||||
}));
|
||||
}
|
||||
|
||||
testLib(net, common.mustCall(() => testLib(tls, common.mustCall())));
|
||||
@@ -44,9 +44,9 @@ const server = tls.createServer(options, function(conn) {
|
||||
server.close();
|
||||
}));
|
||||
|
||||
c.on('data', function(data) {
|
||||
c.on('data', common.mustCallAtLeast((data) => {
|
||||
assert.strictEqual(data.toString(), 'ok');
|
||||
});
|
||||
}));
|
||||
|
||||
const cert = c.getPeerCertificate();
|
||||
assert.strictEqual(cert.subject.C, 'US');
|
||||
|
||||
@@ -21,7 +21,7 @@ const server = tls.createServer({ cert, key }, common.mustNotCall());
|
||||
const errors = [];
|
||||
let stderr = '';
|
||||
|
||||
server.listen(0, '127.0.0.1', function() {
|
||||
server.listen(0, '127.0.0.1', common.mustCall(function() {
|
||||
const address = `${this.address().address}:${this.address().port}`;
|
||||
const args = ['s_client',
|
||||
'-ssl3',
|
||||
@@ -37,7 +37,7 @@ server.listen(0, '127.0.0.1', function() {
|
||||
assert.strictEqual(exitCode, 1);
|
||||
server.close();
|
||||
}));
|
||||
});
|
||||
}));
|
||||
|
||||
server.on('tlsClientError', (err) => errors.push(err));
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ function test(testOptions, cb) {
|
||||
Buffer.from(testOptions.response) : null);
|
||||
}));
|
||||
|
||||
server.listen(0, function() {
|
||||
server.listen(0, common.mustCall(function() {
|
||||
const client = tls.connect({
|
||||
port: this.address().port,
|
||||
requestOCSP: testOptions.ocsp,
|
||||
@@ -100,7 +100,7 @@ function test(testOptions, cb) {
|
||||
client.on('close', common.mustCall(() => {
|
||||
server.close(cb);
|
||||
}));
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
test({ ocsp: true, response: false });
|
||||
|
||||
@@ -20,7 +20,7 @@ const largeMessage = Buffer.alloc(64 * 1024).fill('hello world');
|
||||
tls.createServer(options, common.mustCall(function(socket) {
|
||||
this.close();
|
||||
socket.end(smallMessage);
|
||||
})).listen(0, function() {
|
||||
})).listen(0, common.mustCall(function() {
|
||||
let received = 0;
|
||||
const buffers = [];
|
||||
const sockBuf = Buffer.alloc(8);
|
||||
@@ -29,23 +29,23 @@ tls.createServer(options, common.mustCall(function(socket) {
|
||||
rejectUnauthorized: false,
|
||||
onread: {
|
||||
buffer: sockBuf,
|
||||
callback: function(nread, buf) {
|
||||
callback: common.mustCallAtLeast((nread, buf) => {
|
||||
assert.strictEqual(buf, sockBuf);
|
||||
received += nread;
|
||||
buffers.push(Buffer.from(buf.slice(0, nread)));
|
||||
}
|
||||
})
|
||||
}
|
||||
}).on('data', common.mustNotCall()).on('end', common.mustCall(() => {
|
||||
assert.strictEqual(received, smallMessage.length);
|
||||
assert.deepStrictEqual(Buffer.concat(buffers), smallMessage);
|
||||
}));
|
||||
});
|
||||
}));
|
||||
|
||||
// Test Uint8Array support
|
||||
tls.createServer(options, common.mustCall(function(socket) {
|
||||
this.close();
|
||||
socket.end(smallMessage);
|
||||
})).listen(0, function() {
|
||||
})).listen(0, common.mustCall(function() {
|
||||
let received = 0;
|
||||
let incoming = new Uint8Array(0);
|
||||
const sockBuf = new Uint8Array(8);
|
||||
@@ -54,26 +54,26 @@ tls.createServer(options, common.mustCall(function(socket) {
|
||||
rejectUnauthorized: false,
|
||||
onread: {
|
||||
buffer: sockBuf,
|
||||
callback: function(nread, buf) {
|
||||
callback: common.mustCallAtLeast((nread, buf) => {
|
||||
assert.strictEqual(buf, sockBuf);
|
||||
received += nread;
|
||||
const newIncoming = new Uint8Array(incoming.length + nread);
|
||||
newIncoming.set(incoming);
|
||||
newIncoming.set(buf.slice(0, nread), incoming.length);
|
||||
incoming = newIncoming;
|
||||
}
|
||||
})
|
||||
}
|
||||
}).on('data', common.mustNotCall()).on('end', common.mustCall(() => {
|
||||
assert.strictEqual(received, smallMessage.length);
|
||||
assert.deepStrictEqual(incoming, new Uint8Array(smallMessage));
|
||||
}));
|
||||
});
|
||||
}));
|
||||
|
||||
// Test Buffer callback usage
|
||||
tls.createServer(options, common.mustCall(function(socket) {
|
||||
this.close();
|
||||
socket.end(smallMessage);
|
||||
})).listen(0, function() {
|
||||
})).listen(0, common.mustCall(function() {
|
||||
let received = 0;
|
||||
const incoming = [];
|
||||
const bufPool = [ Buffer.alloc(2), Buffer.alloc(2), Buffer.alloc(2) ];
|
||||
@@ -88,24 +88,24 @@ tls.createServer(options, common.mustCall(function(socket) {
|
||||
bufPoolIdx = (bufPoolIdx + 1) % bufPool.length;
|
||||
return bufPool[bufPoolIdx];
|
||||
},
|
||||
callback: function(nread, buf) {
|
||||
callback: common.mustCallAtLeast((nread, buf) => {
|
||||
assert.strictEqual(buf, bufPool[bufPoolIdx]);
|
||||
received += nread;
|
||||
incoming.push(Buffer.from(buf.slice(0, nread)));
|
||||
}
|
||||
})
|
||||
}
|
||||
}).on('data', common.mustNotCall()).on('end', common.mustCall(() => {
|
||||
assert.strictEqual(received, smallMessage.length);
|
||||
assert.deepStrictEqual(Buffer.concat(incoming), smallMessage);
|
||||
assert.strictEqual(bufPoolUsage, 7);
|
||||
}));
|
||||
});
|
||||
}));
|
||||
|
||||
// Test Uint8Array callback support
|
||||
tls.createServer(options, common.mustCall(function(socket) {
|
||||
this.close();
|
||||
socket.end(smallMessage);
|
||||
})).listen(0, function() {
|
||||
})).listen(0, common.mustCall(function() {
|
||||
let received = 0;
|
||||
let incoming = new Uint8Array(0);
|
||||
const bufPool = [ new Uint8Array(2), new Uint8Array(2), new Uint8Array(2) ];
|
||||
@@ -120,28 +120,28 @@ tls.createServer(options, common.mustCall(function(socket) {
|
||||
bufPoolIdx = (bufPoolIdx + 1) % bufPool.length;
|
||||
return bufPool[bufPoolIdx];
|
||||
},
|
||||
callback: function(nread, buf) {
|
||||
callback: common.mustCallAtLeast((nread, buf) => {
|
||||
assert.strictEqual(buf, bufPool[bufPoolIdx]);
|
||||
received += nread;
|
||||
const newIncoming = new Uint8Array(incoming.length + nread);
|
||||
newIncoming.set(incoming);
|
||||
newIncoming.set(buf.slice(0, nread), incoming.length);
|
||||
incoming = newIncoming;
|
||||
}
|
||||
}),
|
||||
}
|
||||
}).on('data', common.mustNotCall()).on('end', common.mustCall(() => {
|
||||
assert.strictEqual(received, smallMessage.length);
|
||||
assert.deepStrictEqual(incoming, new Uint8Array(smallMessage));
|
||||
assert.strictEqual(bufPoolUsage, 7);
|
||||
}));
|
||||
});
|
||||
}));
|
||||
|
||||
// Test explicit socket pause
|
||||
tls.createServer(options, common.mustCall(function(socket) {
|
||||
this.close();
|
||||
// Need larger message here to observe the pause
|
||||
socket.end(largeMessage);
|
||||
})).listen(0, function() {
|
||||
})).listen(0, common.mustCall(function() {
|
||||
let received = 0;
|
||||
const buffers = [];
|
||||
const sockBuf = Buffer.alloc(64);
|
||||
@@ -151,7 +151,7 @@ tls.createServer(options, common.mustCall(function(socket) {
|
||||
rejectUnauthorized: false,
|
||||
onread: {
|
||||
buffer: sockBuf,
|
||||
callback: function(nread, buf) {
|
||||
callback: common.mustCallAtLeast((nread, buf) => {
|
||||
assert.strictEqual(buf, sockBuf);
|
||||
received += nread;
|
||||
buffers.push(Buffer.from(buf.slice(0, nread)));
|
||||
@@ -162,20 +162,20 @@ tls.createServer(options, common.mustCall(function(socket) {
|
||||
client.resume();
|
||||
}, 100);
|
||||
}
|
||||
}
|
||||
}),
|
||||
}
|
||||
}).on('data', common.mustNotCall()).on('end', common.mustCall(() => {
|
||||
assert.strictEqual(received, largeMessage.length);
|
||||
assert.deepStrictEqual(Buffer.concat(buffers), largeMessage);
|
||||
}));
|
||||
});
|
||||
}));
|
||||
|
||||
// Test implicit socket pause
|
||||
tls.createServer(options, common.mustCall(function(socket) {
|
||||
this.close();
|
||||
// Need larger message here to observe the pause
|
||||
socket.end(largeMessage);
|
||||
})).listen(0, function() {
|
||||
})).listen(0, common.mustCall(function() {
|
||||
let received = 0;
|
||||
const buffers = [];
|
||||
const sockBuf = Buffer.alloc(64);
|
||||
@@ -185,7 +185,7 @@ tls.createServer(options, common.mustCall(function(socket) {
|
||||
rejectUnauthorized: false,
|
||||
onread: {
|
||||
buffer: sockBuf,
|
||||
callback: function(nread, buf) {
|
||||
callback: common.mustCallAtLeast((nread, buf) => {
|
||||
assert.strictEqual(buf, sockBuf);
|
||||
received += nread;
|
||||
buffers.push(Buffer.from(buf.slice(0, nread)));
|
||||
@@ -197,10 +197,10 @@ tls.createServer(options, common.mustCall(function(socket) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}),
|
||||
}
|
||||
}).on('data', common.mustNotCall()).on('end', common.mustCall(() => {
|
||||
assert.strictEqual(received, largeMessage.length);
|
||||
assert.deepStrictEqual(Buffer.concat(buffers), largeMessage);
|
||||
}));
|
||||
});
|
||||
}));
|
||||
@@ -49,12 +49,12 @@ const server = https.createServer(options, common.mustCall((req, res) => {
|
||||
res.end('hello world\n');
|
||||
}));
|
||||
|
||||
const proxy = net.createServer((clientSocket) => {
|
||||
const proxy = net.createServer(common.mustCall((clientSocket) => {
|
||||
console.log('PROXY: got a client connection');
|
||||
|
||||
let serverSocket = null;
|
||||
|
||||
clientSocket.on('data', (chunk) => {
|
||||
clientSocket.on('data', common.mustCallAtLeast((chunk) => {
|
||||
if (!serverSocket) {
|
||||
// Verify the CONNECT request
|
||||
assert.strictEqual(chunk.toString(),
|
||||
@@ -87,12 +87,12 @@ const proxy = net.createServer((clientSocket) => {
|
||||
} else {
|
||||
serverSocket.write(chunk);
|
||||
}
|
||||
});
|
||||
}));
|
||||
|
||||
clientSocket.on('end', () => {
|
||||
serverSocket.destroy();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
server.listen(0);
|
||||
|
||||
@@ -148,7 +148,7 @@ proxy.listen(0, common.mustCall(() => {
|
||||
socket: socket, // reuse the socket
|
||||
agent: false,
|
||||
rejectUnauthorized: false
|
||||
}, (res) => {
|
||||
}, common.mustCall((res) => {
|
||||
assert.strictEqual(res.statusCode, 200);
|
||||
|
||||
res.on('data', common.mustCall((chunk) => {
|
||||
@@ -161,7 +161,7 @@ proxy.listen(0, common.mustCall(() => {
|
||||
proxy.close();
|
||||
server.close();
|
||||
}));
|
||||
}).on('error', (er) => {
|
||||
})).on('error', (er) => {
|
||||
// We're ok with getting ECONNRESET in this test, but it's
|
||||
// timing-dependent, and thus unreliable. Any other errors
|
||||
// are just failures, though.
|
||||
|
||||
@@ -73,7 +73,7 @@ server.listen(0, common.mustCall(() => {
|
||||
console.error('resumed', client);
|
||||
})();
|
||||
}));
|
||||
client.on('data', (data) => {
|
||||
client.on('data', common.mustCallAtLeast((data) => {
|
||||
console.error('data');
|
||||
assert.ok(resumed);
|
||||
received += data.length;
|
||||
@@ -84,7 +84,7 @@ server.listen(0, common.mustCall(() => {
|
||||
client.end();
|
||||
server.close();
|
||||
}
|
||||
});
|
||||
}));
|
||||
}));
|
||||
|
||||
process.on('exit', () => {
|
||||
|
||||
@@ -40,8 +40,7 @@ function sha256(s) {
|
||||
connect({
|
||||
client: { rejectUnauthorized: false },
|
||||
server: keys.agent1,
|
||||
}, function(err, pair, cleanup) {
|
||||
assert.ifError(err);
|
||||
}, common.mustSucceed((pair, cleanup) => {
|
||||
const socket = pair.client.conn;
|
||||
const localCert = socket.getCertificate();
|
||||
assert.deepStrictEqual(localCert, {});
|
||||
@@ -98,13 +97,12 @@ connect({
|
||||
assert.strictEqual(issuer.serialNumber, '4AB16C8DFD6A7D0D2DFCABDF9C4B0E92C6AD0229');
|
||||
|
||||
return cleanup();
|
||||
});
|
||||
}));
|
||||
|
||||
connect({
|
||||
client: { rejectUnauthorized: false },
|
||||
server: keys.ec,
|
||||
}, function(err, pair, cleanup) {
|
||||
assert.ifError(err);
|
||||
}, common.mustSucceed((pair, cleanup) => {
|
||||
const socket = pair.client.conn;
|
||||
let peerCert = socket.getPeerCertificate(true);
|
||||
assert.ok(peerCert.issuerCertificate);
|
||||
@@ -149,4 +147,4 @@ connect({
|
||||
assert.strictEqual(issuer.serialNumber, '32E8197681DA33185867B52885F678BFDBA51727');
|
||||
|
||||
return cleanup();
|
||||
});
|
||||
}));
|
||||
@@ -28,7 +28,7 @@ const server = tls
|
||||
c.end();
|
||||
})
|
||||
)
|
||||
.listen(0, function() {
|
||||
.listen(0, common.mustCall(function() {
|
||||
const client = tls.connect(
|
||||
{
|
||||
port: this.address().port,
|
||||
@@ -36,7 +36,7 @@ const server = tls
|
||||
passphrase: 'sample',
|
||||
rejectUnauthorized: false
|
||||
},
|
||||
function() {
|
||||
common.mustCall(() => {
|
||||
for (let i = 0; i < 10; ++i) {
|
||||
// Calling this repeatedly is a regression test that verifies
|
||||
// that .getCertificate() does not accidentally decrease the
|
||||
@@ -46,6 +46,6 @@ const server = tls
|
||||
}
|
||||
client.end();
|
||||
server.close();
|
||||
}
|
||||
}),
|
||||
);
|
||||
});
|
||||
}));
|
||||
@@ -18,11 +18,11 @@ const TEST_DATA = 'x';
|
||||
|
||||
const serverOptions = {
|
||||
ciphers: CIPHERS,
|
||||
pskCallback(socket, id) {
|
||||
pskCallback: common.mustCallAtLeast((socket, id) => {
|
||||
assert.ok(socket instanceof tls.TLSSocket);
|
||||
assert.ok(typeof id === 'string');
|
||||
return USERS[id];
|
||||
},
|
||||
}),
|
||||
};
|
||||
|
||||
function test(secret, opts, error) {
|
||||
|
||||
@@ -15,11 +15,11 @@ const tls = require('tls');
|
||||
pskCallback: () => {},
|
||||
pskIdentityHint: 'a'.repeat(512), // Too long identity hint.
|
||||
});
|
||||
server.on('tlsClientError', (err) => {
|
||||
server.on('tlsClientError', common.mustCall((err) => {
|
||||
assert.ok(err instanceof Error);
|
||||
assert.strictEqual(err.code, 'ERR_TLS_PSK_SET_IDENTITY_HINT_FAILED');
|
||||
server.close();
|
||||
});
|
||||
}));
|
||||
server.listen(0, () => {
|
||||
const client = tls.connect({
|
||||
port: server.address().port,
|
||||
|
||||
@@ -23,12 +23,12 @@ const IDENTITY = 'TestUser';
|
||||
const server = tls.createServer({
|
||||
ciphers: CIPHERS,
|
||||
pskIdentityHint: IDENTITY,
|
||||
pskCallback(socket, identity) {
|
||||
pskCallback: common.mustCall((socket, identity) => {
|
||||
assert.ok(socket instanceof tls.TLSSocket);
|
||||
assert.ok(typeof identity === 'string');
|
||||
if (identity === IDENTITY)
|
||||
return Buffer.from(KEY, 'hex');
|
||||
}
|
||||
}),
|
||||
});
|
||||
|
||||
server.on('connection', common.mustCall());
|
||||
@@ -45,7 +45,7 @@ let gotHello = false;
|
||||
let sentWorld = false;
|
||||
let gotWorld = false;
|
||||
|
||||
server.listen(0, () => {
|
||||
server.listen(0, common.mustCall(() => {
|
||||
const client = spawn(opensslCli, [
|
||||
's_client',
|
||||
'-connect', `127.0.0.1:${server.address().port}`,
|
||||
@@ -79,4 +79,4 @@ server.listen(0, () => {
|
||||
assert.strictEqual(code, 0);
|
||||
server.close();
|
||||
}));
|
||||
});
|
||||
}));
|
||||
@@ -34,7 +34,7 @@ const goodSecureContext = {
|
||||
ca: [ loadPEM('ca1-cert') ]
|
||||
};
|
||||
|
||||
const server = tls.createServer(serverOptions, (c) => {
|
||||
const server = tls.createServer(serverOptions, common.mustCallAtLeast((c) => {
|
||||
// The 'a' and 'b' subdomains are used to distinguish between client
|
||||
// connections.
|
||||
// Connection to subdomain 'a' is made when the 'bad' secure context is
|
||||
@@ -47,13 +47,13 @@ const server = tls.createServer(serverOptions, (c) => {
|
||||
if ('b.example.com' === c.servername) {
|
||||
assert.strictEqual(c.authorized, true);
|
||||
}
|
||||
});
|
||||
}));
|
||||
|
||||
// 1. Add the 'bad' secure context. A connection using this context will not be
|
||||
// authorized.
|
||||
server.addContext('*.example.com', badSecureContext);
|
||||
|
||||
server.listen(0, () => {
|
||||
server.listen(0, common.mustCall(() => {
|
||||
const options = {
|
||||
port: server.address().port,
|
||||
key: loadPEM('agent1-key'),
|
||||
@@ -96,4 +96,4 @@ server.listen(0, () => {
|
||||
}));
|
||||
}));
|
||||
}));
|
||||
});
|
||||
}));
|
||||
@@ -15,7 +15,7 @@ const options = {
|
||||
|
||||
const server = tls.createServer(options, function(s) {
|
||||
s.end('hello');
|
||||
}).listen(0, function() {
|
||||
}).listen(0, common.mustCall(function() {
|
||||
const opts = {
|
||||
port: this.address().port,
|
||||
rejectUnauthorized: false
|
||||
@@ -29,4 +29,4 @@ const server = tls.createServer(options, function(s) {
|
||||
const client = tls.connect(opts, function() {
|
||||
client.end();
|
||||
});
|
||||
});
|
||||
}));
|
||||
@@ -35,7 +35,7 @@ const altKeyCertVals = [
|
||||
}),
|
||||
};
|
||||
|
||||
tls.createServer(options, (s) => s.end()).listen(0, function() {
|
||||
tls.createServer(options, (s) => s.end()).listen(0, common.mustCall(function() {
|
||||
this.on('connection', common.mustCall((socket) => this.close()));
|
||||
|
||||
tls.connect({
|
||||
@@ -52,5 +52,5 @@ const altKeyCertVals = [
|
||||
this.end();
|
||||
next();
|
||||
}));
|
||||
});
|
||||
}));
|
||||
})();
|
||||
@@ -221,7 +221,7 @@ function runClient(prefix, port, options, cb) {
|
||||
}
|
||||
});
|
||||
|
||||
client.on('exit', function(code) {
|
||||
client.on('exit', common.mustCall((code) => {
|
||||
if (options.shouldReject) {
|
||||
assert.strictEqual(
|
||||
rejected, true,
|
||||
@@ -237,7 +237,7 @@ function runClient(prefix, port, options, cb) {
|
||||
}
|
||||
|
||||
cb();
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
@@ -273,7 +273,7 @@ function runTest(port, testIndex) {
|
||||
}
|
||||
|
||||
let renegotiated = false;
|
||||
const server = tls.Server(serverOptions, function handleConnection(c) {
|
||||
const server = tls.Server(serverOptions, common.mustCallAtLeast(function handleConnection(c) {
|
||||
c.on('error', function(e) {
|
||||
// child.kill() leads ECONNRESET error in the TLS connection of
|
||||
// openssl s_client via spawn(). A test result is already
|
||||
@@ -282,18 +282,17 @@ function runTest(port, testIndex) {
|
||||
});
|
||||
if (tcase.renegotiate && !renegotiated) {
|
||||
renegotiated = true;
|
||||
setTimeout(function() {
|
||||
setTimeout(common.mustCall(() => {
|
||||
console.error(`${prefix}- connected, renegotiating`);
|
||||
c.write('\n_renegotiating\n');
|
||||
return c.renegotiate({
|
||||
requestCert: true,
|
||||
rejectUnauthorized: false
|
||||
}, function(err) {
|
||||
assert.ifError(err);
|
||||
}, common.mustSucceed(() => {
|
||||
c.write('\n_renegotiated\n');
|
||||
handleConnection(c);
|
||||
});
|
||||
}, 200);
|
||||
}));
|
||||
}), 200);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -305,7 +304,7 @@ function runTest(port, testIndex) {
|
||||
console.error(`${prefix}- unauthed connection: %s`, c.authorizationError);
|
||||
c.write('\n_unauthed\n');
|
||||
}
|
||||
});
|
||||
}));
|
||||
|
||||
function runNextClient(clientIndex) {
|
||||
const options = tcase.clients[clientIndex];
|
||||
|
||||
@@ -74,16 +74,16 @@ function doTest(testOptions, callback) {
|
||||
++requestCount;
|
||||
cleartext.end('');
|
||||
});
|
||||
server.on('newSession', function(id, data, cb) {
|
||||
server.on('newSession', common.mustCallAtLeast((id, data, cb) => {
|
||||
++newSessionCount;
|
||||
// Emulate asynchronous store
|
||||
setImmediate(() => {
|
||||
setImmediate(common.mustCall(() => {
|
||||
assert.ok(!session);
|
||||
session = { id, data };
|
||||
cb();
|
||||
});
|
||||
});
|
||||
server.on('resumeSession', function(id, callback) {
|
||||
}));
|
||||
}, 0));
|
||||
server.on('resumeSession', common.mustCallAtLeast((id, callback) => {
|
||||
++resumeCount;
|
||||
assert.ok(session);
|
||||
assert.strictEqual(session.id.toString('hex'), id.toString('hex'));
|
||||
@@ -100,9 +100,9 @@ function doTest(testOptions, callback) {
|
||||
setImmediate(() => {
|
||||
callback(null, data);
|
||||
});
|
||||
});
|
||||
}, 0));
|
||||
|
||||
server.listen(0, function() {
|
||||
server.listen(0, common.mustCall(function() {
|
||||
const args = [
|
||||
's_client',
|
||||
'-tls1',
|
||||
@@ -143,7 +143,7 @@ function doTest(testOptions, callback) {
|
||||
}
|
||||
|
||||
spawnClient();
|
||||
});
|
||||
}));
|
||||
|
||||
process.on('exit', function() {
|
||||
// Each test run connects 6 times: an initial request and 5 reconnect
|
||||
|
||||
@@ -45,7 +45,7 @@ const server = tls.Server(options, common.mustCall(function(socket) {
|
||||
}));
|
||||
|
||||
|
||||
server.listen(0, function() {
|
||||
server.listen(0, common.mustCall(function() {
|
||||
const client = tls.connect({
|
||||
port: this.address().port,
|
||||
rejectUnauthorized: false
|
||||
@@ -55,11 +55,11 @@ server.listen(0, function() {
|
||||
|
||||
client.setEncoding('ascii');
|
||||
|
||||
client.on('data', function(d) {
|
||||
client.on('data', common.mustCall((d) => {
|
||||
console.log('client: on data', d);
|
||||
assert.ok(typeof d === 'string');
|
||||
buffer += d;
|
||||
});
|
||||
}));
|
||||
|
||||
client.on('secureConnect', common.mustCall(() => {
|
||||
console.log('client: on secureConnect');
|
||||
@@ -83,4 +83,4 @@ server.listen(0, function() {
|
||||
|
||||
server.close();
|
||||
}));
|
||||
});
|
||||
}));
|
||||
@@ -87,7 +87,7 @@ async function makeRequest(port, id) {
|
||||
|
||||
let errored = false;
|
||||
req.on('error', () => errored = true);
|
||||
req.on('finish', () => assert.strictEqual(errored, false));
|
||||
req.on('finish', common.mustCallAtLeast(() => assert.strictEqual(errored, false), 0));
|
||||
|
||||
const [res] = await events.once(req, 'response');
|
||||
res.setEncoding('utf8');
|
||||
|
||||
@@ -136,12 +136,12 @@ test({
|
||||
'Invalid SNI context');
|
||||
|
||||
function test(options, clientResult, serverResult, clientError, serverError) {
|
||||
const server = tls.createServer(serverOptions, (c) => {
|
||||
const server = tls.createServer(serverOptions, common.mustCallAtLeast((c) => {
|
||||
assert.deepStrictEqual(
|
||||
serverResult,
|
||||
{ sni: c.servername, authorized: c.authorized }
|
||||
);
|
||||
});
|
||||
}, 0));
|
||||
|
||||
if (serverResult) {
|
||||
assert(!serverError);
|
||||
@@ -153,14 +153,14 @@ function test(options, clientResult, serverResult, clientError, serverError) {
|
||||
}));
|
||||
}
|
||||
|
||||
server.listen(0, () => {
|
||||
server.listen(0, common.mustCall(() => {
|
||||
options.port = server.address().port;
|
||||
const client = tls.connect(options, () => {
|
||||
const client = tls.connect(options, common.mustCallAtLeast(() => {
|
||||
const result = client.authorizationError &&
|
||||
(client.authorizationError === 'ERR_TLS_CERT_ALTNAME_INVALID');
|
||||
assert.strictEqual(result, clientResult);
|
||||
client.end();
|
||||
});
|
||||
}, 0));
|
||||
|
||||
client.on('close', common.mustCall(() => server.close()));
|
||||
|
||||
@@ -170,5 +170,5 @@ function test(options, clientResult, serverResult, clientError, serverError) {
|
||||
}));
|
||||
else
|
||||
client.on('error', common.mustNotCall());
|
||||
});
|
||||
}));
|
||||
}
|
||||
@@ -100,10 +100,10 @@ test(
|
||||
);
|
||||
|
||||
function test(options, clientResult, serverResult) {
|
||||
const server = tls.createServer(serverOptions, (c) => {
|
||||
const server = tls.createServer(serverOptions, common.mustCall((c) => {
|
||||
assert.strictEqual(c.servername, serverResult);
|
||||
assert.strictEqual(c.authorized, false);
|
||||
});
|
||||
}));
|
||||
|
||||
server.addContext('a.example.com', SNIContexts['a.example.com']);
|
||||
server.addContext('*.test.com', SNIContexts['asterisk.test.com']);
|
||||
@@ -111,20 +111,20 @@ function test(options, clientResult, serverResult) {
|
||||
|
||||
server.on('tlsClientError', common.mustNotCall());
|
||||
|
||||
server.listen(0, () => {
|
||||
server.listen(0, common.mustCall(() => {
|
||||
const client = tls.connect({
|
||||
...options,
|
||||
port: server.address().port,
|
||||
rejectUnauthorized: false
|
||||
}, () => {
|
||||
}, common.mustCall(() => {
|
||||
const result = client.authorizationError &&
|
||||
(client.authorizationError === 'ERR_TLS_CERT_ALTNAME_INVALID');
|
||||
assert.strictEqual(result, clientResult);
|
||||
client.end();
|
||||
});
|
||||
}));
|
||||
|
||||
client.on('close', common.mustCall(() => {
|
||||
server.close();
|
||||
}));
|
||||
});
|
||||
}));
|
||||
}
|
||||
@@ -30,7 +30,7 @@ function test(options) {
|
||||
assert.strictEqual(socket.servername, options.servername);
|
||||
}));
|
||||
|
||||
server.listen(0, () => {
|
||||
server.listen(0, common.mustCall(() => {
|
||||
options.port = server.address().port;
|
||||
const client = tls.connect(options, common.mustNotCall());
|
||||
|
||||
@@ -40,7 +40,7 @@ function test(options) {
|
||||
}));
|
||||
|
||||
client.on('close', common.mustCall(() => server.close()));
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
test({
|
||||
|
||||
@@ -13,27 +13,27 @@ const key = fixtures.readKey('agent2-key.pem');
|
||||
const cert = fixtures.readKey('agent2-cert.pem');
|
||||
|
||||
let serverTlsSocket;
|
||||
const tlsServer = tls.createServer({ cert, key }, (socket) => {
|
||||
const tlsServer = tls.createServer({ cert, key }, common.mustCall((socket) => {
|
||||
serverTlsSocket = socket;
|
||||
socket.on('data', (chunk) => {
|
||||
socket.on('data', common.mustCall((chunk) => {
|
||||
assert.strictEqual(chunk[0], 46);
|
||||
socket.write('.');
|
||||
});
|
||||
}));
|
||||
socket.on('close', dec);
|
||||
});
|
||||
}));
|
||||
|
||||
// A plain net server, that manually passes connections to the TLS
|
||||
// server to be upgraded.
|
||||
let netSocket;
|
||||
let netSocketCloseEmitted = false;
|
||||
const netServer = net.createServer((socket) => {
|
||||
const netServer = net.createServer(common.mustCall((socket) => {
|
||||
netSocket = socket;
|
||||
tlsServer.emit('connection', socket);
|
||||
socket.on('close', common.mustCall(() => {
|
||||
netSocketCloseEmitted = true;
|
||||
assert.strictEqual(serverTlsSocket.destroyed, true);
|
||||
}));
|
||||
}).listen(0, common.mustCall(() => {
|
||||
})).listen(0, common.mustCall(() => {
|
||||
connectClient(netServer);
|
||||
}));
|
||||
|
||||
@@ -51,18 +51,18 @@ function connectClient(server) {
|
||||
|
||||
clientTlsSocket.write('.');
|
||||
|
||||
clientTlsSocket.on('data', (chunk) => {
|
||||
clientTlsSocket.on('data', common.mustCall((chunk) => {
|
||||
assert.strictEqual(chunk[0], 46);
|
||||
|
||||
netSocket.destroy();
|
||||
assert.strictEqual(netSocket.destroyed, true);
|
||||
|
||||
setImmediate(() => {
|
||||
setImmediate(common.mustCall(() => {
|
||||
// Close callbacks are executed after `setImmediate()` callbacks.
|
||||
assert.strictEqual(netSocketCloseEmitted, false);
|
||||
assert.strictEqual(serverTlsSocket.destroyed, false);
|
||||
});
|
||||
});
|
||||
}));
|
||||
}));
|
||||
|
||||
clientTlsSocket.on('close', dec);
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ function test(client, callback) {
|
||||
key: keys.agent1.key,
|
||||
cert: keys.agent1.cert,
|
||||
},
|
||||
}, function(err, pair, cleanup) {
|
||||
}, common.mustCall(function(err, pair, cleanup) {
|
||||
assert.strictEqual(err.code, 'UNABLE_TO_VERIFY_LEAF_SIGNATURE');
|
||||
let recv = '';
|
||||
pair.server.server.once('secureConnection', common.mustCall((conn) => {
|
||||
@@ -64,5 +64,5 @@ function test(client, callback) {
|
||||
.on('secure', common.mustCall(function() {
|
||||
callback(this.ssl.verifyError());
|
||||
}));
|
||||
});
|
||||
}));
|
||||
}
|
||||
@@ -10,8 +10,8 @@ const assert = require('assert');
|
||||
|
||||
const bonkers = Buffer.alloc(1024, 42);
|
||||
|
||||
const server = net.createServer(function(c) {
|
||||
setTimeout(function() {
|
||||
const server = net.createServer(common.mustCall((c) => {
|
||||
setTimeout(common.mustCall(() => {
|
||||
const s = new tls.TLSSocket(c, {
|
||||
isServer: true,
|
||||
server: server
|
||||
@@ -30,8 +30,8 @@ const server = net.createServer(function(c) {
|
||||
server.close();
|
||||
s.destroy();
|
||||
});
|
||||
}, common.platformTimeout(200));
|
||||
}).listen(0, function() {
|
||||
}), common.platformTimeout(200));
|
||||
})).listen(0, function() {
|
||||
const c = net.connect({ port: this.address().port }, function() {
|
||||
c.write(bonkers);
|
||||
});
|
||||
|
||||
@@ -58,22 +58,22 @@ function runTest(tindex) {
|
||||
|
||||
const server = tls.createServer(tcase.serverOpts, function(s) {
|
||||
s.resume();
|
||||
}).listen(0, function() {
|
||||
}).listen(0, common.mustCall(function() {
|
||||
tcase.clientOpts.port = this.address().port;
|
||||
const client = tls.connect(tcase.clientOpts);
|
||||
client.on('error', function(e) {
|
||||
client.on('error', common.mustCallAtLeast((e) => {
|
||||
assert.strictEqual(e.code, tcase.errorCode);
|
||||
runNextTest(server, tindex);
|
||||
});
|
||||
}, 0));
|
||||
|
||||
client.on('secureConnect', function() {
|
||||
client.on('secureConnect', common.mustCall(() => {
|
||||
// agent8 can pass StartCom/WoSign check so that the secureConnect
|
||||
// is established.
|
||||
assert.strictEqual(tcase.errorCode, 'CERT_REVOKED');
|
||||
client.end();
|
||||
runNextTest(server, tindex);
|
||||
});
|
||||
});
|
||||
}));
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -59,10 +59,10 @@ if (cluster.isPrimary) {
|
||||
} else {
|
||||
shoot();
|
||||
}
|
||||
}).once('session', (session) => {
|
||||
}).once('session', common.mustCallAtLeast((session) => {
|
||||
assert(!lastSession);
|
||||
lastSession = session;
|
||||
});
|
||||
}, 0));
|
||||
|
||||
c.resume(); // See close_notify comment in server
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ function createServer() {
|
||||
key: fixtures.readKey('agent1-key.pem'),
|
||||
cert: fixtures.readKey('agent1-cert.pem'),
|
||||
ticketKeys: keys
|
||||
}, function(c) {
|
||||
}, common.mustCallAtLeast(function(c) {
|
||||
serverLog.push(id);
|
||||
// TODO(@sam-github) Triggers close_notify before NewSessionTicket bug.
|
||||
// c.end();
|
||||
@@ -85,7 +85,7 @@ function createServer() {
|
||||
} else {
|
||||
throw new Error('UNREACHABLE');
|
||||
}
|
||||
});
|
||||
}));
|
||||
|
||||
return server;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ const server = tls.createServer(options, function(s) {
|
||||
});
|
||||
|
||||
function putImmediate(client) {
|
||||
setImmediate(function() {
|
||||
setImmediate(common.mustCall(() => {
|
||||
if (client.ssl) {
|
||||
const fd = client.ssl.fd;
|
||||
assert(!!fd);
|
||||
@@ -38,5 +38,5 @@ function putImmediate(client) {
|
||||
} else {
|
||||
server.close();
|
||||
}
|
||||
});
|
||||
}));
|
||||
}
|
||||
@@ -6,57 +6,57 @@ const common = require('../common');
|
||||
if (!common.hasCrypto)
|
||||
common.skip('missing crypto');
|
||||
|
||||
const { strictEqual, deepStrictEqual } = require('assert');
|
||||
const assert = require('assert');
|
||||
const { translatePeerCertificate } = require('internal/tls/common');
|
||||
|
||||
const certString = '__proto__=42\nA=1\nB=2\nC=3';
|
||||
|
||||
strictEqual(translatePeerCertificate(null), null);
|
||||
strictEqual(translatePeerCertificate(undefined), null);
|
||||
assert.strictEqual(translatePeerCertificate(null), null);
|
||||
assert.strictEqual(translatePeerCertificate(undefined), null);
|
||||
|
||||
strictEqual(translatePeerCertificate(0), null);
|
||||
strictEqual(translatePeerCertificate(1), 1);
|
||||
assert.strictEqual(translatePeerCertificate(0), null);
|
||||
assert.strictEqual(translatePeerCertificate(1), 1);
|
||||
|
||||
deepStrictEqual(translatePeerCertificate({}), {});
|
||||
assert.deepStrictEqual(translatePeerCertificate({}), {});
|
||||
|
||||
// Earlier versions of Node.js parsed the issuer property but did so
|
||||
// incorrectly. This behavior has now reached end-of-life and user-supplied
|
||||
// strings will not be parsed at all.
|
||||
deepStrictEqual(translatePeerCertificate({ issuer: '' }),
|
||||
{ issuer: '' });
|
||||
deepStrictEqual(translatePeerCertificate({ issuer: null }),
|
||||
{ issuer: null });
|
||||
deepStrictEqual(translatePeerCertificate({ issuer: certString }),
|
||||
{ issuer: certString });
|
||||
assert.deepStrictEqual(translatePeerCertificate({ issuer: '' }),
|
||||
{ issuer: '' });
|
||||
assert.deepStrictEqual(translatePeerCertificate({ issuer: null }),
|
||||
{ issuer: null });
|
||||
assert.deepStrictEqual(translatePeerCertificate({ issuer: certString }),
|
||||
{ issuer: certString });
|
||||
|
||||
// Earlier versions of Node.js parsed the issuer property but did so
|
||||
// incorrectly. This behavior has now reached end-of-life and user-supplied
|
||||
// strings will not be parsed at all.
|
||||
deepStrictEqual(translatePeerCertificate({ subject: '' }),
|
||||
{ subject: '' });
|
||||
deepStrictEqual(translatePeerCertificate({ subject: null }),
|
||||
{ subject: null });
|
||||
deepStrictEqual(translatePeerCertificate({ subject: certString }),
|
||||
{ subject: certString });
|
||||
assert.deepStrictEqual(translatePeerCertificate({ subject: '' }),
|
||||
{ subject: '' });
|
||||
assert.deepStrictEqual(translatePeerCertificate({ subject: null }),
|
||||
{ subject: null });
|
||||
assert.deepStrictEqual(translatePeerCertificate({ subject: certString }),
|
||||
{ subject: certString });
|
||||
|
||||
deepStrictEqual(translatePeerCertificate({ issuerCertificate: '' }),
|
||||
{ issuerCertificate: null });
|
||||
deepStrictEqual(translatePeerCertificate({ issuerCertificate: null }),
|
||||
{ issuerCertificate: null });
|
||||
deepStrictEqual(
|
||||
assert.deepStrictEqual(translatePeerCertificate({ issuerCertificate: '' }),
|
||||
{ issuerCertificate: null });
|
||||
assert.deepStrictEqual(translatePeerCertificate({ issuerCertificate: null }),
|
||||
{ issuerCertificate: null });
|
||||
assert.deepStrictEqual(
|
||||
translatePeerCertificate({ issuerCertificate: { subject: certString } }),
|
||||
{ issuerCertificate: { subject: certString } });
|
||||
|
||||
{
|
||||
const cert = {};
|
||||
cert.issuerCertificate = cert;
|
||||
deepStrictEqual(translatePeerCertificate(cert), { issuerCertificate: cert });
|
||||
assert.deepStrictEqual(translatePeerCertificate(cert), { issuerCertificate: cert });
|
||||
}
|
||||
|
||||
deepStrictEqual(translatePeerCertificate({ infoAccess: '' }),
|
||||
{ infoAccess: { __proto__: null } });
|
||||
deepStrictEqual(translatePeerCertificate({ infoAccess: null }),
|
||||
{ infoAccess: null });
|
||||
assert.deepStrictEqual(translatePeerCertificate({ infoAccess: '' }),
|
||||
{ infoAccess: { __proto__: null } });
|
||||
assert.deepStrictEqual(translatePeerCertificate({ infoAccess: null }),
|
||||
{ infoAccess: null });
|
||||
{
|
||||
const input =
|
||||
'__proto__:mostly harmless\n' +
|
||||
@@ -66,6 +66,6 @@ deepStrictEqual(translatePeerCertificate({ infoAccess: null }),
|
||||
expected.__proto__ = ['mostly harmless'];
|
||||
expected.hasOwnProperty = ['not a function'];
|
||||
expected['OCSP - URI'] = ['file:///etc/passwd'];
|
||||
deepStrictEqual(translatePeerCertificate({ infoAccess: input }),
|
||||
{ infoAccess: expected });
|
||||
assert.deepStrictEqual(translatePeerCertificate({ infoAccess: input }),
|
||||
{ infoAccess: expected });
|
||||
}
|
||||
@@ -31,11 +31,9 @@ const server = tls.createServer(options, common.mustCall((c) => {
|
||||
let socket;
|
||||
let lastIdleStart;
|
||||
|
||||
server.listen(0, () => {
|
||||
socket = net.connect(server.address().port, function() {
|
||||
const s = socket.setTimeout(TIMEOUT_MAX, function() {
|
||||
throw new Error('timeout');
|
||||
});
|
||||
server.listen(0, common.mustCall(() => {
|
||||
socket = net.connect(server.address().port, common.mustCall(() => {
|
||||
const s = socket.setTimeout(TIMEOUT_MAX, common.mustNotCall('timeout'));
|
||||
assert.ok(s instanceof net.Socket);
|
||||
|
||||
assert.notStrictEqual(socket[kTimeout]._idleTimeout, -1);
|
||||
@@ -46,8 +44,8 @@ server.listen(0, () => {
|
||||
rejectUnauthorized: false
|
||||
});
|
||||
tsocket.resume();
|
||||
});
|
||||
});
|
||||
}));
|
||||
}));
|
||||
|
||||
process.on('exit', () => {
|
||||
assert.strictEqual(socket[kTimeout]._idleTimeout, -1);
|
||||
|
||||
@@ -48,16 +48,15 @@ if (process.argv[2] === 'child') {
|
||||
|
||||
assert(fs.existsSync(file));
|
||||
const data = await fs.promises.readFile(file, { encoding: 'utf8' });
|
||||
JSON.parse(data).traceEvents
|
||||
.filter((trace) => trace.cat !== '__metadata')
|
||||
.forEach((trace) => {
|
||||
assert.strictEqual(trace.pid, proc.pid);
|
||||
assert(names.includes(trace.name));
|
||||
if (trace.name === 'count::bar')
|
||||
assert.strictEqual(trace.args.data, expectedCounts.shift());
|
||||
else if (trace.name === 'time::foo')
|
||||
assert.strictEqual(trace.ph, expectedTimeTypes.shift());
|
||||
});
|
||||
for (const trace of JSON.parse(data).traceEvents
|
||||
.filter((trace) => trace.cat !== '__metadata')) {
|
||||
assert.strictEqual(trace.pid, proc.pid);
|
||||
assert(names.includes(trace.name));
|
||||
if (trace.name === 'count::bar')
|
||||
assert.strictEqual(trace.args.data, expectedCounts.shift());
|
||||
else if (trace.name === 'time::foo')
|
||||
assert.strictEqual(trace.ph, expectedTimeTypes.shift());
|
||||
}
|
||||
assert.strictEqual(expectedCounts.length, 0);
|
||||
assert.strictEqual(expectedTimeTypes.length, 0);
|
||||
}));
|
||||
|
||||
@@ -43,10 +43,10 @@ async function test() {
|
||||
|
||||
const events = [];
|
||||
let tracingComplete = false;
|
||||
session.on('NodeTracing.dataCollected', (n) => {
|
||||
session.on('NodeTracing.dataCollected', common.mustCall((n) => {
|
||||
assert.ok(n?.params?.value);
|
||||
events.push(...n.params.value); // append the events.
|
||||
});
|
||||
}, 2));
|
||||
session.on('NodeTracing.tracingComplete', () => tracingComplete = true);
|
||||
|
||||
trace(kBeforeEvent, 'foo', 'test1', 0, 'test');
|
||||
|
||||
@@ -46,13 +46,12 @@ if (process.argv[2] === 'child') {
|
||||
|
||||
assert(fs.existsSync(file));
|
||||
const data = await fs.promises.readFile(file);
|
||||
JSON.parse(data.toString()).traceEvents
|
||||
.filter((trace) => trace.cat !== '__metadata')
|
||||
.forEach((trace) => {
|
||||
assert.strictEqual(trace.pid, proc.pid);
|
||||
assert(names.has(trace.name));
|
||||
checkSet.add(trace.name);
|
||||
});
|
||||
for (const trace of JSON.parse(data.toString()).traceEvents
|
||||
.filter((trace) => trace.cat !== '__metadata')) {
|
||||
assert.strictEqual(trace.pid, proc.pid);
|
||||
assert(names.has(trace.name));
|
||||
checkSet.add(trace.name);
|
||||
}
|
||||
|
||||
assert.deepStrictEqual(names, checkSet);
|
||||
}));
|
||||
|
||||
@@ -20,29 +20,20 @@
|
||||
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
'use strict';
|
||||
require('../common');
|
||||
const common = require('../common');
|
||||
|
||||
// This test ensures piping from `stdin` isn't broken.
|
||||
// https://github.com/nodejs/node/issues/5927
|
||||
|
||||
const assert = require('assert');
|
||||
const readline = require('readline');
|
||||
|
||||
const rl = readline.createInterface(process.stdin, process.stdout);
|
||||
rl.resume();
|
||||
|
||||
let hasPaused = false;
|
||||
|
||||
const origPause = rl.pause;
|
||||
rl.pause = function() {
|
||||
hasPaused = true;
|
||||
origPause.apply(this, arguments);
|
||||
};
|
||||
|
||||
const origSetRawMode = rl._setRawMode;
|
||||
rl._setRawMode = function(mode) {
|
||||
assert.ok(hasPaused);
|
||||
origSetRawMode.apply(this, arguments);
|
||||
};
|
||||
rl.pause = common.mustCall(function pause() {
|
||||
Reflect.apply(origPause, this, arguments);
|
||||
});
|
||||
rl._setRawMode = common.mustNotCall();
|
||||
|
||||
rl.close();
|
||||
@@ -21,8 +21,8 @@ const fixtures = require('../common/fixtures');
|
||||
|
||||
// This test ensures the correctness of the automated timezone upgrade PRs.
|
||||
|
||||
const { strictEqual } = require('assert');
|
||||
const assert = require('assert');
|
||||
const { readFileSync } = require('fs');
|
||||
|
||||
const expectedVersion = readFileSync(fixtures.path('tz-version.txt'), 'utf8').trim();
|
||||
strictEqual(process.versions.tz, expectedVersion);
|
||||
assert.strictEqual(process.versions.tz, expectedVersion);
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
const { hasIntl } = require('../common');
|
||||
|
||||
const { strictEqual } = require('node:assert');
|
||||
const assert = require('node:assert');
|
||||
const { domainToASCII, domainToUnicode } = require('node:url');
|
||||
const { test } = require('node:test');
|
||||
|
||||
@@ -20,8 +20,8 @@ const domainWithASCII = [
|
||||
test('domainToASCII and domainToUnicode', { skip: !hasIntl }, () => {
|
||||
for (const [domain, ascii] of domainWithASCII) {
|
||||
const domainConvertedToASCII = domainToASCII(domain);
|
||||
strictEqual(domainConvertedToASCII, ascii);
|
||||
assert.strictEqual(domainConvertedToASCII, ascii);
|
||||
const asciiConvertedToUnicode = domainToUnicode(ascii);
|
||||
strictEqual(asciiConvertedToUnicode, domain);
|
||||
assert.strictEqual(asciiConvertedToUnicode, domain);
|
||||
}
|
||||
});
|
||||
@@ -3,7 +3,7 @@
|
||||
require('../common');
|
||||
|
||||
const { URLPattern } = require('url');
|
||||
const { throws } = require('assert');
|
||||
const assert = require('assert');
|
||||
|
||||
const pattern = new URLPattern();
|
||||
const proto = Object.getPrototypeOf(pattern);
|
||||
@@ -22,7 +22,7 @@ const proto = Object.getPrototypeOf(pattern);
|
||||
'hasRegExpGroups',
|
||||
].forEach((i) => {
|
||||
const prop = Object.getOwnPropertyDescriptor(proto, i).get;
|
||||
throws(() => prop({}), {
|
||||
assert.throws(() => prop({}), {
|
||||
message: 'Illegal invocation',
|
||||
}, i);
|
||||
});
|
||||
@@ -32,9 +32,9 @@ const proto = Object.getPrototypeOf(pattern);
|
||||
|
||||
const { test, exec } = pattern;
|
||||
|
||||
throws(() => test({}), {
|
||||
assert.throws(() => test({}), {
|
||||
message: 'Illegal invocation',
|
||||
});
|
||||
throws(() => exec({}), {
|
||||
assert.throws(() => exec({}), {
|
||||
message: 'Illegal invocation',
|
||||
});
|
||||
@@ -3,44 +3,44 @@
|
||||
require('../common');
|
||||
|
||||
const { URLPattern } = require('url');
|
||||
const { throws } = require('assert');
|
||||
const assert = require('assert');
|
||||
|
||||
// Verifies that calling URLPattern with no new keyword throws.
|
||||
throws(() => URLPattern(), {
|
||||
assert.throws(() => URLPattern(), {
|
||||
code: 'ERR_CONSTRUCT_CALL_REQUIRED',
|
||||
});
|
||||
|
||||
// Verifies that type checks are performed on the arguments.
|
||||
throws(() => new URLPattern(1), {
|
||||
assert.throws(() => new URLPattern(1), {
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
});
|
||||
|
||||
throws(() => new URLPattern({}, 1), {
|
||||
assert.throws(() => new URLPattern({}, 1), {
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
});
|
||||
|
||||
throws(() => new URLPattern({}, '', 1), {
|
||||
assert.throws(() => new URLPattern({}, '', 1), {
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
});
|
||||
|
||||
throws(() => new URLPattern({}, { ignoreCase: '' }), {
|
||||
assert.throws(() => new URLPattern({}, { ignoreCase: '' }), {
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
});
|
||||
|
||||
const pattern = new URLPattern();
|
||||
|
||||
throws(() => pattern.exec(1), {
|
||||
assert.throws(() => pattern.exec(1), {
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
});
|
||||
|
||||
throws(() => pattern.exec('', 1), {
|
||||
assert.throws(() => pattern.exec('', 1), {
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
});
|
||||
|
||||
throws(() => pattern.test(1), {
|
||||
assert.throws(() => pattern.test(1), {
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
});
|
||||
|
||||
throws(() => pattern.test('', 1), {
|
||||
assert.throws(() => pattern.test('', 1), {
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
});
|
||||
@@ -2,12 +2,12 @@
|
||||
|
||||
require('../common');
|
||||
|
||||
const { throws } = require('assert');
|
||||
const assert = require('assert');
|
||||
const { URLPattern } = require('url');
|
||||
|
||||
// Verify that if an error is thrown while accessing any of the
|
||||
// init options, the error is appropriately propagated.
|
||||
throws(() => {
|
||||
assert.throws(() => {
|
||||
new URLPattern({
|
||||
get protocol() {
|
||||
throw new Error('boom');
|
||||
@@ -19,7 +19,7 @@ throws(() => {
|
||||
|
||||
// Verify that if an error is thrown while accessing the ignoreCase
|
||||
// option, the error is appropriately propagated.
|
||||
throws(() => {
|
||||
assert.throws(() => {
|
||||
new URLPattern({}, { get ignoreCase() {
|
||||
throw new Error('boom');
|
||||
} });
|
||||
|
||||
@@ -188,6 +188,7 @@ const values = [
|
||||
for (const value of values) {
|
||||
const iAmThis = {
|
||||
fn(arg) {
|
||||
// eslint-disable-next-line node-core/must-call-assert
|
||||
assert.strictEqual(this, iAmThis);
|
||||
return Promise.resolve(arg);
|
||||
},
|
||||
@@ -200,6 +201,7 @@ const values = [
|
||||
|
||||
const iAmThat = {
|
||||
async fn(arg) {
|
||||
// eslint-disable-next-line node-core/must-call-assert
|
||||
assert.strictEqual(this, iAmThat);
|
||||
return arg;
|
||||
},
|
||||
@@ -289,11 +291,11 @@ const values = [
|
||||
|
||||
const cbPromiseFn = callbackify(promiseFn);
|
||||
|
||||
cbPromiseFn(null, (err) => {
|
||||
cbPromiseFn(null, common.mustCall((err) => {
|
||||
assert.strictEqual(err.message, 'Promise was rejected with falsy value');
|
||||
assert.strictEqual(err.code, 'ERR_FALSY_VALUE_REJECTION');
|
||||
assert.strictEqual(err.reason, null);
|
||||
const stack = err.stack.split(/[\r\n]+/);
|
||||
assert.match(stack[1], /at process\.processTicksAndRejections/);
|
||||
});
|
||||
}));
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
// Flags: --expose-internals
|
||||
'use strict';
|
||||
|
||||
require('../common');
|
||||
const common = require('../common');
|
||||
|
||||
// Tests basic functionality of util.deprecate().
|
||||
|
||||
@@ -83,7 +83,7 @@ for (const fn of [
|
||||
assert.strictEqual(typeof deprecatedWithProto.prototype.testMethod, 'function');
|
||||
}
|
||||
|
||||
process.on('warning', (warning) => {
|
||||
process.on('warning', common.mustCallAtLeast((warning) => {
|
||||
assert.strictEqual(warning.name, 'DeprecationWarning');
|
||||
assert.ok(expectedWarnings.has(warning.message));
|
||||
const expected = expectedWarnings.get(warning.message);
|
||||
@@ -91,7 +91,7 @@ process.on('warning', (warning) => {
|
||||
expected.count = expected.count - 1;
|
||||
if (expected.count === 0)
|
||||
expectedWarnings.delete(warning.message);
|
||||
});
|
||||
}));
|
||||
|
||||
process.on('exit', () => {
|
||||
assert.deepStrictEqual(expectedWarnings, new Map());
|
||||
|
||||
@@ -1035,11 +1035,11 @@ util.inspect({ hasOwnProperty: null });
|
||||
|
||||
assert.strictEqual(util.inspect(subject), '{ baz: \'quux\' }');
|
||||
|
||||
subject[inspect] = (depth, opts) => {
|
||||
subject[inspect] = common.mustCall((depth, opts) => {
|
||||
assert.strictEqual(opts.customInspectOptions, true);
|
||||
assert.strictEqual(opts.seen, null);
|
||||
return {};
|
||||
};
|
||||
});
|
||||
|
||||
util.inspect(subject, { customInspectOptions: true, seen: null });
|
||||
}
|
||||
@@ -2913,7 +2913,7 @@ assert.strictEqual(
|
||||
).join('\n');
|
||||
}
|
||||
const escapedCWD = util.inspect(process.cwd()).slice(1, -1);
|
||||
util.inspect(err, { colors: true }).split('\n').forEach((line, i) => {
|
||||
util.inspect(err, { colors: true }).split('\n').forEach(common.mustCallAtLeast((line, i) => {
|
||||
let expected = stack[i].replace(/node_modules\/(@[^/]+\/[^/]+|[^/]+)/gi, (_, m) => {
|
||||
return `node_modules/\u001b[4m${m}\u001b[24m`;
|
||||
}).replaceAll(new RegExp(`(\\(?${escapedCWD}(\\\\|/))`, 'gi'), (_, m) => {
|
||||
@@ -2930,7 +2930,7 @@ assert.strictEqual(
|
||||
expected = expected.replaceAll('/', '\\');
|
||||
}
|
||||
assert.strictEqual(line, expected);
|
||||
});
|
||||
}));
|
||||
|
||||
// Check ESM
|
||||
const encodedCwd = url.pathToFileURL(process.cwd());
|
||||
@@ -3144,9 +3144,9 @@ assert.strictEqual(
|
||||
{
|
||||
// Cross platform checks.
|
||||
const err = new Error('foo');
|
||||
util.inspect(err, { colors: true }).split('\n').forEach((line, i) => {
|
||||
util.inspect(err, { colors: true }).split('\n').forEach(common.mustCallAtLeast((line, i) => {
|
||||
assert(i < 2 || line.startsWith('\u001b[90m'));
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
@@ -6,52 +6,52 @@ if (common.isWindows) {
|
||||
common.skip('platform not supported');
|
||||
}
|
||||
|
||||
const { describe, test } = require('node:test');
|
||||
const assert = require('assert');
|
||||
const { internalBinding } = require('internal/test/binding');
|
||||
const binding = internalBinding('contextify');
|
||||
|
||||
[(next) => {
|
||||
// Test with no signal observed.
|
||||
binding.startSigintWatchdog();
|
||||
const hadPendingSignals = binding.stopSigintWatchdog();
|
||||
assert.strictEqual(hadPendingSignals, false);
|
||||
next();
|
||||
},
|
||||
(next) => {
|
||||
// Test with one call to the watchdog, one signal.
|
||||
binding.startSigintWatchdog();
|
||||
process.kill(process.pid, 'SIGINT');
|
||||
waitForPendingSignal(common.mustCall(() => {
|
||||
const hadPendingSignals = binding.stopSigintWatchdog();
|
||||
assert.strictEqual(hadPendingSignals, true);
|
||||
next();
|
||||
}));
|
||||
},
|
||||
(next) => {
|
||||
// Nested calls are okay.
|
||||
binding.startSigintWatchdog();
|
||||
binding.startSigintWatchdog();
|
||||
process.kill(process.pid, 'SIGINT');
|
||||
waitForPendingSignal(common.mustCall(() => {
|
||||
const hadPendingSignals1 = binding.stopSigintWatchdog();
|
||||
const hadPendingSignals2 = binding.stopSigintWatchdog();
|
||||
assert.strictEqual(hadPendingSignals1, true);
|
||||
assert.strictEqual(hadPendingSignals2, false);
|
||||
next();
|
||||
}));
|
||||
},
|
||||
() => {
|
||||
// Signal comes in after first call to stop.
|
||||
binding.startSigintWatchdog();
|
||||
binding.startSigintWatchdog();
|
||||
const hadPendingSignals1 = binding.stopSigintWatchdog();
|
||||
process.kill(process.pid, 'SIGINT');
|
||||
waitForPendingSignal(common.mustCall(() => {
|
||||
const hadPendingSignals2 = binding.stopSigintWatchdog();
|
||||
assert.strictEqual(hadPendingSignals1, false);
|
||||
assert.strictEqual(hadPendingSignals2, true);
|
||||
}));
|
||||
}].reduceRight((a, b) => common.mustCall(b).bind(null, a))();
|
||||
describe({ concurrency: false }, () => {
|
||||
test('with no signal observed', (_, next) => {
|
||||
binding.startSigintWatchdog();
|
||||
const hadPendingSignals = binding.stopSigintWatchdog();
|
||||
assert.strictEqual(hadPendingSignals, false);
|
||||
next();
|
||||
});
|
||||
test('with one call to the watchdog, one signal', (_, next) => {
|
||||
binding.startSigintWatchdog();
|
||||
process.kill(process.pid, 'SIGINT');
|
||||
waitForPendingSignal(common.mustCall(() => {
|
||||
const hadPendingSignals = binding.stopSigintWatchdog();
|
||||
assert.strictEqual(hadPendingSignals, true);
|
||||
next();
|
||||
}));
|
||||
});
|
||||
test('Nested calls are okay', (_, next) => {
|
||||
binding.startSigintWatchdog();
|
||||
binding.startSigintWatchdog();
|
||||
process.kill(process.pid, 'SIGINT');
|
||||
waitForPendingSignal(common.mustCall(() => {
|
||||
const hadPendingSignals1 = binding.stopSigintWatchdog();
|
||||
const hadPendingSignals2 = binding.stopSigintWatchdog();
|
||||
assert.strictEqual(hadPendingSignals1, true);
|
||||
assert.strictEqual(hadPendingSignals2, false);
|
||||
next();
|
||||
}));
|
||||
});
|
||||
test('Signal comes in after first call to stop', (_, done) => {
|
||||
binding.startSigintWatchdog();
|
||||
binding.startSigintWatchdog();
|
||||
const hadPendingSignals1 = binding.stopSigintWatchdog();
|
||||
process.kill(process.pid, 'SIGINT');
|
||||
waitForPendingSignal(common.mustCall(() => {
|
||||
const hadPendingSignals2 = binding.stopSigintWatchdog();
|
||||
assert.strictEqual(hadPendingSignals1, false);
|
||||
assert.strictEqual(hadPendingSignals2, true);
|
||||
done();
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
function waitForPendingSignal(cb) {
|
||||
if (binding.watchdogHasPendingSigint())
|
||||
|
||||
Reference in new issue
Block a user