0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00
mongodb/jstests/auth/auth_helpers.js
2019-07-27 11:02:23 -04:00

25 lines
784 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);
})();