summaryrefslogtreecommitdiff
path: root/jstests/auth/auth2.js
blob: 077acf07c0f2ca84ddb1fa2b3bec9a69bc8e8e71 (plain)
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
// test read/write permissions

let m = MongoRunner.runMongod({auth: "", bind_ip: "127.0.0.1"});
db = m.getDB("admin");

// These statements throw because the localhost exception does not allow
// these operations: it only allows the creation of the first admin user
// and necessary setup operations.
assert.throws(function() {
    db.users.count();
});
assert.throws(function() {
    db.shutdownServer();
});

db.createUser({user: "eliot", pwd: "eliot", roles: ["root"]});

// These statements throw because we have a user but have not authenticated
// as that user.
assert.throws(function() {
    db.users.count();
});
assert.throws(function() {
    db.shutdownServer();
});

db.auth("eliot", "eliot");

let users = db.getCollection("system.users");
assert.eq(1, users.count());

db.shutdownServer();
waitProgram(m.pid);