summaryrefslogtreecommitdiff
path: root/jstests/noPassthroughWithMongod
diff options
context:
space:
mode:
authorSara Golemon <sara.golemon@mongodb.com>2017-09-18 12:07:30 -0400
committerSara Golemon <sara.golemon@mongodb.com>2017-11-27 10:45:41 -0500
commite76bc63489eea392e82d9a029a578541c9cdff33 (patch)
tree8a00d2a98b20a24408a50d5c60f93f457e44ddcc /jstests/noPassthroughWithMongod
parent80652b9b86a78971c06fa05497cb359930ff4661 (diff)
downloadmongo-e76bc63489eea392e82d9a029a578541c9cdff33.tar.gz
SERVER-28072 Construct mongodb:// URI from RS string and dbname
(cherry picked from commit 592208bb012bee0355d2024dcbc062185e6d22e7)
Diffstat (limited to 'jstests/noPassthroughWithMongod')
-rw-r--r--jstests/noPassthroughWithMongod/replset_host_connection_validation.js64
1 files changed, 43 insertions, 21 deletions
diff --git a/jstests/noPassthroughWithMongod/replset_host_connection_validation.js b/jstests/noPassthroughWithMongod/replset_host_connection_validation.js
index 7e48de363e2..e65387dd705 100644
--- a/jstests/noPassthroughWithMongod/replset_host_connection_validation.js
+++ b/jstests/noPassthroughWithMongod/replset_host_connection_validation.js
@@ -1,5 +1,6 @@
// Test --host with a replica set.
(function() {
+ 'use strict';
const replSetName = 'hostTestReplSetName';
@@ -26,35 +27,56 @@
// Pass the inner test's exit code back as the outer test's exit code
if (exitCode != 0) {
- doassert("inner test failed with exit code " + exitcode);
+ doassert("inner test failed with exit code " + exitCode);
}
return;
}
- const testHost = function(host) {
- const exitCode = runMongoProgram('mongo', '--eval', ';', '--host', host);
- if (exitCode !== 0) {
- doassert("failed to connect with `--host " + host +
- "`, but expected success. Exit code: " + exitCode);
+ function testHost(host, uri, ok) {
+ const exitCode = runMongoProgram('mongo', '--eval', ';', '--host', host, uri);
+ if (ok) {
+ assert.eq(exitCode, 0, "failed to connect with `--host " + host + "`");
+ } else {
+ assert.neq(exitCode, 0, "unexpectedly succeeded to connect with `--host " + host + "`");
}
- };
-
- const connStrings = [
- `localhost:${port}`,
- `${replSetName}/localhost:${port}`,
- `mongodb://localhost:${port}/admin?replicaSet=${replSetName}`,
- `mongodb://localhost:${port}`,
- ];
-
- function runConnectionStringTestFor(i, connectionString) {
- print("Testing connection string " + i + "...");
- print(" * testing " + connectionString);
- testHost(connectionString);
}
- for (let i = 0; i < connStrings.length; ++i) {
- runConnectionStringTestFor(i, connStrings[i]);
+ function runConnectionStringTestFor(connectionString, uri, ok) {
+ print("* Testing: --host " + connectionString + " " + uri);
+ if (!ok) {
+ print(" This should fail");
+ }
+ testHost(connectionString, uri, ok);
+ }
+
+ function expSuccess(str) {
+ runConnectionStringTestFor(str, '', true);
+ if (!str.startsWith('mongodb://')) {
+ runConnectionStringTestFor(str, 'dbname', true);
+ }
}
+ function expFailure(str) {
+ runConnectionStringTestFor(str, '', false);
+ }
+
+ expSuccess(`localhost:${port}`);
+ expSuccess(`${replSetName}/localhost:${port}`);
+ expSuccess(`${replSetName}/localhost:${port},[::1]:${port}`);
+ expSuccess(`${replSetName}/localhost:${port},`);
+ expSuccess(`${replSetName}/localhost:${port},,`);
+ expSuccess(`mongodb://localhost:${port}/admin?replicaSet=${replSetName}`);
+ expSuccess(`mongodb://localhost:${port}`);
+
+ expFailure(',');
+ expFailure(',,');
+ expFailure(`${replSetName}/`);
+ expFailure(`${replSetName}/,`);
+ expFailure(`${replSetName}/,,`);
+ expFailure(`${replSetName}//not/a/socket`);
+ expFailure(`mongodb://localhost:${port}/admin?replicaSet=`);
+ expFailure('mongodb://localhost:');
+ expFailure(`mongodb://:${port}`);
+
jsTest.log("SUCCESSFUL test completion");
})();