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

SERVER-258 make db.eval work with read only mode

This commit is contained in:
Aaron 2010-02-01 10:31:08 -08:00
parent 75fd1d6257
commit 946d42e8e7
2 changed files with 20 additions and 4 deletions

View File

@ -111,8 +111,15 @@ namespace mongo {
virtual bool slaveOk() {
return false;
}
// We need at least read only access to run db.eval - auth for eval'd writes will be checked
// as they are requested.
virtual bool requiresAuth() {
return false;
}
CmdEval() : Command("$eval") { }
bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
AuthenticationInfo *ai = currentClient.get()->ai;
uassert( 12596 , "$eval readOnly unauthorized", ai->isReadOnlyAuthorized(cc().database()->name.c_str()));
return dbEval(ns, cmdObj, result, errmsg);
}
} cmdeval;

View File

@ -20,11 +20,15 @@ assert.throws( function() { t.findOne() }, [], "read without login" );
assert( db.auth( "eliot" , "eliot" ) , "auth failed" );
for( i = 0; i < 1000; ++i ) {
for( i = 0; i < 999; ++i ) {
t.save( {i:i} );
}
assert.eq( 1000, t.count() );
assert.eq( 1000, t.find().toArray().length );
assert.eq( 999, t.count() );
assert.eq( 999, t.find().toArray().length );
assert.eq( 999, db.eval( function() { return db[ "jstests_auth_auth1" ].count(); } ) );
db.eval( function() { db[ "jstests_auth_auth1" ].save( {i:1} ) } );
assert.eq( 1000, db.eval( function() { return db[ "jstests_auth_auth1" ].count(); } ) );
assert( db.auth( "guest", "guest" ), "auth failed 2" );
@ -41,4 +45,9 @@ assert.eq( 2, db.system.users.count() );
assert( !db.getLastError() );
db.addUser( "a", "b" );
assert( db.getLastError() );
assert.eq( 2, db.system.users.count() );
assert.eq( 2, db.system.users.count() );
assert.eq( 1000, db.eval( function() { return db[ "jstests_auth_auth1" ].count(); } ) );
assert.eq( 1000, db.eval( function() { return db[ "jstests_auth_auth1" ].find().toArray().length; } ) );
db.eval( function() { db[ "jstests_auth_auth1" ].save( {i:1} ) } );
assert.eq( 1000, db.eval( function() { return db[ "jstests_auth_auth1" ].count(); } ) );