summaryrefslogtreecommitdiff
path: root/jstests/replsets/localhostAuthBypass.js
diff options
context:
space:
mode:
authorJonathan Abrahams <jonathan@mongodb.com>2016-03-09 12:17:50 -0500
committerJonathan Abrahams <jonathan@mongodb.com>2016-03-09 12:18:14 -0500
commit4ae691e8edc87d0e3cfb633bb91c328426be007b (patch)
tree52079a593f54382ca13a2e741633eab1b6271893 /jstests/replsets/localhostAuthBypass.js
parenta025d43f3ce2efc1fb1282a718f5d286fa0a4dc1 (diff)
downloadmongo-4ae691e8edc87d0e3cfb633bb91c328426be007b.tar.gz
SERVER-22468 Format JS code with approved style in jstests/
Diffstat (limited to 'jstests/replsets/localhostAuthBypass.js')
-rw-r--r--jstests/replsets/localhostAuthBypass.js127
1 files changed, 71 insertions, 56 deletions
diff --git a/jstests/replsets/localhostAuthBypass.js b/jstests/replsets/localhostAuthBypass.js
index 68300c7aeb2..2b2332d258a 100644
--- a/jstests/replsets/localhostAuthBypass.js
+++ b/jstests/replsets/localhostAuthBypass.js
@@ -1,7 +1,7 @@
-//SERVER-6591: Localhost authentication exception doesn't work right on sharded cluster
+// SERVER-6591: Localhost authentication exception doesn't work right on sharded cluster
//
-//This test is to ensure that localhost authentication works correctly against a replica set
-//whether they are hosted with "localhost" or a hostname.
+// This test is to ensure that localhost authentication works correctly against a replica set
+// whether they are hosted with "localhost" or a hostname.
var replSetName = "replsets_server-6591";
var keyfile = "jstests/libs/key1";
@@ -19,55 +19,69 @@ var assertCannotRunCommands = function(mongo, isPrimary) {
print("============ ensuring that commands cannot be run.");
var test = mongo.getDB("test");
- assert.throws( function() { test.system.users.findOne(); });
- assert.throws( function() { test.foo.findOne({ _id: 0 }); });
+ assert.throws(function() {
+ test.system.users.findOne();
+ });
+ assert.throws(function() {
+ test.foo.findOne({_id: 0});
+ });
if (isPrimary) {
- assert.writeError(test.foo.save({ _id: 0 }));
- assert.writeError(test.foo.update({ _id: 0 }, { $set: { x: 20 }}));
- assert.writeError(test.foo.remove({ _id: 0 }));
+ assert.writeError(test.foo.save({_id: 0}));
+ assert.writeError(test.foo.update({_id: 0}, {$set: {x: 20}}));
+ assert.writeError(test.foo.remove({_id: 0}));
}
- assert.throws(function() {
+ assert.throws(function() {
test.foo.mapReduce(
- function() { emit(1, 1); },
- function(id, count) { return Array.sum(count); },
- { out: "other" });
+ function() {
+ emit(1, 1);
+ },
+ function(id, count) {
+ return Array.sum(count);
+ },
+ {out: "other"});
});
// DB operations
var authorizeErrorCode = 13;
- assert.commandFailedWithCode(mongo.getDB("test").copyDatabase("admin", "admin2"),
- authorizeErrorCode, "copyDatabase");
+ assert.commandFailedWithCode(
+ mongo.getDB("test").copyDatabase("admin", "admin2"), authorizeErrorCode, "copyDatabase");
// Create collection
- assert.commandFailedWithCode(mongo.getDB("test").createCollection(
- "log", { capped: true, size: 5242880, max: 5000 } ),
- authorizeErrorCode, "createCollection");
+ assert.commandFailedWithCode(
+ mongo.getDB("test").createCollection("log", {capped: true, size: 5242880, max: 5000}),
+ authorizeErrorCode,
+ "createCollection");
// Set/Get system parameters
- var params = [{ param: "journalCommitInterval", val: 200 },
- { param: "logLevel", val: 2 },
- { param: "logUserIds", val: 1 },
- { param: "notablescan", val: 1 },
- { param: "quiet", val: 1 },
- { param: "replApplyBatchSize", val: 10 },
- { param: "replIndexPrefetch", val: "none" },
- { param: "syncdelay", val: 30 },
- { param: "traceExceptions", val: true },
- { param: "sslMode", val: "preferSSL" },
- { param: "clusterAuthMode", val: "sendX509" },
- { param: "userCacheInvalidationIntervalSecs", val: 300 }
- ];
+ var params = [
+ {param: "journalCommitInterval", val: 200},
+ {param: "logLevel", val: 2},
+ {param: "logUserIds", val: 1},
+ {param: "notablescan", val: 1},
+ {param: "quiet", val: 1},
+ {param: "replApplyBatchSize", val: 10},
+ {param: "replIndexPrefetch", val: "none"},
+ {param: "syncdelay", val: 30},
+ {param: "traceExceptions", val: true},
+ {param: "sslMode", val: "preferSSL"},
+ {param: "clusterAuthMode", val: "sendX509"},
+ {param: "userCacheInvalidationIntervalSecs", val: 300}
+ ];
params.forEach(function(p) {
- var cmd = { setParameter: 1 };
+ var cmd = {
+ setParameter: 1
+ };
cmd[p.param] = p.val;
- assert.commandFailedWithCode(mongo.getDB("admin").runCommand(cmd),
- authorizeErrorCode, "setParameter: "+p.param);
+ assert.commandFailedWithCode(
+ mongo.getDB("admin").runCommand(cmd), authorizeErrorCode, "setParameter: " + p.param);
});
params.forEach(function(p) {
- var cmd = { getParameter: 1 };
+ var cmd = {
+ getParameter: 1
+ };
cmd[p.param] = 1;
- assert.commandFailedWithCode(mongo.getDB("admin").runCommand(cmd),
- authorizeErrorCode, "getParameter: "+p.param);
+ assert.commandFailedWithCode(
+ mongo.getDB("admin").runCommand(cmd), authorizeErrorCode, "getParameter: " + p.param);
});
};
@@ -78,16 +92,18 @@ var assertCanRunCommands = function(mongo) {
// will throw on failure
test.system.users.findOne();
- assert.writeOK(test.foo.save({_id: 0 }));
- assert.writeOK(test.foo.update({ _id: 0 }, { $set: { x: 20 }}));
- assert.writeOK(test.foo.remove({ _id: 0 }));
-
+ assert.writeOK(test.foo.save({_id: 0}));
+ assert.writeOK(test.foo.update({_id: 0}, {$set: {x: 20}}));
+ assert.writeOK(test.foo.remove({_id: 0}));
test.foo.mapReduce(
- function() { emit(1, 1); },
- function(id, count) { return Array.sum(count); },
- { out: "other" }
- );
+ function() {
+ emit(1, 1);
+ },
+ function(id, count) {
+ return Array.sum(count);
+ },
+ {out: "other"});
assert.commandWorked(mongo.getDB("admin").runCommand({replSetGetStatus: 1}));
};
@@ -98,11 +114,8 @@ var authenticate = function(mongo) {
};
var start = function(useHostName) {
- var rs = new ReplSetTest({name: replSetName,
- nodes : 3,
- keyFile : keyfile,
- auth: "",
- useHostName: useHostName});
+ var rs = new ReplSetTest(
+ {name: replSetName, nodes: 3, keyFile: keyfile, auth: "", useHostName: useHostName});
rs.startSet();
rs.initiate();
@@ -111,9 +124,9 @@ var start = function(useHostName) {
var shutdown = function(rs) {
print("============ shutting down.");
- rs.stopSet(/*signal*/false,
- /*forRestart*/false,
- { auth: { user: username, pwd: password}});
+ rs.stopSet(/*signal*/ false,
+ /*forRestart*/ false,
+ {auth: {user: username, pwd: password}});
};
var runTest = function(useHostName) {
@@ -181,7 +194,7 @@ var runTest = function(useHostName) {
var runNonlocalTest = function(ipAddr) {
print("==========================");
- print("starting mongod: non-local host access "+ipAddr);
+ print("starting mongod: non-local host access " + ipAddr);
print("==========================");
var rs = start(false);
@@ -190,7 +203,7 @@ var runNonlocalTest = function(ipAddr) {
var secHosts = [];
rs.getSecondaries().forEach(function(sec) {
- secHosts.push(ipAddr + ":" + rs.getPort(sec));
+ secHosts.push(ipAddr + ":" + rs.getPort(sec));
});
var mongo = new Mongo(host);
@@ -207,8 +220,10 @@ var runNonlocalTest = function(ipAddr) {
assertCannotRunCommands(m, false);
});
- assert.throws(function() { mongo.getDB("admin").createUser
- ({ user:username, pwd: password, roles: jsTest.adminUserRoles }); });
+ assert.throws(function() {
+ mongo.getDB("admin")
+ .createUser({user: username, pwd: password, roles: jsTest.adminUserRoles});
+ });
shutdown(rs);
};