Files
mongo/jstests/auth/auth2.js
Zac 591928c619 SERVER-108478 JS formatted by prettier and remove clang-format (#39656)
GitOrigin-RevId: 6c8f6aded47f260aa4f7c231b17dae3302cb1e04
2025-08-21 17:27:09 +00:00

34 lines
834 B
JavaScript

// test read/write permissions
let m = MongoRunner.runMongod({auth: "", bind_ip: "127.0.0.1"});
const 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);