diff options
Diffstat (limited to 'jstests/core/connection_string_validation.js')
-rw-r--r-- | jstests/core/connection_string_validation.js | 80 |
1 files changed, 37 insertions, 43 deletions
diff --git a/jstests/core/connection_string_validation.js b/jstests/core/connection_string_validation.js index a682b27ea79..232650f230b 100644 --- a/jstests/core/connection_string_validation.js +++ b/jstests/core/connection_string_validation.js @@ -3,39 +3,36 @@ port = "27017"; -if ( db.getMongo().host.indexOf( ":" ) >= 0 ) { - var idx = db.getMongo().host.indexOf( ":" ); - port = db.getMongo().host.substring( idx + 1 ); +if (db.getMongo().host.indexOf(":") >= 0) { + var idx = db.getMongo().host.indexOf(":"); + port = db.getMongo().host.substring(idx + 1); } -var goodStrings = [ - "localhost:" + port + "/test", - "127.0.0.1:" + port + "/test" - ]; +var goodStrings = ["localhost:" + port + "/test", "127.0.0.1:" + port + "/test"]; var badStrings = [ - { s: undefined, r: /^Missing connection string$/ }, - { s: 7, r: /^Incorrect type/ }, - { s: null, r: /^Incorrect type/ }, - { s: "", r: /^Empty connection string$/ }, - { s: " ", r: /^Empty connection string$/ }, - { s: ":", r: /^Missing host name/ }, - { s: "/", r: /^Missing host name/ }, - { s: ":/", r: /^Missing host name/ }, - { s: ":/test", r: /^Missing host name/ }, - { s: ":" + port + "/", r: /^Missing host name/ }, - { s: ":" + port + "/test", r: /^Missing host name/ }, - { s: "/test", r: /^Missing host name/ }, - { s: "localhost:/test", r: /^Missing port number/ }, - { s: "127.0.0.1:/test", r: /^Missing port number/ }, - { s: "127.0.0.1:cat/test", r: /^Invalid port number/ }, - { s: "127.0.0.1:1cat/test", r: /^Invalid port number/ }, - { s: "127.0.0.1:123456/test", r: /^Invalid port number/ }, - { s: "127.0.0.1:65536/test", r: /^Invalid port number/ }, - { s: "::1:65536/test", r: /^Invalid port number/ }, - { s: "127.0.0.1:" + port + "/", r: /^Missing database name/ }, - { s: "::1:" + port + "/", r: /^Missing database name/ } - ]; + {s: undefined, r: /^Missing connection string$/}, + {s: 7, r: /^Incorrect type/}, + {s: null, r: /^Incorrect type/}, + {s: "", r: /^Empty connection string$/}, + {s: " ", r: /^Empty connection string$/}, + {s: ":", r: /^Missing host name/}, + {s: "/", r: /^Missing host name/}, + {s: ":/", r: /^Missing host name/}, + {s: ":/test", r: /^Missing host name/}, + {s: ":" + port + "/", r: /^Missing host name/}, + {s: ":" + port + "/test", r: /^Missing host name/}, + {s: "/test", r: /^Missing host name/}, + {s: "localhost:/test", r: /^Missing port number/}, + {s: "127.0.0.1:/test", r: /^Missing port number/}, + {s: "127.0.0.1:cat/test", r: /^Invalid port number/}, + {s: "127.0.0.1:1cat/test", r: /^Invalid port number/}, + {s: "127.0.0.1:123456/test", r: /^Invalid port number/}, + {s: "127.0.0.1:65536/test", r: /^Invalid port number/}, + {s: "::1:65536/test", r: /^Invalid port number/}, + {s: "127.0.0.1:" + port + "/", r: /^Missing database name/}, + {s: "::1:" + port + "/", r: /^Missing database name/} +]; function testGood(i, connectionString) { print("\nTesting good connection string " + i + " (\"" + connectionString + "\") ..."); @@ -44,18 +41,17 @@ function testGood(i, connectionString) { try { var connectDB = connect(connectionString); connectDB = null; - } - catch (e) { + } catch (e) { gotException = true; exception = e; } if (!gotException) { - print("Good connection string " + i + - " (\"" + connectionString + "\") correctly validated"); + print("Good connection string " + i + " (\"" + connectionString + + "\") correctly validated"); return; } - var message = "FAILED to correctly validate goodString " + i + - " (\"" + connectionString + "\"): exception was \"" + tojson(exception) + "\""; + var message = "FAILED to correctly validate goodString " + i + " (\"" + connectionString + + "\"): exception was \"" + tojson(exception) + "\""; doassert(message); } @@ -67,8 +63,7 @@ function testBad(i, connectionString, errorRegex) { try { var connectDB = connect(connectionString); connectDB = null; - } - catch (e) { + } catch (e) { gotException = true; exception = e; if (errorRegex.test(e.message)) { @@ -80,13 +75,12 @@ function testBad(i, connectionString, errorRegex) { "\") correctly rejected:\n" + tojson(exception)); return; } - var message = "FAILED to generate correct exception for badString " + i + - " (\"" + connectionString + "\"): "; + var message = "FAILED to generate correct exception for badString " + i + " (\"" + + connectionString + "\"): "; if (gotException) { - message += "exception was \"" + tojson(exception) + - "\", it should have matched \"" + errorRegex.toString() + "\""; - } - else { + message += "exception was \"" + tojson(exception) + "\", it should have matched \"" + + errorRegex.toString() + "\""; + } else { message += "no exception was thrown"; } doassert(message); |