File: auth1.js

package info (click to toggle)
mongodb 1%3A2.0.6-1.1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 17,204 kB
  • sloc: cpp: 109,783; ansic: 101,073; python: 2,287; perl: 395; makefile: 370; sh: 242; asm: 46
file content (57 lines) | stat: -rw-r--r-- 1,530 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
users = db.getCollection( "system.users" );
users.remove( {} );

pass = "a" + Math.random();
//print( "password [" + pass + "]" );

db.addUser( "eliot" , pass );

assert( db.auth( "eliot" , pass ) , "auth failed" );
assert( ! db.auth( "eliot" , pass + "a" ) , "auth should have failed" );

pass2 = "b" + Math.random();
db.addUser( "eliot" , pass2 );

assert( ! db.auth( "eliot" , pass ) , "failed to change password failed" );
assert( db.auth( "eliot" , pass2 ) , "new password didn't take" );

assert( db.auth( "eliot" , pass2 ) , "what?" );
db.removeUser( "eliot" );
assert( ! db.auth( "eliot" , pass2 ) , "didn't remove user" );


var a = db.getMongo().getDB( "admin" );
users = a.getCollection( "system.users" );
users.remove( {} );
pass = "c" + Math.random();
a.addUser( "super", pass );
assert( a.auth( "super" , pass ) , "auth failed" );
assert( !a.auth( "super" , pass + "a" ) , "auth should have failed" );

db2 = new Mongo( db.getMongo().host ).getDB( db.getName() );

users = db2.getCollection( "system.users" );
users.remove( {} );

pass = "a" + Math.random();

db2.addUser( "eliot" , pass );

assert.commandFailed( db2.runCommand( { authenticate: 1, user: "eliot", nonce: "foo", key: "bar" } ) );

// check sanity check SERVER-3003

before = db2.system.users.count()

assert.throws( function(){
    db2.addUser( "" , "abc" )
} , null , "C1" )

assert.throws( function(){
    db2.addUser( "abc" , "" )
} , null , "C2" )


after = db2.system.users.count()
assert( before > 0 , "C3" )
assert.eq( before , after , "C4" )