diff options
author | Militsa Sotirova <militsa.sotirova@mongodb.com> | 2023-01-20 14:03:44 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2023-01-20 15:05:21 +0000 |
commit | 4594ea6598ce28d01c5c5d76164b1cfeeba1494f (patch) | |
tree | ecd9ddcb24ba6a3b7199572d8b3bef3b748f203b | |
parent | 62949c560f99bd257c54a52ca7bbc96b74e7d27d (diff) | |
download | mongo-4594ea6598ce28d01c5c5d76164b1cfeeba1494f.tar.gz |
SERVER-73020 Using checkLog.containsWithCount to check for failures
-rw-r--r-- | jstests/auth/auth_system_logs.js | 60 |
1 files changed, 22 insertions, 38 deletions
diff --git a/jstests/auth/auth_system_logs.js b/jstests/auth/auth_system_logs.js index 68111ca5dba..243a866063d 100644 --- a/jstests/auth/auth_system_logs.js +++ b/jstests/auth/auth_system_logs.js @@ -9,35 +9,21 @@ mongod.getDB('admin').createUser( assert(mongod.getDB('admin').auth('admin', 'pwd')); // `mongod` is authenticated as a super user and stays that way. -// base64 encoded: 'n,,n=admin,r=deadbeefcafeba11'; -const kClientPayload = 'biwsbj1hZG1pbixyPWRlYWRiZWVmY2FmZWJhMTE='; - const kFailedToAuthMsg = 5286307; -// Obtains all of the logs that contain a failed to authenticate message. -function getFailures() { - // No need to auth, we're already superuser. - return checkLog.getGlobalLog(mongod) - .map(JSON.parse) - .filter((log) => log.id == kFailedToAuthMsg); -} - -// Ensures that there are exactly expectedNumFailures failures in the logs after failuresBefore. -function assertNewAuthFailures(failuresBefore, expectedNumFailures) { - const failuresAfter = getFailures(); - assert.eq(failuresBefore.length + expectedNumFailures, - failuresAfter.length, - "Unexpected new failures: " + tojson(failuresAfter.slice(failuresBefore.length))); -} - -function runTest(speculations, performNormalAuth = false) { - const failuresBefore = getFailures(); +let failuresAlreadyObserved = 0; +// Run the number of speculations specified, and if performNormalAuth is true we complete the +// authentication session. At the end, we check to see that the total number of failures in the logs +// for this iteration is the same as expectedNumFailures. +function runTest(speculations, performNormalAuth, expectedNumFailures) { // Running the operations in a parallel shell so that if performNormalAuth is false, we // encounter an "authentication session abandoned" error because the client will disconnect. let runAuths = startParallelShell( funWithArgs(function(speculations, performNormalAuth = false) { const admin = db.getSiblingDB('admin'); + + // base64 encoded: 'n,,n=admin,r=deadbeefcafeba11'; const kClientPayload = 'biwsbj1hZG1pbixyPWRlYWRiZWVmY2FmZWJhMTE='; // Run speculative auth(s). @@ -60,25 +46,23 @@ function runTest(speculations, performNormalAuth = false) { runAuths(); - // If we perform a normal auth after the speculative one(s), we complete the authentication - // session (and thus, do not encounter the "authentication session abandoned" error). - let expectedFailures = 0; - if (speculations > 0) { - expectedFailures = performNormalAuth ? 0 : 1; - } - if (speculations > 1) { - expectedFailures += speculations - 1; - } - - assertNewAuthFailures(failuresBefore, expectedFailures); + checkLog.containsWithCount( + mongod, kFailedToAuthMsg, failuresAlreadyObserved + expectedNumFailures); + failuresAlreadyObserved += expectedNumFailures; } -// Run test with no speculation (0), normal speculation (1), and a few levels of excessive -// speculation. Try each degree both with and without performing a normal authentication at the end. -for (let speculate = 0; speculate < 5; ++speculate) { - runTest(speculate, true); - runTest(speculate, false); -} +// Running with 0 speculations should not cause any failures. +runTest(0, true, 0); +runTest(0, false, 0); + +// Running with 1 speculation should only cause a failure when we do not complete the authentication +// session with a normal auth. +runTest(1, true, 0); +runTest(1, false, 1); + +// Running 2 speculations should cause a failure because the second will override the first. +runTest(2, true, 1); +runTest(2, false, 2); MongoRunner.stopMongod(mongod); })(); |