diff options
author | Kevin Butler <haqkrs@gmail.com> | 2013-09-03 01:14:43 +0100 |
---|---|---|
committer | Kevin Butler <haqkrs@gmail.com> | 2013-09-03 01:14:43 +0100 |
commit | 5327605caa5863ec9593fd0899425cd971a9d525 (patch) | |
tree | beda4e3d2f8aebd32716ab6fc0e9862b1d1d04a6 /src/test/test_dir.c | |
parent | 00bcc25d05dc0273323a2cae20c6aa62afd4b50a (diff) | |
download | tor-5327605caa5863ec9593fd0899425cd971a9d525.tar.gz tor-5327605caa5863ec9593fd0899425cd971a9d525.zip |
Tougher validation for parsing urls from HTTP headers. Fixes #2767.
Diffstat (limited to 'src/test/test_dir.c')
-rw-r--r-- | src/test/test_dir.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/test/test_dir.c b/src/test/test_dir.c index 6c2915d094..05e13b5741 100644 --- a/src/test/test_dir.c +++ b/src/test/test_dir.c @@ -2364,6 +2364,45 @@ test_dir_fmt_control_ns(void *arg) tor_free(s); } +static void +test_dir_http_handling(void *args) +{ + (void)args; + char *url = NULL; + + /* Parse http url tests: */ + /* Good headers */ + test_eq(parse_http_url("GET /tor/a/b/c.txt HTTP/1.1\r\n" + "Host: example.com\r\n" + "User-Agent: Mozilla/5.0 (Windows;" + " U; Windows NT 6.1; en-US; rv:1.9.1.5)\r\n", + &url), 0); + test_streq(url, "/tor/a/b/c.txt"); + tor_free(url); + + /* Should prepends '/tor/' to url if required */ + test_eq(parse_http_url("GET /a/b/c.txt HTTP/1.1\r\n" + "Host: example.com\r\n" + "User-Agent: Mozilla/5.0 (Windows;" + " U; Windows NT 6.1; en-US; rv:1.9.1.5)\r\n", + &url), 0); + test_streq(url, "/tor/a/b/c.txt"); + tor_free(url); + + /* Bad headers */ + test_eq(parse_http_url("GET /a/b/c.txt\r\n" + "Host: example.com\r\n" + "User-Agent: Mozilla/5.0 (Windows;" + " U; Windows NT 6.1; en-US; rv:1.9.1.5)\r\n", + &url), -1); + tt_assert(!url); + + /* TODO: more http handling tests */ + + done: + ; +} + #define DIR_LEGACY(name) \ { #name, legacy_test_helper, TT_FORK, &legacy_setup, test_dir_ ## name } @@ -2386,6 +2425,7 @@ struct testcase_t dir_tests[] = { DIR_LEGACY(clip_unmeasured_bw_kb_alt), DIR(v2_dir, TT_FORK), DIR(fmt_control_ns, 0), + DIR(http_handling, 0), END_OF_TESTCASES }; |