File: validate_user_documents.js

package info (click to toggle)
mongodb 1%3A2.4.10-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 82,464 kB
  • sloc: cpp: 740,225; ansic: 152,098; sh: 13,820; python: 11,864; makefile: 1,012; perl: 922; pascal: 617; java: 452; lisp: 222; asm: 174
file content (52 lines) | stat: -rw-r--r-- 1,653 bytes parent folder | download | duplicates (3)
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
// Ensure that inserts and updates of the system.users collection validate the schema of inserted
// documents.

mydb = db.getSisterDB( "validate_user_documents" );

function assertGLEOK(status) {
    assert(status.ok && status.err === null,
           "Expected OK status object; found " + tojson(status));
}

function assertGLENotOK(status) {
    assert(status.ok && status.err !== null,
           "Expected not-OK status object; found " + tojson(status));
}

mydb.dropDatabase();

//
// Tests of the insert path
//

// Valid compatibility document; insert should succeed.
mydb.system.users.insert({ user: "spencer", pwd: hex_md5("spencer:mongo:a"), readOnly: true });
assertGLEOK(mydb.getLastErrorObj());

// Invalid compatibility document; insert should fail.
mydb.system.users.insert({ user: "andy", readOnly: true });
assertGLENotOK(mydb.getLastErrorObj());

// Valid extended document; insert should succeed.
mydb.system.users.insert({ user: "spencer", userSource: "test2", roles: ["dbAdmin"] });
assertGLEOK(mydb.getLastErrorObj());

// Invalid extended document; insert should fail.
mydb.system.users.insert({ user: "andy", userSource: "test2", roles: ["dbAdmin", 15] });
assertGLENotOK(mydb.getLastErrorObj());


//
// Tests of the update path
//

// Update a document in a legal way, expect success.
mydb.system.users.update({user: "spencer", userSource: null}, { $set: {readOnly: false} });
assertGLEOK(mydb.getLastErrorObj());


// Update a document in a way that is illegal, expect failure.
mydb.system.users.update({user: "spencer", userSource: null}, { $unset: {pwd: 1} });
assertGLENotOK(mydb.getLastErrorObj());

mydb.dropDatabase();