mongo/jstests/auth/disable_localhost_bypass.js
Steve McClure 1ffbc6c2e9 SERVER-109432: Autofix JS var usage to favor let (#40637)
GitOrigin-RevId: 9674b7db36a0f3f650d39c1e3fb2ad6ff2141cfb
2025-08-28 19:21:01 +00:00

31 lines
1.1 KiB
JavaScript

let conn1 = MongoRunner.runMongod({auth: "", setParameter: "enableLocalhostAuthBypass=true"});
let 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"});