1
// Ensure that inserts and updates of the system.users collection validate the schema of inserted
4
mydb = db.getSisterDB( "validate_user_documents" );
6
function assertGLEOK(status) {
7
assert(status.ok && status.err === null,
8
"Expected OK status object; found " + tojson(status));
11
function assertGLENotOK(status) {
12
assert(status.ok && status.err !== null,
13
"Expected not-OK status object; found " + tojson(status));
19
// Tests of the insert path
22
// Valid compatibility document; insert should succeed.
23
mydb.system.users.insert({ user: "spencer", pwd: hex_md5("spencer:mongo:a"), readOnly: true });
24
assertGLEOK(mydb.getLastErrorObj());
26
// Invalid compatibility document; insert should fail.
27
mydb.system.users.insert({ user: "andy", readOnly: true });
28
assertGLENotOK(mydb.getLastErrorObj());
30
// Valid extended document; insert should succeed.
31
mydb.system.users.insert({ user: "spencer", userSource: "test2", roles: ["dbAdmin"] });
32
assertGLEOK(mydb.getLastErrorObj());
34
// Invalid extended document; insert should fail.
35
mydb.system.users.insert({ user: "andy", userSource: "test2", roles: ["dbAdmin", 15] });
36
assertGLENotOK(mydb.getLastErrorObj());
40
// Tests of the update path
43
// Update a document in a legal way, expect success.
44
mydb.system.users.update({user: "spencer", userSource: null}, { $set: {readOnly: false} });
45
assertGLEOK(mydb.getLastErrorObj());
48
// Update a document in a way that is illegal, expect failure.
49
mydb.system.users.update({user: "spencer", userSource: null}, { $unset: {pwd: 1} });
50
assertGLENotOK(mydb.getLastErrorObj());