summaryrefslogtreecommitdiff
path: root/jstests/auth/disable_localhost_bypass.js
blob: f26eb4f6ed6d5aa864928cb6582f7c0a11d39031 (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
var conn1 = MongoRunner.runMongod({auth: "", setParameter: "enableLocalhostAuthBypass=true"});
var conn2 = MongoRunner.runMongod({auth: "", setParameter: "enableLocalhostAuthBypass=false"});

// Should fail because of localhost exception narrowed (SERVER-12621).
assert.writeError(conn1.getDB("test").foo.insert({a: 1}));
assert.throws(function() {
    conn2.getDB("test").foo.findOne();
});

// Should succeed due to localhost exception.
conn1.getDB("admin").createUser({user: "root", pwd: "pass", roles: ["root"]});

conn1.getDB("admin").auth("root", "pass");
conn1.getDB("test").foo.insert({a: 1});

conn1.getDB("admin").dropAllUsers();
conn1.getDB("admin").logout();

assert.throws(function() {
    conn2.getDB("test").foo.findOne();
});

// Should fail since localhost exception is disabled
assert.throws(function() {
    conn2.getDB("admin").createUser({user: "root", pwd: "pass", roles: ["root"]});
});

print("SUCCESS Completed disable_localhost_bypass.js");
MongoRunner.stopMongod(conn1, null, {user: "root", pwd: "pass"});
MongoRunner.stopMongod(conn2, null, {user: "root", pwd: "pass"});