diff options
author | Antonin Kral <a.kral@bobek.cz> | 2010-03-25 19:21:32 +0100 |
---|---|---|
committer | Antonin Kral <a.kral@bobek.cz> | 2010-03-25 19:21:32 +0100 |
commit | 0ca01a91ae0a3562e54c226e7b9512feb2ea83d0 (patch) | |
tree | 2b3886e435b0217d6afd63a213b04d32bb4b4f6f /jstests/auth | |
parent | a696359b248adef0cc8576fce3f473535e995136 (diff) | |
download | mongodb-0ca01a91ae0a3562e54c226e7b9512feb2ea83d0.tar.gz |
Imported Upstream version 1.4.0
Diffstat (limited to 'jstests/auth')
-rw-r--r-- | jstests/auth/auth1.js | 73 | ||||
-rw-r--r-- | jstests/auth/copyauth.js | 29 |
2 files changed, 102 insertions, 0 deletions
diff --git a/jstests/auth/auth1.js b/jstests/auth/auth1.js new file mode 100644 index 0000000..6fc6dc5 --- /dev/null +++ b/jstests/auth/auth1.js @@ -0,0 +1,73 @@ +// test read/write permissions + +port = allocatePorts( 1 )[ 0 ]; +baseName = "jstests_auth_auth1"; + +m = startMongod( "--auth", "--port", port, "--dbpath", "/data/db/" + baseName, "--nohttpinterface", "--bind_ip", "127.0.0.1" ); +db = m.getDB( "test" ); + +t = db[ baseName ]; +t.drop(); + +users = db.getCollection( "system.users" ); +users.remove( {} ); + +db.addUser( "eliot" , "eliot" ); +db.addUser( "guest" , "guest", true ); +db.getSisterDB( "admin" ).addUser( "super", "super" ); + +assert.throws( function() { t.findOne() }, [], "read without login" ); + +assert( db.auth( "eliot" , "eliot" ) , "auth failed" ); + +for( i = 0; i < 999; ++i ) { + t.save( {i:i} ); +} +assert.eq( 999, t.count() , "A1" ); +assert.eq( 999, t.find().toArray().length , "A2" ); + +assert.eq( 999, db.eval( function() { return db[ "jstests_auth_auth1" ].count(); } ) , "A3" ); +db.eval( function() { db[ "jstests_auth_auth1" ].save( {i:999} ) } ); +assert.eq( 1000, db.eval( function() { return db[ "jstests_auth_auth1" ].count(); } ) , "A4" ); + +var p = { key : { i : true } , + reduce : function(obj,prev) { prev.count++; }, +initial: { count: 0 } +}; + +assert.eq( 1000, t.group( p ).length , "A5" ); + +if ( db.runCommand( "features" ).readlock ){ + print( "doing readonly test" ); + assert( db.auth( "guest", "guest" ), "auth failed 2" ); + + assert.eq( 1000, t.count() , "B1" ); + assert.eq( 1000, t.find().toArray().length , "B2" ); // make sure we have a getMore in play + assert.commandWorked( db.runCommand( {ismaster:1} ) , "B3" ); + + assert( !db.getLastError() , "B4" ); + t.save( {} ); // fail + assert( db.getLastError() , "B5: " + tojson( db.getLastErrorObj() ) ); + assert.eq( 1000, t.count() , "B6" ); + + assert.eq( 2, db.system.users.count() , "B7" ); + assert( !db.getLastError() , "B8" ); + db.addUser( "a", "b" ); + assert( db.getLastError() , "B9" ); + assert.eq( 2, db.system.users.count() , "B10"); + + assert.eq( 1000, db.eval( function() { return db[ "jstests_auth_auth1" ].count(); } ) , "C1" ); + assert.eq( 1000, db.eval( function() { return db[ "jstests_auth_auth1" ].find().toArray().length; } ) , "C2" ); + db.eval( function() { db[ "jstests_auth_auth1" ].save( {i:1} ) } , "C3" ); + assert.eq( 1000, db.eval( function() { return db[ "jstests_auth_auth1" ].count(); } ) , "C4" ); + + assert.eq( 1000, t.group( p ).length , "C5" ); + + var p = { key : { i : true } , + reduce : function(obj,prev) { db.jstests_auth_auth1.save( {i:10000} ); prev.count++; }, + initial: { count: 0 } + }; + + assert.throws( function() { return t.group( p ) }, "write reduce didn't fail" ); +} + diff --git a/jstests/auth/copyauth.js b/jstests/auth/copyauth.js new file mode 100644 index 0000000..043b863 --- /dev/null +++ b/jstests/auth/copyauth.js @@ -0,0 +1,29 @@ +// test copyDatabase from an auth enabled source + +ports = allocatePorts( 2 ); + +var baseName = "jstests_clone_copyauth"; + +var source = startMongod( "--auth", "--port", ports[ 0 ], "--dbpath", "/data/db/" + baseName + "_source", "--nohttpinterface", "--bind_ip", "127.0.0.1", "--smallfiles" ); +var target = startMongod( "--port", ports[ 1 ], "--dbpath", "/data/db/" + baseName + "_target", "--nohttpinterface", "--bind_ip", "127.0.0.1", "--smallfiles" ); + +source.getDB( baseName )[ baseName ].save( {i:1} ); +source.getDB( baseName ).addUser( "foo", "bar" ); +source.getDB( "admin" ).addUser( "super", "super" ); +assert.throws( function() { source.getDB( baseName )[ baseName ].findOne(); } ); + +target.getDB( baseName ).copyDatabase( baseName, baseName, source.host, "foo", "bar" ); +assert.eq( 1, target.getDB( baseName )[ baseName ].count() ); +assert.eq( 1, target.getDB( baseName )[ baseName ].findOne().i ); + +stopMongod( ports[ 1 ] ); + +var target = startMongod( "--auth", "--port", ports[ 1 ], "--dbpath", "/data/db/" + baseName + "_target", "--nohttpinterface", "--bind_ip", "127.0.0.1", "--smallfiles" ); + +target.getDB( "admin" ).addUser( "super1", "super1" ); +assert.throws( function() { source.getDB( baseName )[ baseName ].findOne(); } ); +target.getDB( "admin" ).auth( "super1", "super1" ); + +target.getDB( baseName ).copyDatabase( baseName, baseName, source.host, "foo", "bar" ); +assert.eq( 1, target.getDB( baseName )[ baseName ].count() ); +assert.eq( 1, target.getDB( baseName )[ baseName ].findOne().i ); |