mongo/jstests/auth/profile_access.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

43 lines
1.3 KiB
JavaScript

// @tags: [requires_profiling]
let conn = MongoRunner.runMongod({auth: ""});
let adminDb = conn.getDB("admin");
let testDb = conn.getDB("testdb");
adminDb.createUser({
user: "admin",
pwd: "password",
roles: ["userAdminAnyDatabase", "dbAdminAnyDatabase", "readWriteAnyDatabase"],
});
adminDb.auth("admin", "password");
testDb.createUser({user: "readUser", pwd: "password", roles: ["read"]});
testDb.createUser({user: "dbAdminUser", pwd: "password", roles: ["dbAdmin"]});
testDb.createUser({
user: "dbAdminAnyDBUser",
pwd: "password",
roles: [{role: "dbAdminAnyDatabase", db: "admin"}],
});
testDb.setProfilingLevel(2);
testDb.foo.findOne();
adminDb.logout();
testDb.auth("readUser", "password");
assert.throws(function () {
testDb.system.profile.findOne();
});
testDb.logout();
// SERVER-14355
testDb.auth("dbAdminUser", "password");
testDb.setProfilingLevel(0);
testDb.system.profile.drop();
assert.commandWorked(testDb.createCollection("system.profile", {capped: true, size: 1024}));
testDb.logout();
// SERVER-16944
testDb.auth("dbAdminAnyDBUser", "password");
testDb.setProfilingLevel(0);
testDb.system.profile.drop();
assert.commandWorked(testDb.createCollection("system.profile", {capped: true, size: 1024}));
MongoRunner.stopMongod(conn, null, {user: "admin", pwd: "password"});