summaryrefslogtreecommitdiff
path: root/src/mongo/client/mongo_uri_test.cpp
diff options
context:
space:
mode:
authorJonathan Reams <jbreams@mongodb.com>2016-06-28 15:39:08 -0400
committerJonathan Reams <jbreams@mongodb.com>2016-06-30 10:50:39 -0400
commit85e60b54d73f185113575bdcb82f691471e12478 (patch)
tree8080b9ba26a8bd579af02549382c42732ae400d3 /src/mongo/client/mongo_uri_test.cpp
parent515b33fed131084cbef6da9be499642715bc12f1 (diff)
downloadmongo-85e60b54d73f185113575bdcb82f691471e12478.tar.gz
SERVER-23126 Check result of connect when constructing DBClient from MongoURI
Diffstat (limited to 'src/mongo/client/mongo_uri_test.cpp')
-rw-r--r--src/mongo/client/mongo_uri_test.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/mongo/client/mongo_uri_test.cpp b/src/mongo/client/mongo_uri_test.cpp
index f67aad7b60f..71e43989a3f 100644
--- a/src/mongo/client/mongo_uri_test.cpp
+++ b/src/mongo/client/mongo_uri_test.cpp
@@ -308,4 +308,17 @@ TEST(MongoURI, InvalidURIs) {
}
}
+TEST(MongoURI, ValidButBadURIsFailToConnect) {
+ // "invalid" is a TLD that cannot exit on the public internet (see rfc2606). It should always
+ // parse as a valid URI, but connecting should always fail.
+ auto sw_uri = MongoURI::parse("mongodb://user:pass@hostname.invalid:12345");
+ ASSERT_OK(sw_uri.getStatus());
+ auto uri = sw_uri.getValue();
+ ASSERT_TRUE(uri.isValid());
+
+ std::string errmsg;
+ auto dbclient = uri.connect(errmsg);
+ ASSERT_EQ(dbclient, static_cast<decltype(dbclient)>(nullptr));
+}
+
} // namespace