summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/start_session_command.js
blob: 1068561672cc39f114de09d38d391481c63f1dcc (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
76
77
78
79
80
(function() {
'use strict';

// This test makes assertions about the number of sessions, which are not compatible with
// implicit sessions.
TestData.disableImplicitSessions = true;

const request = {
    startSession: 1
};

let conn = MongoRunner.runMongod({setParameter: {maxSessions: 2}});
let admin = conn.getDB("admin");

// ensure that the cache is empty
let serverStatus = assert.commandWorked(admin.adminCommand({serverStatus: 1}));
assert.eq(0, serverStatus.logicalSessionRecordCache.activeSessionsCount);

// test that we can run startSession unauthenticated when the server is running without --auth

let result = admin.runCommand(request);
assert.commandWorked(
    result,
    "failed test that we can run startSession unauthenticated when the server is running without --auth");
assert(result.id, "failed test that our session response has an id");
assert.eq(result.timeoutMinutes, 30, "failed test that our session record has the correct timeout");

// test that startSession added to the cache
serverStatus = assert.commandWorked(admin.adminCommand({serverStatus: 1}));
assert.eq(1, serverStatus.logicalSessionRecordCache.activeSessionsCount);

// test that we can run startSession authenticated when the server is running without --auth

admin.createUser({user: 'user0', pwd: 'password', roles: []});
admin.auth("user0", "password");

result = admin.runCommand(request);
assert.commandWorked(
    result,
    "failed test that we can run startSession authenticated when the server is running without --auth");
assert(result.id, "failed test that our session response has an id");
assert.eq(result.timeoutMinutes, 30, "failed test that our session record has the correct timeout");

assert.commandFailed(admin.runCommand(request),
                     "failed test that we can't run startSession when the cache is full");
MongoRunner.stopMongod(conn);

//

conn = MongoRunner.runMongod({auth: ""});
admin = conn.getDB("admin");

// test that we can't run startSession unauthenticated when the server is running with --auth

assert.commandFailed(
    admin.runCommand(request),
    "failed test that we can't run startSession unauthenticated when the server is running with --auth");

//

admin.createUser({user: 'admin', pwd: 'admin', roles: jsTest.adminUserRoles});
admin.auth("admin", "admin");
admin.createUser({user: 'user0', pwd: 'password', roles: jsTest.basicUserRoles});
admin.logout();

// test that we can run startSession authenticated as one user with proper permissions

admin.auth("user0", "password");
result = admin.runCommand(request);
assert.commandWorked(
    result,
    "failed test that we can run startSession authenticated as one user with proper permissions");
assert(result.id, "failed test that our session response has an id");
assert.eq(result.timeoutMinutes, 30, "failed test that our session record has the correct timeout");
admin.logout();

//

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