Files
mongo/jstests/core/auth1.js

55 lines
1.7 KiB
JavaScript
Raw Normal View History

var mydb = db.getSiblingDB('auth1_db');
mydb.dropAllUsers();
2009-01-26 23:28:26 -05:00
pass = "a" + Math.random();
2009-01-31 18:06:10 -05:00
//print( "password [" + pass + "]" );
2009-01-26 23:28:26 -05:00
mydb.createUser({user: "eliot" ,pwd: pass, roles: jsTest.basicUserRoles});
2009-01-26 23:28:26 -05:00
assert( mydb.auth( "eliot" , pass ) , "auth failed" );
assert( ! mydb.auth( "eliot" , pass + "a" ) , "auth should have failed" );
2009-01-26 23:28:26 -05:00
pass2 = "b" + Math.random();
mydb.changeUserPassword("eliot", pass2);
2009-01-26 23:28:26 -05:00
assert( ! mydb.auth( "eliot" , pass ) , "failed to change password failed" );
assert( mydb.auth( "eliot" , pass2 ) , "new password didn't take" );
2009-02-06 14:26:56 -05:00
assert( mydb.auth( "eliot" , pass2 ) , "what?" );
mydb.dropUser( "eliot" );
assert( ! mydb.auth( "eliot" , pass2 ) , "didn't drop user" );
2009-02-07 10:27:22 -05:00
2009-02-06 14:26:56 -05:00
var a = mydb.getMongo().getDB( "admin" );
a.dropAllUsers();
2009-02-06 14:26:56 -05:00
pass = "c" + Math.random();
a.createUser({user: "super", pwd: pass, roles: jsTest.adminUserRoles});
2009-02-06 14:26:56 -05:00
assert( a.auth( "super" , pass ) , "auth failed" );
2009-02-07 10:27:22 -05:00
assert( !a.auth( "super" , pass + "a" ) , "auth should have failed" );
mydb.dropAllUsers();
pass = "a" + Math.random();
mydb.createUser({user: "eliot" , pwd: pass, roles: jsTest.basicUserRoles});
assert.commandFailed( mydb.runCommand( { authenticate: 1, user: "eliot", nonce: "foo", key: "bar" } ) );
// check sanity check SERVER-3003
var before = a.system.users.count({db: mydb.getName()});
assert.throws( function(){
mydb.createUser({ user: "" , pwd: "abc", roles: jsTest.basicUserRoles});
} , null , "C1" )
assert.throws( function(){
mydb.createUser({ user: "abc" , pwd: "", roles: jsTest.basicUserRoles});
} , null , "C2" )
var after = a.system.users.count({db: mydb.getName()});
assert( before > 0 , "C3" )
assert.eq( before , after , "C4" )
2011-11-11 16:15:57 -05:00
// Clean up after ourselves so other tests using authentication don't get messed up.
mydb.dropAllUsers()