summaryrefslogtreecommitdiff
path: root/jstests/auth/auth_pass_prompt.js
blob: 11dccae04d183d0fca0a969b2c3d62146139400e (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
25
26
27
28
29
30
// Test db.auth with password prompt
(function() {
'use strict';

// Cannot run on windows because of a workaround for runProgram for Windows.
if (!_isWindows()) {
    const conn = MongoRunner.runMongod();
    const test = conn.getDB("test");

    test.createUser({user: "user", pwd: "password", roles: []});
    const user = '"user"';
    const database = '"test"';
    const auth =
        "'var database = db.getMongo().getDB(" + database + "); database.auth(" + user + ");'";

    const binshell = '/bin/sh';
    const mongo = 'mongo';
    const host = conn.host;
    const port = conn.port;
    const ret = runProgram(
        binshell, '-c', `echo password | ${mongo} --host ${host} --port ${port} --eval ${auth}`);

    assert.soon(() => {
        const output = rawMongoProgramOutput();
        return output.includes("Enter password:") && output.includes("Authentication succeeded");
    });

    MongoRunner.stopMongod(conn);
}
}());