summaryrefslogtreecommitdiff
path: root/jstests/auth/auth_helpers.js
blob: f2d9f458eacfc84596c507d1cb126c7825f59a51 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// 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);
})();