diff options
author | Shreyas Kalyan <shreyaskalyan@gmail.com> | 2018-10-08 15:49:24 -0400 |
---|---|---|
committer | Shreyas Kalyan <shreyaskalyan@gmail.com> | 2018-10-12 16:35:55 -0400 |
commit | 2e58710210f996eea00e192f987ae90acb71abbf (patch) | |
tree | 4eb63e2f39158302eadb96d15013dfde85730e08 /src/mongo/client/mongo_uri_test.cpp | |
parent | 8657f94a66ff4950a9dc4c04eebec86730d87db2 (diff) | |
download | mongo-2e58710210f996eea00e192f987ae90acb71abbf.tar.gz |
SERVER-36272 Catch error in parsing values after % in URIs
Diffstat (limited to 'src/mongo/client/mongo_uri_test.cpp')
-rw-r--r-- | src/mongo/client/mongo_uri_test.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/mongo/client/mongo_uri_test.cpp b/src/mongo/client/mongo_uri_test.cpp index 4d8088ea015..6e97d94e924 100644 --- a/src/mongo/client/mongo_uri_test.cpp +++ b/src/mongo/client/mongo_uri_test.cpp @@ -39,6 +39,8 @@ #include "mongo/unittest/unittest.h" #include <boost/filesystem/operations.hpp> +#include <boost/optional.hpp> +#include <boost/optional/optional_io.hpp> namespace mongo { namespace { @@ -55,6 +57,7 @@ struct URITestCase { struct InvalidURITestCase { std::string URI; + boost::optional<Status> status = boost::none; }; const ConnectionString::ConnectionType kMaster = ConnectionString::MASTER; @@ -354,6 +357,12 @@ const InvalidURITestCase invalidCases[] = { // Host list must actually be comma separated. {"mongodb://localhost:27017localhost:27018"}, + // % symbol in password must be escaped. + {"mongodb://localhost:pass%word@127.0.0.1:27017", + Status(ErrorCodes::FailedToParse, + "The characters after the % do not form a hex value. Please escape the % or pass a " + "valid hex value. ")}, + // Domain sockets have to end in ".sock". {"mongodb://%2Fnotareal%2Fdomainsock"}, @@ -465,6 +474,9 @@ TEST(MongoURI, InvalidURIs) { unittest::log() << "Testing URI: " << testCase.URI << '\n'; auto cs_status = MongoURI::parse(testCase.URI); ASSERT_NOT_OK(cs_status); + if (testCase.status) { + ASSERT_EQUALS(testCase.status, cs_status.getStatus()); + } } } |