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

28 lines
1023 B
JavaScript

// Test the db.auth() shell helper.
const conn = MongoRunner.runMongod();
const admin = conn.getDB("admin");
const kTestUser = "andy";
const kTestPassword = "a";
admin.createUser({user: kTestUser, pwd: kTestPassword, roles: jsTest.adminUserRoles});
assert(admin.auth({user: kTestUser, pwd: kTestPassword}));
assert(admin.logout());
// Try all the ways to call db.auth that uses SCRAM-SHA-1.
assert(admin.auth(kTestUser, kTestPassword));
assert(admin.logout());
assert(admin.auth({user: kTestUser, pwd: kTestPassword}));
assert(admin.logout());
assert(admin.auth({mechanism: "SCRAM-SHA-1", user: kTestUser, pwd: kTestPassword}));
assert(admin.logout());
// MONGODB-CR is not supported anymore.
assert(!admin.auth({mechanism: "MONGODB-CR", user: kTestUser, pwd: kTestPassword}));
MongoRunner.stopMongod(conn);
// Invalid mechanisms shouldn't lead to authentication, but also shouldn't crash.
assert(!admin.auth({mechanism: "this-mechanism-is-fake", user: kTestUser, pwd: kTestPassword}));
MongoRunner.stopMongod(conn);