summaryrefslogtreecommitdiff
path: root/jstests/auth/shell.js
blob: 0685798952cc416fd718109c9d8d2e2c2756ed5e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// Authenticate to a mongod from the shell via command line.

(function() {
'use strict';

const port = allocatePort();
const mongod = MongoRunner.runMongod({auth: '', port: port});
const admin = mongod.getDB('admin');

admin.createUser({user: 'admin', pwd: 'pass', roles: jsTest.adminUserRoles});

// Connect via shell round-trip in order to verify handling of mongodb:// uri with password.
const uri = 'mongodb://admin:pass@localhost:' + port + '/admin';
// Be sure to actually do something requiring authentication.
const mongo = runMongoProgram('mongo', uri, '--eval', 'db.system.users.find({});');
assert.eq(mongo, 0, "Failed connecting to mongod via shell+mongodb uri");

MongoRunner.stopMongod(mongod);
})();