Files
mongo/jstests/auth/auth_helpers.js
Gabriel Marks 4245ac41b8 SERVER-87287 Remove MONGODB-CR auth logic (#26633)
GitOrigin-RevId: 902bce3c1018e15e526a7ce0cb0192067566f8fe
2024-08-30 20:29:27 +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);