summaryrefslogtreecommitdiff
path: root/jstests/auth/kill_sessions_logging.js
blob: a32517d40c2d0acecd36bbf839c05c6cfba03b48 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Test that killing a session logs a message.
//
// @tags: [requires_sharding]

"use strict";

function testFixtureSimple(name) {
    this.name = name + " (simple)";
    jsTest.log("Starting test: " + this.name);

    this.mongod = MongoRunner.runMongod();
    this.db = this.mongod.getDB("admin");
    this.db.createUser({user: 'user', pwd: 'pwd', roles: ['root']});

    jsTest.log(this.name + " initialization complete");

    this.check = function() {
        checkLog.contains(this.db, '"msg":"Success: kill session"', 15000);
        jsTest.log(this.name + " verified successfully");
    };

    this.stop = function() {
        jsTest.log(this.name + " shutting down");
        MongoRunner.stopMongod(this.mongod);
        jsTest.log(this.name + " shutdown complete");
    };
}

function testFixtureShard(name) {
    this.name = name + " (shard)";
    jsTest.log("Starting test: " + this.name);

    this.mongos = new ShardingTest({});
    this.db = this.mongos.getDB("admin");
    this.db.createUser({user: 'user', pwd: 'pwd', roles: ['root']});

    jsTest.log(this.name + " initialization complete");

    this.check = function() {
        checkLog.contains(this.db, '"msg":"Success: kill session"', 15000);
        jsTest.log(this.name + " verified successfully");
    };

    this.stop = function() {
        jsTest.log(this.name + " shutting down");
        this.mongos.stop();
        jsTest.log(this.name + " shutdown complete");
    };
}

const testKillSessions = function(fixture) {
    const randomSessionId = UUID("193bd705-3941-4be4-b463-5ca01f384e6f");
    assert.commandWorked(fixture.db.runCommand({killSessions: [{id: randomSessionId}]}));
    fixture.check();
    fixture.stop();
};

const testKillAllSessions = function(fixture) {
    assert.commandWorked(fixture.db.runCommand({killAllSessions: [{user: "user", db: "admin"}]}));
    fixture.check();
    fixture.stop();
};

const testKillAllSessionsByPattern = function(fixture) {
    fixture.db.runCommand({killAllSessionsByPattern: [{users: [{user: "user", db: "admin"}]}]});
    fixture.check();
    fixture.stop();
};

testKillSessions(new testFixtureSimple("testKillSessions"));
testKillAllSessions(new testFixtureSimple("testKillAllSessions"));
testKillAllSessionsByPattern(new testFixtureSimple("testKillAllSessionsByPattern"));
testKillSessions(new testFixtureShard("testKillSessions"));
testKillAllSessions(new testFixtureShard("testKillAllSessions"));
testKillAllSessionsByPattern(new testFixtureShard("testKillAllSessionsByPattern"));