diff options
author | rl1987 <rl1987@sdf.lonestar.org> | 2014-10-12 20:39:00 +0300 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2014-11-04 00:36:37 -0500 |
commit | e8e45ff13ed86d8851bab77d65d899d0ca6e3b89 (patch) | |
tree | 08b48055e4ba8d1dd79cbb42324d7de6216a6a18 /src/test/test_util.c | |
parent | 1ea9a6fd72b66ec634446cbd2119641a5ed1e703 (diff) | |
download | tor-e8e45ff13ed86d8851bab77d65d899d0ca6e3b89.tar.gz tor-e8e45ff13ed86d8851bab77d65d899d0ca6e3b89.zip |
Introducing helper function to validate IPv4 address strings.
Diffstat (limited to 'src/test/test_util.c')
-rw-r--r-- | src/test/test_util.c | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/test/test_util.c b/src/test/test_util.c index fb3ce7d941..fba90da492 100644 --- a/src/test/test_util.c +++ b/src/test/test_util.c @@ -4138,9 +4138,9 @@ test_util_hostname_validation(void *arg) tt_assert(!string_is_valid_hostname("-torproject.org")); tt_assert(!string_is_valid_hostname("subdomain.-domain.org")); tt_assert(!string_is_valid_hostname("-subdomain.domain.org")); - + // Hostnames cannot contain non-alphanumeric characters. - tt_assert(!string_is_valid_hostname("%%domain.\\org.")); + tt_assert(!string_is_valid_hostname("%%domain.\\org.")); tt_assert(!string_is_valid_hostname("***x.net")); tt_assert(!string_is_valid_hostname("___abc.org")); tt_assert(!string_is_valid_hostname("\xff\xffxyz.org")); @@ -4152,6 +4152,22 @@ test_util_hostname_validation(void *arg) return; } +static void +test_util_ipv4_validation(void *arg) +{ + (void)arg; + + tt_assert(string_is_valid_ipv4_address("192.168.0.1")); + tt_assert(string_is_valid_ipv4_address("8.8.8.8")); + + tt_assert(!string_is_valid_ipv4_address("abcd")); + tt_assert(!string_is_valid_ipv4_address("300.300.300.300")); + tt_assert(!string_is_valid_ipv4_address("8.8.")); + + done: + return; +} + struct testcase_t util_tests[] = { UTIL_LEGACY(time), UTIL_TEST(parse_http_time, 0), @@ -4225,6 +4241,7 @@ struct testcase_t util_tests[] = { &socketpair_setup, (void*)"1" }, UTIL_TEST(max_mem, 0), UTIL_TEST(hostname_validation, 0), + UTIL_TEST(ipv4_validation, 0), END_OF_TESTCASES }; |