summaryrefslogtreecommitdiff
path: root/jstests/auth
diff options
context:
space:
mode:
authorCharlie Swanson <charlie.swanson@mongodb.com>2015-09-01 16:19:57 -0400
committerCharlie Swanson <charlie.swanson@mongodb.com>2015-09-09 13:14:48 -0400
commitc15f4bb96d2ee86874582d45d1865e9358168e7e (patch)
tree92c788863ae91a8b9c5801e1d536d7ef1a02ec05 /jstests/auth
parentf5e063d4785b0460ab41de8cc4b537e5e2151338 (diff)
downloadmongo-c15f4bb96d2ee86874582d45d1865e9358168e7e.tar.gz
SERVER-18272 Update jstests to use allocatePort() instead of hard coding ports
Diffstat (limited to 'jstests/auth')
-rw-r--r--jstests/auth/auth1.js3
-rw-r--r--jstests/auth/auth3.js8
-rw-r--r--jstests/auth/localhostAuthBypass.js26
-rw-r--r--jstests/auth/logout_reconnect.js5
-rw-r--r--jstests/auth/server-4892.js23
5 files changed, 31 insertions, 34 deletions
diff --git a/jstests/auth/auth1.js b/jstests/auth/auth1.js
index 32628e8bf57..a15d4a46995 100644
--- a/jstests/auth/auth1.js
+++ b/jstests/auth/auth1.js
@@ -3,12 +3,9 @@
function setupTest() {
print("START auth1.js");
-
- port = allocatePorts( 1 )[ 0 ];
baseName = "jstests_auth_auth1";
m = MongoRunner.runMongod({auth: "",
- port: port,
nohttpinterface: "",
bind_ip: "127.0.0.1",
useHostname: false});
diff --git a/jstests/auth/auth3.js b/jstests/auth/auth3.js
index 2f28111da24..fde160d06ce 100644
--- a/jstests/auth/auth3.js
+++ b/jstests/auth/auth3.js
@@ -1,4 +1,8 @@
-var conn = MongoRunner.runMongod({auth : "", port : 31001});
+(function() {
+
+'use strict'
+
+var conn = MongoRunner.runMongod({ auth: "" });
var admin = conn.getDB("admin");
var errorCodeUnauthorized = 13;
@@ -24,3 +28,5 @@ conn.getDB("admin").auth("foo","bar");
assert("inprog" in admin.currentOp());
assert("info" in admin.killOp(123));
assert.eq(admin.fsyncUnlock().errmsg, "not locked");
+
+})();
diff --git a/jstests/auth/localhostAuthBypass.js b/jstests/auth/localhostAuthBypass.js
index b3b40598015..1b07456fbe3 100644
--- a/jstests/auth/localhostAuthBypass.js
+++ b/jstests/auth/localhostAuthBypass.js
@@ -7,8 +7,6 @@ var baseName = "auth_server-6591";
var dbpath = MongoRunner.dataPath + baseName;
var username = "foo";
var password = "bar";
-var port = allocatePorts(1)[0];
-var host = "localhost:" + port;
load("jstests/libs/host_ipaddr.js");
@@ -101,18 +99,18 @@ var authenticate = function(mongo) {
mongo.getDB("admin").auth(username, password);
};
-var shutdown = function(mongo) {
+var shutdown = function(conn) {
print("============ shutting down.");
- MongoRunner.stopMongod(port, /*signal*/false, { auth: { user: username, pwd: password}});
+ MongoRunner.stopMongod(conn.port, /*signal*/false, { auth: { user: username, pwd: password}});
};
var runTest = function(useHostName) {
print("==========================");
print("starting mongod: useHostName=" + useHostName);
print("==========================");
- MongoRunner.runMongod({auth: "", port: port, dbpath: dbpath, useHostName: useHostName});
+ var conn = MongoRunner.runMongod({auth: "", dbpath: dbpath, useHostName: useHostName});
- var mongo = new Mongo(host);
+ var mongo = new Mongo("localhost:" + conn.port);
assertCannotRunCommands(mongo);
@@ -125,7 +123,7 @@ var runTest = function(useHostName) {
assertCanRunCommands(mongo);
print("============ reconnecting with new client.");
- mongo = new Mongo(host);
+ mongo = new Mongo("localhost:" + conn.port);
assertCannotRunCommands(mongo);
@@ -133,26 +131,26 @@ var runTest = function(useHostName) {
assertCanRunCommands(mongo);
- shutdown(mongo);
+ shutdown(conn);
};
-var runNonlocalTest = function(hostPort) {
+var runNonlocalTest = function(host) {
print("==========================");
- print("starting mongod: non-local host access "+hostPort);
+ print("starting mongod: non-local host access " + host);
print("==========================");
- MongoRunner.runMongod({auth: "", port: port, dbpath: dbpath});
+ var conn = MongoRunner.runMongod({auth: "", dbpath: dbpath});
- var mongo = new Mongo(hostPort);
+ var mongo = new Mongo(host + ":" + conn.port);
assertCannotRunCommands(mongo);
assert.throws(function() { mongo.getDB("admin").createUser
({ user:username, pwd: password, roles: jsTest.adminUserRoles }); });
assert.throws(function() { mongo.getDB("$external").createUser
({ user:username, pwd: password, roles: jsTest.adminUserRoles }); });
- shutdown(mongo);
+ shutdown(conn);
};
runTest(false);
runTest(true);
-runNonlocalTest(get_ipaddr()+":"+port);
+runNonlocalTest(get_ipaddr());
diff --git a/jstests/auth/logout_reconnect.js b/jstests/auth/logout_reconnect.js
index 20d46836780..119284ce9d4 100644
--- a/jstests/auth/logout_reconnect.js
+++ b/jstests/auth/logout_reconnect.js
@@ -4,11 +4,8 @@
* It is a regression test for SERVER-8798.
*/
-port = allocatePorts( 1 )[ 0 ];
-
-conn = MongoRunner.runMongod({
+var conn = MongoRunner.runMongod({
auth : "",
- port : port,
remember : true
});
diff --git a/jstests/auth/server-4892.js b/jstests/auth/server-4892.js
index 12fc0d8c067..3053fcab4dc 100644
--- a/jstests/auth/server-4892.js
+++ b/jstests/auth/server-4892.js
@@ -7,24 +7,25 @@
var baseName = 'jstests_auth_server4892';
var dbpath = MongoRunner.dataPath + baseName;
-var port = allocatePorts( 1 )[ 0 ];
-var mongod_common_args = [
- '--port', port, '--dbpath', dbpath, '--bind_ip', '127.0.0.1', '--nohttpinterface' ];
+resetDbpath(dbpath);
+var mongodCommonArgs = {
+ dbpath: dbpath,
+ noCleanData: true,
+};
/*
* Start an instance of mongod, pass it as a parameter to operation(), then stop the instance of
* mongod before unwinding or returning out of with_mongod().
*
- * extra_mongod_args are extra arguments to pass on the mongod command line, in an Array.
+ * 'extraMongodArgs' are extra arguments to pass on the mongod command line, as an object.
*/
-function with_mongod( extra_mongod_args, operation ) {
- var mongod = startMongoProgram.apply(
- null, ['mongod'].concat( mongod_common_args, extra_mongod_args ) );
+function withMongod(extraMongodArgs, operation) {
+ var mongod = MongoRunner.runMongod(Object.merge(mongodCommonArgs, extraMongodArgs));
try {
operation( mongod );
} finally {
- MongoRunner.stopMongod( port );
+ MongoRunner.stopMongod( mongod.port );
}
}
@@ -42,9 +43,7 @@ function expectNumLiveCursors(mongod, expectedNumLiveCursors) {
+ expectedNumLiveCursors + ")");
}
-resetDbpath( dbpath );
-
-with_mongod( ['--noauth'], function setupTest( mongod ) {
+withMongod({noauth: ""}, function setupTest(mongod) {
var admin, somedb, conn;
conn = new Mongo( mongod.host );
admin = conn.getDB( 'admin' );
@@ -59,7 +58,7 @@ with_mongod( ['--noauth'], function setupTest( mongod ) {
admin.logout();
} );
-with_mongod( ['--auth'], function runTest( mongod ) {
+withMongod({auth: ""}, function runTest(mongod) {
var conn = new Mongo( mongod.host );
var somedb = conn.getDB( 'somedb' );
somedb.auth('frim', 'fram');