From da75a62a328f854eee86ed305b5e0c08e299f266 Mon Sep 17 00:00:00 2001 From: Sergey Lyubka Date: Fri, 27 Jul 2012 06:24:11 +0100 Subject: [PATCH] More tests --- test/env.cgi | 6 +----- test/test.pl | 5 +++++ test/unit_test.c | 11 +++++++++++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/test/env.cgi b/test/env.cgi index cb60dc3b..479e1fd3 100755 --- a/test/env.cgi +++ b/test/env.cgi @@ -21,8 +21,6 @@ foreach my $key (sort keys %in) { print "\n"; -#sleep 10; - print 'CURRENT_DIR=' . getcwd() . "\n"; print "\n"; @@ -43,8 +41,6 @@ my $stuff = < EOP -system('some shit'); - -#print STDERR "fuck!!!\n\n"; +#system('some shit'); print $stuff; diff --git a/test/test.pl b/test/test.pl index 3e56eac0..16dd8b70 100644 --- a/test/test.pl +++ b/test/test.pl @@ -339,6 +339,11 @@ unless (scalar(@ARGV) > 0 and $ARGV[0] eq "basic_tests") { o("GET /hello.txt HTTP/1.0\nAuthorization: $auth_header\n\n", 'HTTP/1.1 200 OK', 'GET regular file with auth'); unlink "$root/.htpasswd"; + my $x = 'x=' . 'A' x (200 * 1024); + my $len = length($x); + o("POST /env.cgi HTTP/1.0\r\nContent-Length: $len\r\n\r\n$x", + '^HTTP/1.1 200 OK', 'Long POST'); + o("GET /env.cgi HTTP/1.0\n\r\n", 'HTTP/1.1 200 OK', 'GET CGI file'); o("GET /bad2.cgi HTTP/1.0\n\n", "HTTP/1.1 123 Please pass me to the client\r", 'CGI Status code text'); diff --git a/test/unit_test.c b/test/unit_test.c index bace953b..f6b80c52 100644 --- a/test/unit_test.c +++ b/test/unit_test.c @@ -11,6 +11,7 @@ static void test_parse_http_request() { char req1[] = "GET / HTTP/1.1\r\n\r\n"; char req2[] = "BLAH / HTTP/1.1\r\n\r\n"; char req3[] = "GET / HTTP/1.1\r\nBah\r\n"; + char req4[] = "GET / HTTP/1.1\r\nA: foo bar\r\nB: bar\r\nbaz\r\n\r\n"; ASSERT(parse_http_request(req1, &ri) == 1); ASSERT(strcmp(ri.http_version, "1.1") == 0); @@ -23,6 +24,16 @@ static void test_parse_http_request() { ASSERT(ri.num_headers == 1); ASSERT(strcmp(ri.http_headers[0].name, "Bah\r\n") == 0); + // TODO(lsm): Fix this. Header value may span multiple lines. + ASSERT(parse_http_request(req4, &ri) == 1); + ASSERT(ri.num_headers == 3); + ASSERT(strcmp(ri.http_headers[0].name, "A") == 0); + ASSERT(strcmp(ri.http_headers[0].value, "foo bar") == 0); + ASSERT(strcmp(ri.http_headers[1].name, "B") == 0); + ASSERT(strcmp(ri.http_headers[1].value, "bar") == 0); + ASSERT(strcmp(ri.http_headers[2].name, "baz\r\n\r\n") == 0); + ASSERT(strcmp(ri.http_headers[2].value, "") == 0); + // TODO(lsm): add more tests. }