diff options
author | Sara Golemon <sara.golemon@mongodb.com> | 2021-10-18 18:21:31 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-10-19 21:16:38 +0000 |
commit | 93fc544da4f7752a5ce2ab2166e94c50ea70221f (patch) | |
tree | b9cab89efe8d039b0ea99afb0f42a630f636af1a | |
parent | 5510efff15cc6c9895530c2e42abd6371a73f605 (diff) | |
download | mongo-93fc544da4f7752a5ce2ab2166e94c50ea70221f.tar.gz |
SERVER-59970 Fix reply value from authenticate command
-rw-r--r-- | jstests/ssl/x509_client.js | 16 | ||||
-rw-r--r-- | src/mongo/db/commands/authentication_commands.cpp | 6 |
2 files changed, 16 insertions, 6 deletions
diff --git a/jstests/ssl/x509_client.js b/jstests/ssl/x509_client.js index 26f4ecc4c71..f764575227b 100644 --- a/jstests/ssl/x509_client.js +++ b/jstests/ssl/x509_client.js @@ -32,10 +32,18 @@ function authAndTest(mongo) { "authentication with valid user failed"); assert(external.auth({mechanism: 'MONGODB-X509'}), "authentication with valid client cert and no user field failed"); - assert(external.runCommand({authenticate: 1, mechanism: 'MONGODB-X509', user: CLIENT_USER}).ok, - "runCommand authentication with valid client cert and user field failed"); - assert(external.runCommand({authenticate: 1, mechanism: 'MONGODB-X509'}).ok, - "runCommand authentication with valid client cert and no user field failed"); + + const withUserReply = assert.commandWorked( + external.runCommand({authenticate: 1, mechanism: 'MONGODB-X509', user: CLIENT_USER}), + "runCommand authentication with valid client cert and user field failed"); + assert.eq(withUserReply.user, CLIENT_USER); + assert.eq(withUserReply.dbname, '$external'); + + const noUserReply = assert.commandWorked( + external.runCommand({authenticate: 1, mechanism: 'MONGODB-X509'}), + "runCommand authentication with valid client cert and no user field failed"); + assert.eq(noUserReply.user, CLIENT_USER); + assert.eq(noUserReply.dbname, '$external'); // Check that there's a "Successfully authenticated" message that includes the client IP const log = diff --git a/src/mongo/db/commands/authentication_commands.cpp b/src/mongo/db/commands/authentication_commands.cpp index ba920d46e20..394a97912ce 100644 --- a/src/mongo/db/commands/authentication_commands.cpp +++ b/src/mongo/db/commands/authentication_commands.cpp @@ -364,8 +364,10 @@ AuthenticateReply authCommand(OperationContext* opCtx, session->markSuccessful(); - return AuthenticateReply(session->getUserName().toString(), - session->getDatabase().toString()); + AuthenticateReply reply; + reply.setUser(session->getUserName()); + reply.setDbname(session->getDatabase()); + return reply; } catch (const AssertionException& ex) { if (!serverGlobalParams.quiet.load()) { |