From 9a3d6880e844231404a4cfafe4e0349798eaacad Mon Sep 17 00:00:00 2001 From: Vincent Richard Date: Fri, 10 Feb 2017 21:20:22 +0100 Subject: Fixed issue #160: invalid characters in hostname. --- tests/utility/stringUtilsTest.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'tests') diff --git a/tests/utility/stringUtilsTest.cpp b/tests/utility/stringUtilsTest.cpp index a21c2742..d86bbda0 100644 --- a/tests/utility/stringUtilsTest.cpp +++ b/tests/utility/stringUtilsTest.cpp @@ -43,6 +43,9 @@ VMIME_TEST_SUITE_BEGIN(stringUtilsTest) VMIME_TEST(testCountASCIIChars) VMIME_TEST(testUnquote) + + VMIME_TEST(testIsValidHostname) + VMIME_TEST(testIsValidFQDN) VMIME_TEST_LIST_END @@ -160,5 +163,30 @@ VMIME_TEST_SUITE_BEGIN(stringUtilsTest) VASSERT_EQ("4", "quoted with \"escape\"", stringUtils::unquote("\"quoted with \\\"escape\\\"\"")); // "quoted with \"escape\"" } + void testIsValidHostname() + { + VASSERT_TRUE ("1", stringUtils::isValidHostname("localhost")); + VASSERT_TRUE ("2", stringUtils::isValidHostname("localhost.localdomain")); + VASSERT_TRUE ("3", stringUtils::isValidHostname("example.com")); + VASSERT_TRUE ("4", stringUtils::isValidHostname("host.example.com")); + VASSERT_FALSE("5", stringUtils::isValidHostname(".example.com")); + VASSERT_FALSE("6", stringUtils::isValidHostname(".-example.com")); + VASSERT_FALSE("7", stringUtils::isValidHostname(".example-.com")); + VASSERT_FALSE("8", stringUtils::isValidHostname(".exa--mple.com")); + VASSERT_FALSE("9", stringUtils::isValidHostname("-example.com")); + } + + void testIsValidFQDN() + { + VASSERT_FALSE("1", stringUtils::isValidFQDN("localhost")); + VASSERT_FALSE("2", stringUtils::isValidFQDN("localhost.localdomain")); + VASSERT_FALSE("3", stringUtils::isValidFQDN("example.com")); + VASSERT_TRUE ("4", stringUtils::isValidFQDN("host.example.com")); + VASSERT_FALSE("5", stringUtils::isValidFQDN(".example.com")); + VASSERT_FALSE("6", stringUtils::isValidFQDN(".-example.com")); + VASSERT_FALSE("7", stringUtils::isValidFQDN(".example-.com")); + VASSERT_FALSE("8", stringUtils::isValidFQDN(".exa--mple.com")); + } + VMIME_TEST_SUITE_END -- cgit v1.2.3