diff options
author | Nick Mathewson <nickm@torproject.org> | 2013-09-03 11:37:04 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2013-09-03 11:38:15 -0400 |
commit | 270b4f030a07a0ff3ad80e4ae5495ad89b4096ef (patch) | |
tree | 795d5af274317b57a954a64b320b71226f9f1862 /src/test/test_dir.c | |
parent | 5327605caa5863ec9593fd0899425cd971a9d525 (diff) | |
download | tor-270b4f030a07a0ff3ad80e4ae5495ad89b4096ef.tar.gz tor-270b4f030a07a0ff3ad80e4ae5495ad89b4096ef.zip |
Handle HTTP minor versions greater than 9
(In practice they don't exist, but so long as we're making changes for
standards compliance...)
Also add several more unit tests for good and bad URL types.
Diffstat (limited to 'src/test/test_dir.c')
-rw-r--r-- | src/test/test_dir.c | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/src/test/test_dir.c b/src/test/test_dir.c index 05e13b5741..0292cbd667 100644 --- a/src/test/test_dir.c +++ b/src/test/test_dir.c @@ -2380,7 +2380,15 @@ test_dir_http_handling(void *args) test_streq(url, "/tor/a/b/c.txt"); tor_free(url); - /* Should prepends '/tor/' to url if required */ + test_eq(parse_http_url("GET /tor/a/b/c.txt HTTP/1.0\r\n", &url), 0); + test_streq(url, "/tor/a/b/c.txt"); + tor_free(url); + + test_eq(parse_http_url("GET /tor/a/b/c.txt HTTP/1.600\r\n", &url), 0); + test_streq(url, "/tor/a/b/c.txt"); + tor_free(url); + + /* Should prepend '/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;" @@ -2389,6 +2397,14 @@ test_dir_http_handling(void *args) test_streq(url, "/tor/a/b/c.txt"); tor_free(url); + /* Bad headers -- no HTTP/1.x*/ + 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); + /* Bad headers */ test_eq(parse_http_url("GET /a/b/c.txt\r\n" "Host: example.com\r\n" @@ -2397,10 +2413,23 @@ test_dir_http_handling(void *args) &url), -1); tt_assert(!url); - /* TODO: more http handling tests */ + test_eq(parse_http_url("GET /tor/a/b/c.txt", &url), -1); + tt_assert(!url); + + test_eq(parse_http_url("GET /tor/a/b/c.txt HTTP/1.1", &url), -1); + tt_assert(!url); + + test_eq(parse_http_url("GET /tor/a/b/c.txt HTTP/1.1x\r\n", &url), -1); + tt_assert(!url); + + test_eq(parse_http_url("GET /tor/a/b/c.txt HTTP/1.", &url), -1); + tt_assert(!url); + + test_eq(parse_http_url("GET /tor/a/b/c.txt HTTP/1.\r", &url), -1); + tt_assert(!url); - done: - ; + done: + tor_free(url); } #define DIR_LEGACY(name) \ |