diff options
author | rl1987 <rl1987@sdf.lonestar.org> | 2014-10-12 19:33:08 +0300 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2014-11-04 00:35:43 -0500 |
commit | 1ea9a6fd72b66ec634446cbd2119641a5ed1e703 (patch) | |
tree | 5f8ab6a546218e39d4843e954452e79d428a10c4 /src/test/test_util.c | |
parent | f94e5f2e5212034cb8b2666716eeaa61e874065b (diff) | |
download | tor-1ea9a6fd72b66ec634446cbd2119641a5ed1e703.tar.gz tor-1ea9a6fd72b66ec634446cbd2119641a5ed1e703.zip |
Introducing helper function to validate DNS name strings.
Diffstat (limited to 'src/test/test_util.c')
-rw-r--r-- | src/test/test_util.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/test/test_util.c b/src/test/test_util.c index c67aa71b02..fb3ce7d941 100644 --- a/src/test/test_util.c +++ b/src/test/test_util.c @@ -4122,6 +4122,36 @@ test_util_max_mem(void *arg) ; } +static void +test_util_hostname_validation(void *arg) +{ + (void)arg; + + // Lets try valid hostnames first. + tt_assert(string_is_valid_hostname("torproject.org")); + tt_assert(string_is_valid_hostname("ocw.mit.edu")); + tt_assert(string_is_valid_hostname("i.4cdn.org")); + tt_assert(string_is_valid_hostname("stanford.edu")); + tt_assert(string_is_valid_hostname("multiple-words-with-hypens.jp")); + + // Subdomain name cannot start with '-'. + 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("***x.net")); + tt_assert(!string_is_valid_hostname("___abc.org")); + tt_assert(!string_is_valid_hostname("\xff\xffxyz.org")); + tt_assert(!string_is_valid_hostname("word1 word2.net")); + + // XXX: do we allow single-label DNS names? + + done: + return; +} + struct testcase_t util_tests[] = { UTIL_LEGACY(time), UTIL_TEST(parse_http_time, 0), @@ -4194,6 +4224,7 @@ struct testcase_t util_tests[] = { { "socketpair_ersatz", test_util_socketpair, TT_FORK, &socketpair_setup, (void*)"1" }, UTIL_TEST(max_mem, 0), + UTIL_TEST(hostname_validation, 0), END_OF_TESTCASES }; |