diff --git a/src/aws-cpp-sdk-core/source/utils/DNS.cpp b/src/aws-cpp-sdk-core/source/utils/DNS.cpp index ce588150e2f..50a2e0610ef 100644 --- a/src/aws-cpp-sdk-core/source/utils/DNS.cpp +++ b/src/aws-cpp-sdk-core/source/utils/DNS.cpp @@ -5,6 +5,7 @@ #include #include +#include namespace Aws { @@ -49,7 +50,7 @@ namespace Aws return false; } - return !std::any_of(labels.begin(), labels.end(), [](const Aws::String& label){ return !IsValidDnsLabel(label); }); + return !std::any_of(labels.begin(), labels.end(), [](const Aws::String& label){ return !IsValidDnsLabel(label); }) || aws_host_utils_is_ipv6(aws_byte_cursor_from_c_str(host.c_str()), false); } } } diff --git a/tests/aws-cpp-sdk-core-tests/utils/DNSTest.cpp b/tests/aws-cpp-sdk-core-tests/utils/DNSTest.cpp index f35429211c0..5a3d0ef9e16 100644 --- a/tests/aws-cpp-sdk-core-tests/utils/DNSTest.cpp +++ b/tests/aws-cpp-sdk-core-tests/utils/DNSTest.cpp @@ -61,3 +61,29 @@ TEST_F(DnsTest, TestHost) ASSERT_FALSE(IsValidHost("0123456789012345678901234567890123456789012345678901234567890123.com")); // 64 characters } + +TEST_F(DnsTest, TestIPV6) +{ + Aws::Vector< std::pair > inputs = { + {"2001:0db8:85a3:0000:0000:8a2e:0370:7334", true}, + {"2001:DB8:85A3::8A2E:370:7334", true}, + {"::ffff", true}, + {"::", true}, + {"ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff",true}, + {"2001:db8:85a3:0:0:8a2e:370:7334",true}, + {"2001:db8:85a3:0000:0000:8a2e:0370:7334:1", false}, + {"2001:db8:85a3:0000", false}, + {"2001:0db8:85a3:0000:0000:8a2e:0370:7334:", false}, + {"g001:0db8:85a3:0000:0000:8a2e:0370:7334", false}, + {"2001:db8::85a3::1", false}, + {":2001:db8:85a3:0000:0000:8a2e:0370:7334", false}, + {"0:0:0:0:0:0:0:0", true}, + {"2001:db8::", true} + }; + + for(auto t : inputs) + { + ASSERT_EQ(IsValidHost(t.first), t.second); + } + +} \ No newline at end of file