aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorRichard Walters <rwalters@digitalstirling.com>2018-07-01 14:48:14 -0700
committerRichard Walters <rwalters@digitalstirling.com>2018-07-01 14:48:14 -0700
commit9f9ee6af4299dbc95f5d7b814679714ba0ab5051 (patch)
treef69cafb9f60470d762b73388fbd86775459df200 /test
parent6b9217cc7eeb72363f33a0b1330dcdca52d25f8e (diff)
Handle bad host names
* Detect bad characters in host names. * Incorporate splitting host and port into the state machine that is parsing/decoding the host. NOTE: IPv6address is not checked for bad characters yet. More research is needed to learn exactly what are the various ways to write an IPv6 address.
Diffstat (limited to 'test')
-rw-r--r--test/src/UriTests.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/test/src/UriTests.cpp b/test/src/UriTests.cpp
index 1724b89..d7ada25 100644
--- a/test/src/UriTests.cpp
+++ b/test/src/UriTests.cpp
@@ -311,6 +311,44 @@ TEST(UriTests, ParseFromStringUserInfoBarelyLegal) {
}
}
+TEST(UriTests, ParseFromStringHostIllegalCharacters) {
+ const std::vector< std::string > testVectors{
+ {"//%X@www.example.com/"},
+ {"//@www:example.com/"},
+ {"//[vX.:]/"},
+ };
+ size_t index = 0;
+ for (const auto& testVector : testVectors) {
+ Uri::Uri uri;
+ ASSERT_FALSE(uri.ParseFromString(testVector)) << index;
+ ++index;
+ }
+}
+
+TEST(UriTests, ParseFromStringHostBarelyLegal) {
+ struct TestVector {
+ std::string uriString;
+ std::string host;
+ };
+ const std::vector< TestVector > testVectors{
+ {"//%41/", "A"},
+ {"///", ""},
+ {"//!/", "!"},
+ {"//'/", "'"},
+ {"//(/", "("},
+ {"//;/", ";"},
+ {"//1.2.3.4/", "1.2.3.4"},
+ {"//[v7.:]/", "[v7.:]"},
+ };
+ size_t index = 0;
+ for (const auto& testVector : testVectors) {
+ Uri::Uri uri;
+ ASSERT_TRUE(uri.ParseFromString(testVector.uriString)) << index;
+ ASSERT_EQ(testVector.host, uri.GetHost());
+ ++index;
+ }
+}
+
TEST(UriTests, ParseFromStringDontMisinterpretColonInAuthorityAsSchemeDelimiter) {
const std::vector< std::string > testVectors{
{"//foo:bar@www.example.com/"},