From 2ff2b24ce6c0745e181f2cb1fe4fc12d220a9e8a Mon Sep 17 00:00:00 2001 From: Adam Cooper Date: Wed, 24 Jul 2019 16:54:44 -0400 Subject: [PATCH] SERVER-35753 listCommands should include value for requiresAuth --- jstests/core/list_commands.js | 12 ++++++++++++ src/mongo/db/commands/generic.cpp | 1 + 2 files changed, 13 insertions(+) diff --git a/jstests/core/list_commands.js b/jstests/core/list_commands.js index 94e85511a9b..0eadce58507 100644 --- a/jstests/core/list_commands.js +++ b/jstests/core/list_commands.js @@ -24,4 +24,16 @@ assert(commands["commands"].hasOwnProperty("isMaster")); assert(commands["commands"].hasOwnProperty("insert")); assert(commands["commands"].hasOwnProperty("ping")); + + // Test that commands listed have required properties + const isMaster = commands["commands"]["isMaster"]; + assert(isMaster.hasOwnProperty("help")); + assert(isMaster.hasOwnProperty("slaveOk")); + assert(isMaster.hasOwnProperty("adminOnly")); + assert(isMaster.hasOwnProperty("requiresAuth")); + + // Test that requiresAuth outputs correct value + const insert = commands["commands"]["insert"]; + assert(isMaster["requiresAuth"] === false); + assert(insert["requiresAuth"] === true); })(); diff --git a/src/mongo/db/commands/generic.cpp b/src/mongo/db/commands/generic.cpp index dd3fbeca47a..5ba09526814 100644 --- a/src/mongo/db/commands/generic.cpp +++ b/src/mongo/db/commands/generic.cpp @@ -174,6 +174,7 @@ public: for (const auto& c : commands) { BSONObjBuilder temp(b.subobjStart(c->getName())); temp.append("help", c->help()); + temp.append("requiresAuth", c->requiresAuth()); temp.append("slaveOk", c->secondaryAllowed(opCtx->getServiceContext()) == Command::AllowedOnSecondary::kAlways);