From 54ce9f3a48dcde0758e4cdf77d7b0efd08d71e2b Mon Sep 17 00:00:00 2001 From: Adam Rayner Date: Fri, 12 May 2023 16:10:51 +0000 Subject: SERVER-76961: update expected log struct for abandoned session, add deterministic test for abandoned authentication session --- jstests/auth/authn_session_abandoned.js | 31 +++++++++++++++++++++++++++++++ jstests/auth/speculative-auth-replset.js | 5 +++-- 2 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 jstests/auth/authn_session_abandoned.js diff --git a/jstests/auth/authn_session_abandoned.js b/jstests/auth/authn_session_abandoned.js new file mode 100644 index 00000000000..d5298ecbe02 --- /dev/null +++ b/jstests/auth/authn_session_abandoned.js @@ -0,0 +1,31 @@ +// Test for auth counters in serverStatus. + +(function() { +'use strict'; +load('jstests/libs/parallel_shell_helpers.js'); + +const kFailedToAuthMsgId = 5286307; + +const mongod = MongoRunner.runMongod(); + +try { + mongod.getDB("admin").createUser( + {"user": "admin", "pwd": "pwd", roles: ['root'], mechanisms: ["SCRAM-SHA-256"]}); + + const shellCmd = () => { + // base64 encoded: 'n,,n=admin,r=deadbeefcafeba11'; + const kClientPayload = 'biwsbj1hZG1pbixyPWRlYWRiZWVmY2FmZWJhMTE='; + + db.getSiblingDB("admin").runCommand( + {saslStart: 1, mechanism: "SCRAM-SHA-256", payload: kClientPayload}); + }; + + startParallelShell(shellCmd, mongod.port)(); + + assert.soon(() => checkLog.checkContainsOnceJson( + mongod, kFailedToAuthMsgId, {"result": ErrorCodes.AuthenticationAbandoned})); + +} finally { + MongoRunner.stopMongod(mongod); +} +})(); diff --git a/jstests/auth/speculative-auth-replset.js b/jstests/auth/speculative-auth-replset.js index 9f36444a020..3bd960780d6 100644 --- a/jstests/auth/speculative-auth-replset.js +++ b/jstests/auth/speculative-auth-replset.js @@ -27,8 +27,9 @@ function countAuthInLog(conn) { } } else if (entry.id === kAuthenticationFailedLogId) { // Authentication can fail legitimately because the secondary abandons the connection - // during shutdown. - assert.eq(entry.attr.error.code, ErrorCodes.AuthenticationAbandoned); + // during shutdown - if we do encounter an authentication failure in the log, make sure + // that it is only of this type, fail anything else + assert.eq(entry.attr.result, ErrorCodes.AuthenticationAbandoned); } else { // Irrelevant. return; -- cgit v1.2.1