summaryrefslogtreecommitdiff
path: root/jstests/auth/pre_auth_commands_with_sessions.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/auth/pre_auth_commands_with_sessions.js')
-rw-r--r--jstests/auth/pre_auth_commands_with_sessions.js95
1 files changed, 47 insertions, 48 deletions
diff --git a/jstests/auth/pre_auth_commands_with_sessions.js b/jstests/auth/pre_auth_commands_with_sessions.js
index 0e440a01c13..19bee66efb6 100644
--- a/jstests/auth/pre_auth_commands_with_sessions.js
+++ b/jstests/auth/pre_auth_commands_with_sessions.js
@@ -1,52 +1,51 @@
(function() {
- 'use strict';
-
- var conn = MongoRunner.runMongod({auth: ""});
- var admin = conn.getDB("admin");
- var db = conn.getDB("otherdb");
-
- admin.createUser({user: "admin", pwd: "pwd", roles: jsTest.adminUserRoles});
- admin.auth("admin", "pwd");
- db.createUser({user: "lily", pwd: "pwd", roles: jsTest.basicUserRoles});
+'use strict';
+
+var conn = MongoRunner.runMongod({auth: ""});
+var admin = conn.getDB("admin");
+var db = conn.getDB("otherdb");
+
+admin.createUser({user: "admin", pwd: "pwd", roles: jsTest.adminUserRoles});
+admin.auth("admin", "pwd");
+db.createUser({user: "lily", pwd: "pwd", roles: jsTest.basicUserRoles});
+admin.logout();
+
+var testCommand = function(cmd) {
+ // Test that we can run a pre-auth command without authenticating.
+ var command = {[cmd]: 1};
+
+ assert.commandWorked(admin.runCommand(command));
+
+ // Test that we can authenticate and start a session
+ db.auth("lily", "pwd");
+ var res = admin.runCommand({startSession: 1});
+ assert.commandWorked(res);
+ var id = res.id;
+
+ var commandWithSession = {[cmd]: 1, lsid: res.id};
+
+ // Test that we can run a pre-auth command with a session while
+ // the session owner is logged in (and the session gets ignored)
+ assert.commandWorked(db.runCommand(command),
+ "failed to run command " + cmd + " while logged in");
+ assert.commandWorked(db.runCommand(commandWithSession),
+ "failed to run command " + cmd + " with session while logged in");
+
+ // Test that we can run a pre-auth command with a session while
+ // nobody is logged in (and the session gets ignored)
+ db.logout();
+ assert.commandWorked(db.runCommand(command),
+ "failed to run command " + cmd + " without being logged in");
+ assert.commandWorked(db.runCommand(commandWithSession),
+ "failed to run command " + cmd + " with session without being logged in");
+
+ db.logout();
admin.logout();
+};
- var testCommand = function(cmd) {
- // Test that we can run a pre-auth command without authenticating.
- var command = {[cmd]: 1};
-
- assert.commandWorked(admin.runCommand(command));
-
- // Test that we can authenticate and start a session
- db.auth("lily", "pwd");
- var res = admin.runCommand({startSession: 1});
- assert.commandWorked(res);
- var id = res.id;
-
- var commandWithSession = {[cmd]: 1, lsid: res.id};
-
- // Test that we can run a pre-auth command with a session while
- // the session owner is logged in (and the session gets ignored)
- assert.commandWorked(db.runCommand(command),
- "failed to run command " + cmd + " while logged in");
- assert.commandWorked(db.runCommand(commandWithSession),
- "failed to run command " + cmd + " with session while logged in");
-
- // Test that we can run a pre-auth command with a session while
- // nobody is logged in (and the session gets ignored)
- db.logout();
- assert.commandWorked(db.runCommand(command),
- "failed to run command " + cmd + " without being logged in");
- assert.commandWorked(
- db.runCommand(commandWithSession),
- "failed to run command " + cmd + " with session without being logged in");
-
- db.logout();
- admin.logout();
- };
-
- var commands = ["ping", "ismaster"];
- for (var i = 0; i < commands.length; i++) {
- testCommand(commands[i]);
- }
- MongoRunner.stopMongod(conn, null, {user: "admin", pwd: "pwd"});
+var commands = ["ping", "ismaster"];
+for (var i = 0; i < commands.length; i++) {
+ testCommand(commands[i]);
+}
+MongoRunner.stopMongod(conn, null, {user: "admin", pwd: "pwd"});
})();