diff options
| author | Matt Cotter <matt.cotter@mongodb.com> | 2016-12-12 16:45:59 -0500 |
|---|---|---|
| committer | Jonathan Reams <jbreams@mongodb.com> | 2017-01-18 16:33:50 -0500 |
| commit | 316a719cf7e88a3195f94a26a8085e7145660c47 (patch) | |
| tree | 0ee58bfdd715eef33974f06d04257d211ab4895a /jstests/noPassthroughWithMongod | |
| parent | 3b126d3ebe606f1ab13a178a4c22e797caafe12c (diff) | |
| download | mongo-316a719cf7e88a3195f94a26a8085e7145660c47.tar.gz | |
SERVER-27289 fix ConnectionString parsing in shell
(cherry picked from commit 68c8715feaa2ead6a3c25eb9aa512de779c4795d)
Diffstat (limited to 'jstests/noPassthroughWithMongod')
| -rw-r--r-- | jstests/noPassthroughWithMongod/host_connection_string_validation.js | 54 | ||||
| -rw-r--r-- | jstests/noPassthroughWithMongod/replset_host_connection_validation.js | 61 |
2 files changed, 83 insertions, 32 deletions
diff --git a/jstests/noPassthroughWithMongod/host_connection_string_validation.js b/jstests/noPassthroughWithMongod/host_connection_string_validation.js index 89d77e707f1..bb6bba625dd 100644 --- a/jstests/noPassthroughWithMongod/host_connection_string_validation.js +++ b/jstests/noPassthroughWithMongod/host_connection_string_validation.js @@ -49,50 +49,40 @@ var testHost = function(host, shouldSucceed) { var goodStrings = [ "[::1]:27999", - "[::1]:27999/test", "localhost:27999", - "localhost:27999/test", "127.0.0.1:27999", - "127.0.0.1:27999/test", "[0:0:0:0:0:0:0:1]:27999", - "[0:0:0:0:0:0:0:1]:27999/test", "[0000:0000:0000:0000:0000:0000:0000:0001]:27999", - "[0000:0000:0000:0000:0000:0000:0000:0001]:27999/test", ]; var goodSocketStrings = [ "/tmp/mongodb-27999.sock", - "/tmp/mongodb-27999.sock/test", ]; var badStrings = [ - "/", + "::1:27999", + "::1:65536", + "::1]:27999", ":", - ":/", - "/test", - ":/test", - ":27999/", - ":27999/test", - "::1]:27999/", - "[::1:27999/", - "[::1]:/test", - "[::1:]27999/", - "a[::1:]27999/", - "::1:27999/test", - "::1:65536/test", - "[::1]:cat/test", - "[::1]:1cat/test", - "localhost:/test", - "127.0.0.1:/test", - "[::1]:65536/test", - "[::1]:123456/test", - "127.0.0.1:cat/test", - "a[127.0.0.1]:27999/", - "127.0.0.1:1cat/test", - "127.0.0.1:65536/test", - "0:0::0:0:1:27999/test", - "127.0.0.1:123456/test", - "0000:0000:0000:0000:0000:0000:0000:0001:27999/test", + ":27999", + "", + "[::1:]27999", + "[::1:27999", + "[::1]:", + "[::1]:123456", + "[::1]:1cat", + "[::1]:65536", + "[::1]:cat", + "0:0::0:0:1:27999", + "0000:0000:0000:0000:0000:0000:0000:0001:27999", + "127.0.0.1:", + "127.0.0.1:123456", + "127.0.0.1:1cat", + "127.0.0.1:65536", + "127.0.0.1:cat", + "a[::1:]27999", + "a[127.0.0.1]:27999", + "localhost:", ]; function runUriTestFor(i, connectionString, isGood) { diff --git a/jstests/noPassthroughWithMongod/replset_host_connection_validation.js b/jstests/noPassthroughWithMongod/replset_host_connection_validation.js new file mode 100644 index 00000000000..076b5f931ae --- /dev/null +++ b/jstests/noPassthroughWithMongod/replset_host_connection_validation.js @@ -0,0 +1,61 @@ +// Test --host with a replica set. +(function() { + + const replSetName = 'hostTestReplSetName'; + + // This "inner_mode" method of spawning a replset and re-running was copied from + // host_connection_string_validation.js + if ("undefined" == typeof inner_mode) { + jsTest.log("Outer mode test starting a replica set"); + + const replTest = new ReplSetTest({name: replSetName, nodes: 2}); + replTest.startSet(); + replTest.initiate(); + + const primary = replTest.getPrimary(); + + const args = [ + "mongo", + "--nodb", + "--eval", + "inner_mode=true;port=" + primary.port + ";", + "jstests/noPassthroughWithMongod/host_connection_string_validation.js" + ]; + const exitCode = _runMongoProgram(...args); + jsTest.log("Inner mode test finished, exit code was " + exitCode); + + // Stop the server we started + jsTest.log("Outer mode test stopping server"); + MongoRunner.stopMongod(primary.port, 15); + + // Pass the inner test's exit code back as the outer test's exit code + quit(exitCode); + } + + 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); + } + }; + + 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]); + } + + jsTest.log("SUCCESSFUL test completion"); +})(); |
