[tests] mv tests from request.t to test_request.c

move some tests from tests/*.t to src/t/test_request.c
master
Glenn Strauss 2 years ago
parent d4f43f7e1b
commit a0a8cf821d

@ -311,6 +311,12 @@ static void test_request_http_request_parse(request_st * const r)
CONST_STR_LEN("GET HTTP/1.0\r\n"
"\r\n"));
run_http_request_parse(r, __LINE__, 0,
"URL-decode request-URI",
CONST_STR_LEN("GET /index%2ehtml HTTP/1.0\r\n"
"\r\n"));
assert(buffer_eq_slen(&r->uri.path, CONST_STR_LEN("/index.html")));
run_http_request_parse(r, __LINE__, 0,
"#1232 - duplicate headers with line-wrapping",
CONST_STR_LEN("GET / HTTP/1.0\r\n"
@ -544,6 +550,42 @@ static void test_request_http_request_parse(request_st * const r)
"Connection: close\r\n"
"\r\n"));
run_http_request_parse(r, __LINE__, 0,
"ignore duplicated If-Modified-Since if matching",
CONST_STR_LEN("GET / HTTP/1.1\r\n"
"Host: zzz.example.org\r\n"
"If-Modified-Since: Sun, 01 Jan 2036 00:00:02 GMT\r\n"
"If-Modified-Since: Sun, 01 Jan 2036 00:00:02 GMT\r\n"
"Connection: close\r\n"
"\r\n"));
b = http_header_request_get(r, HTTP_HEADER_IF_MODIFIED_SINCE,
CONST_STR_LEN("If-Modified-Since"));
assert(b && buffer_eq_slen(b,
CONST_STR_LEN("Sun, 01 Jan 2036 00:00:02 GMT")));
run_http_request_parse(r, __LINE__, 400,
"reject duplicated If-Modified-Since if not matching",
CONST_STR_LEN("GET / HTTP/1.1\r\n"
"Host: zzz.example.org\r\n"
"If-Modified-Since: Sun, 01 Jan 2036 00:00:02 GMT\r\n"
"If-Modified-Since: Sun, 01 Jan 2036 00:00:03 GMT\r\n"
"Connection: close\r\n"
"\r\n"));
run_http_request_parse(r, __LINE__, 0,
"large headers", /*(copied from tests/request.t)*/
CONST_STR_LEN("GET / HTTP/1.0\r\n"
"Hsgfsdjf: asdfhdf\r\n"
"hdhd: shdfhfdasd\r\n"
"hfhr: jfghsdfg\r\n"
"jfuuehdmn: sfdgjfdg\r\n"
"jvcbzufdg: sgfdfg\r\n"
"hrnvcnd: jfjdfg\r\n"
"jfusfdngmd: gfjgfdusdfg\r\n"
"nfj: jgfdjdfg\r\n"
"jfue: jfdfdg\r\n"
"\r\n"));
/* (quick check that none of above tests were left in a state
* which resulted in subsequent tests returning 400 for other
* reasons) */

@ -8,7 +8,7 @@ BEGIN {
use strict;
use IO::Socket;
use Test::More tests => 12;
use Test::More tests => 11;
use LightyTest;
my $tf = LightyTest->new();
@ -43,13 +43,6 @@ ok($tf->handle_http($t) == 0, 'OPTIONS');
## Low-Level Request-Header Parsing - URI
$t->{REQUEST} = ( <<EOF
GET /index%2ehtml HTTP/1.0
EOF
);
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
ok($tf->handle_http($t) == 0, 'URL-encoding');
$t->{REQUEST} = ( <<EOF
GET /index.html%00 HTTP/1.0
EOF

@ -8,7 +8,7 @@ BEGIN {
use strict;
use IO::Socket;
use Test::More tests => 14;
use Test::More tests => 13;
use LightyTest;
my $tf = LightyTest->new();
@ -27,13 +27,6 @@ EOF
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 200, '+Date' => '' } ];
ok($tf->handle_http($t) == 0, 'Date header');
$t->{REQUEST} = ( <<EOF
GET / HTTP/1.1
EOF
);
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 400, 'Connection' => 'close' } ];
ok($tf->handle_http($t) == 0, 'Host missing');
$t->{REQUEST} = ( <<EOF
GET / HTTP/1.0
EOF

@ -8,7 +8,7 @@ BEGIN {
use strict;
use IO::Socket;
use Test::More tests => 54;
use Test::More tests => 52;
use LightyTest;
my $tf = LightyTest->new();
@ -393,23 +393,6 @@ EOF
ok($tf->handle_http($t) == 0, 'GET, Range start out of range');
$t->{REQUEST} = ( <<EOF
GET / HTTP/1.0
Hsgfsdjf: asdfhdf
hdhd: shdfhfdasd
hfhr: jfghsdfg
jfuuehdmn: sfdgjfdg
jvcbzufdg: sgfdfg
hrnvcnd: jfjdfg
jfusfdngmd: gfjgfdusdfg
nfj: jgfdjdfg
jfue: jfdfdg
EOF
);
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
ok($tf->handle_http($t) == 0, 'larger headers');
$t->{REQUEST} = ( <<EOF
GET /range.pdf HTTP/1.1
Host: 123.example.org
@ -462,15 +445,6 @@ ok($tf->handle_http($t) == 0, 'OPTIONS for RTSP');
my $nextyr = (gmtime(time()))[5] + 1900 + 1;
$t->{REQUEST} = ( <<EOF
GET /index.html HTTP/1.0
If-Modified-Since: Sun, 01 Jan $nextyr 00:00:02 GMT
If-Modified-Since: Sun, 01 Jan $nextyr 00:00:02 GMT
EOF
);
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304 } ];
ok($tf->handle_http($t) == 0, 'Duplicate If-Mod-Since, with equal timestamps');
$t->{REQUEST} = ( "GET / HTTP/1.0\r\nIf-Modified-Since: \r\n\r\n" );
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
ok($tf->handle_http($t) == 0, 'empty If-Modified-Since');

Loading…
Cancel
Save