0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 01:21:03 +01:00
mongodb/jstests/auth/auth_helpers.js

25 lines
848 B
JavaScript

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