diff options
| author | Richard Walters <rwalters@digitalstirling.com> | 2018-06-30 23:35:15 -0700 | 
|---|---|---|
| committer | Richard Walters <rwalters@digitalstirling.com> | 2018-06-30 23:35:15 -0700 | 
| commit | b57bf0b772c5cfef789363b9951f737d9e92a28a (patch) | |
| tree | 369f2d034a9ae4862674d73ced46a9df3714a65e /test/src | |
| parent | 6f389efe5808c83f86a4c71861c50e6e941fc5bb (diff) | |
Add code to check that scheme, if present, is legal
Diffstat (limited to 'test/src')
| -rw-r--r-- | test/src/UriTests.cpp | 39 | 
1 files changed, 39 insertions, 0 deletions
| diff --git a/test/src/UriTests.cpp b/test/src/UriTests.cpp index 6ee57c4..b4be2d5 100644 --- a/test/src/UriTests.cpp +++ b/test/src/UriTests.cpp @@ -235,3 +235,42 @@ TEST(UriTests, ParseFromStringTwiceFirstUserInfoThenWithout) {      ASSERT_TRUE(uri.ParseFromString("/foo/bar"));      ASSERT_TRUE(uri.GetUserInfo().empty());  } + +TEST(UriTests, ParseFromStringSchemeIllegalCharacters) { +    const std::vector< std::string > testVectors{ +        {"://www.example.com/"}, +        {"0://www.example.com/"}, +        {"+://www.example.com/"}, +        {"@://www.example.com/"}, +        {".://www.example.com/"}, +        {"h@://www.example.com/"}, +    }; +    size_t index = 0; +    for (const auto& testVector : testVectors) { +        Uri::Uri uri; +        ASSERT_FALSE(uri.ParseFromString(testVector)) << index; +        ++index; +    } +} + +TEST(UriTests, ParseFromStringSchemeBarelyLegal) { +    struct TestVector { +        std::string uriString; +        std::string scheme; +    }; +    const std::vector< TestVector > testVectors{ +        {"h://www.example.com/", "h"}, +        {"x+://www.example.com/", "x+"}, +        {"y-://www.example.com/", "y-"}, +        {"z.://www.example.com/", "z."}, +        {"aa://www.example.com/", "aa"}, +        {"a0://www.example.com/", "a0"}, +    }; +    size_t index = 0; +    for (const auto& testVector : testVectors) { +        Uri::Uri uri; +        ASSERT_TRUE(uri.ParseFromString(testVector.uriString)) << index; +        ASSERT_EQ(testVector.scheme, uri.GetScheme()); +        ++index; +    } +} | 
