0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00

SERVER-35463 Mark listCommands as pre-auth

This commit is contained in:
Sara Golemon 2018-06-06 17:33:47 -04:00
parent 8d2ff6ae7c
commit aa14a86962
No known key found for this signature in database
GPG Key ID: 4C450CE8EB5C4016
2 changed files with 41 additions and 0 deletions

View File

@ -0,0 +1,38 @@
// Make sure that listCommands doesn't require authentication.
(function() {
'use strict';
function runTest(conn) {
const admin = conn.getDB('admin');
// Commands should succeed in auth-bypass mode regardless of requiresAuth().
assert.commandWorked(admin.runCommand({listDatabases: 1}),
"listDatabases shouldn't work pre-auth");
assert.commandWorked(admin.runCommand({listCommands: 1}),
"listCommands should work pre-auth");
admin.createUser({user: 'admin', pwd: 'pass', roles: jsTest.adminUserRoles});
// listDatabases should now fail, because auth bypass is no longer valid.
assert.commandFailed(admin.runCommand({listDatabases: 1}),
"listDatabases shouldn't work pre-auth");
// listCommands should STILL work, because it does not require auth.
assert.commandWorked(admin.runCommand({listCommands: 1}),
"listCommands should work pre-auth");
}
const mongod = MongoRunner.runMongod({auth: ""});
runTest(mongod);
MongoRunner.stopMongod(mongod);
// TODO: Remove 'shardAsReplicaSet: false' when SERVER-32672 is fixed.
const st = new ShardingTest({
shards: 1,
mongos: 1,
config: 1,
other: {keyFile: 'jstests/libs/key1', shardAsReplicaSet: false}
});
runTest(st.s0);
st.stop();
})();

View File

@ -143,6 +143,9 @@ public:
virtual void addRequiredPrivileges(const std::string& dbname,
const BSONObj& cmdObj,
std::vector<Privilege>* out) const {} // No auth required
bool requiresAuth() const final {
return false;
}
virtual bool run(OperationContext* opCtx,
const string& ns,
const BSONObj& cmdObj,