summaryrefslogtreecommitdiff
path: root/jstests/auth/logout_deprecated.js
blob: ec95cc3b9ade73f091a70fe6d9c6bf050703743f (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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/**
 * Tests that logout emits a deprecation warning once.
 *
 * @tags: [
 *   requires_auth,
 *   requires_non_retryable_commands,
 *   requires_sharding,
 * ]
 */
(function() {
"use strict";

function runTest(conn) {
    const logId = 5626600;
    const logAttr = {};

    const admin = conn.getDB("admin");
    admin.createUser({user: 'admin', pwd: 'pass', roles: jsTest.adminUserRoles});
    assert(admin.auth('admin', 'pass'));

    admin.createUser({user: 'test', pwd: 'pass', roles: []});

    const logoutConn = new Mongo(conn.host);
    const logoutDB = logoutConn.getDB('admin');

    assert(logoutDB.auth('test', 'pass'));
    assert.commandWorked(logoutDB.runCommand({logout: 1}));
    assert(checkLog.checkContainsOnceJson(admin, logId, logAttr));

    // We don't emit the message a second time, so there's still just one entry.
    assert(logoutDB.auth('test', 'pass'));
    assert.commandWorked(logoutDB.runCommand({logout: 1}));
    assert(checkLog.checkContainsOnceJson(admin, logId, logAttr));
}

{
    jsTest.log("Running standalone test");
    const m = MongoRunner.runMongod({auth: ""});
    runTest(m);
    MongoRunner.stopMongod(m);
}

{
    jsTest.log("Running sharded test");
    const st =
        new ShardingTest({shards: 1, mongos: 1, config: 1, other: {keyFile: 'jstests/libs/key1'}});
    runTest(st.s0);
    st.stop();
}
})();