3
3
var conn = MongoRunner.runMongod({auth : ""});
5
function assertGLENotOK(status) {
6
assert(status.ok && status.err !== null,
7
"Expected not-OK status object; found " + tojson(status));
10
5
var adminDB = conn.getDB("admin");
11
6
var testDB = conn.getDB("test");
12
adminDB.addUser({user:'admin', pwd:'x', roles:['userAdminAnyDatabase']});
7
adminDB.createUser({user:'admin', pwd:'x', roles:['userAdminAnyDatabase']});
13
8
adminDB.auth('admin','x');
14
adminDB.addUser({user:'mallory', pwd:'x', roles:[], otherDBRoles:{test:['readWrite']}});
15
testDB.addUser({user:'user1', pwd:'x', roles:['read']});
16
testDB.addUser({user:'user2', pwd:'x', roles:['read']});
17
assert.eq(2, testDB.system.users.count());
9
adminDB.createUser({user:'mallory', pwd:'x', roles:['readWriteAnyDatabase']});
10
testDB.createUser({user:'user', pwd:'x', roles:['read']});
11
assert.eq(3, adminDB.system.users.count());
20
14
adminDB.auth('mallory', 'x');
21
testDB.system.users.createIndex({haxx:1}, {unique:true, dropDups:true});
22
assertGLENotOK(testDB.getLastErrorObj());
23
testDB.exploit.system.indexes.insert({ns: "test.system.users", key: { haxx: 1.0 }, name: "haxx_1",
24
unique: true, dropDups: true});
25
assertGLENotOK(testDB.getLastErrorObj());
15
var res = adminDB.system.users.createIndex({ haxx: 1 }, { unique: true, dropDups: true });
17
assert.eq(13, res.code); // unauthorized
18
assert.writeError(adminDB.exploit.system.indexes.insert({ ns: "admin.system.users",
26
23
// Make sure that no indexes were built.
28
testDB.system.namespaces.findOne(
29
{$and : [{name : /^test\.system\.users\.\$/},
30
{name : {$ne : "test.system.users.$_id_"}},
31
{name : {$ne : "test.system.users.$user_1_userSource_1"}} ]}));
25
adminDB.system.namespaces.findOne(
26
{$and : [{name : /^admin\.system\.users\.\$/},
27
{name : {$ne : "admin.system.users.$_id_"}},
28
{name : {$ne : "admin.system.users.$user_1_db_1"}} ]}));
34
31
adminDB.auth('admin','x');
35
32
// Make sure that no users were actually dropped
36
assert.eq(2, testDB.system.users.count());
b'\\ No newline at end of file'
33
assert.eq(3, adminDB.system.users.count());