drain backend socket/pipe bufs upon FDEVENT_HUP
[lighttpd.git] / tests / core.t
blobb196666a2de7a0117419f8b3624f95ae85f75462
1 #!/usr/bin/env perl
2 BEGIN {
3 # add current source dir to the include-path
4 # we need this for make distcheck
5 (my $srcdir = $0) =~ s,/[^/]+$,/,;
6 unshift @INC, $srcdir;
9 use strict;
10 use IO::Socket;
11 use Test::More tests => 21;
12 use LightyTest;
14 my $tf = LightyTest->new();
15 my $t;
17 ok($tf->start_proc == 0, "Starting lighttpd") or die();
19 $t->{REQUEST} = ( <<EOF
20 GET / HTTP/1.0
21 EOF
23 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
24 ok($tf->handle_http($t) == 0, 'Valid HTTP/1.0 Request') or die();
26 $t->{REQUEST} = ( <<EOF
27 GET /
28 EOF
30 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
31 ok($tf->handle_http($t) == 0, 'missing Protocol');
33 $t->{REQUEST} = ( <<EOF
34 GET / HTTP/01.01
35 Host: foo
36 Connection: close
37 EOF
39 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 200 } ];
40 ok($tf->handle_http($t) == 0, 'zeros in protocol version');
42 $t->{REQUEST} = ( <<EOF
43 GET / HTTP/.01
44 EOF
46 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
47 ok($tf->handle_http($t) == 0, 'missing major version');
49 $t->{REQUEST} = ( <<EOF
50 GET / HTTP/01.
51 EOF
53 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
54 ok($tf->handle_http($t) == 0, 'missing minor version');
56 $t->{REQUEST} = ( <<EOF
57 GET / HTTP/a.b
58 EOF
60 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
61 ok($tf->handle_http($t) == 0, 'strings as version');
63 $t->{REQUEST} = ( <<EOF
64 BC /
65 EOF
67 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
68 ok($tf->handle_http($t) == 0, 'missing protocol + unknown method');
70 $t->{REQUEST} = ( <<EOF
71 ABC
72 EOF
74 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
75 ok($tf->handle_http($t) == 0, 'missing protocol + unknown method + missing URI');
77 $t->{REQUEST} = ( <<EOF
78 ABC / HTTP/1.0
79 EOF
81 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 501 } ];
82 ok($tf->handle_http($t) == 0, 'unknown method');
84 $t->{REQUEST} = ( <<EOF
85 GET / HTTP/1.3
86 EOF
88 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 505 } ];
89 ok($tf->handle_http($t) == 0, 'unknown protocol');
91 $t->{REQUEST} = ( <<EOF
92 GET http://www.example.org/ HTTP/1.0
93 EOF
95 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
96 ok($tf->handle_http($t) == 0, 'absolute URI');
98 print "\nLow-Level Request-Header Parsing\n";
99 $t->{REQUEST} = ( <<EOF
100 GET / HTTP/1.0
101 ABC : foo
104 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
105 ok($tf->handle_http($t) == 0, 'whitespace after key');
107 $t->{REQUEST} = ( <<EOF
108 GET / HTTP/1.0
109 ABC a: foo
112 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
113 ok($tf->handle_http($t) == 0, 'whitespace with-in key');
115 $t->{REQUEST} = ( <<EOF
116 GET / HTTP/1.0
117 ABC:foo
120 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
121 ok($tf->handle_http($t) == 0, 'no whitespace');
123 $t->{REQUEST} = ( <<EOF
124 GET / HTTP/1.0
125 ABC:foo
129 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
130 ok($tf->handle_http($t) == 0, 'line-folding');
132 print "\nLow-Level Request-Header Parsing - URI\n";
133 $t->{REQUEST} = ( <<EOF
134 GET /index%2ehtml HTTP/1.0
137 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
138 ok($tf->handle_http($t) == 0, 'URL-encoding');
140 $t->{REQUEST} = ( <<EOF
141 GET /index.html%00 HTTP/1.0
144 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ];
145 ok($tf->handle_http($t) == 0, 'URL-encoding, %00');
147 $t->{REQUEST} = ( <<EOF
148 OPTIONS * HTTP/1.0
151 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
152 ok($tf->handle_http($t) == 0, 'OPTIONS');
154 $t->{REQUEST} = ( <<EOF
155 OPTIONS / HTTP/1.1
156 Host: www.example.org
157 Connection: close
160 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 200 } ];
161 ok($tf->handle_http($t) == 0, 'OPTIONS');
165 ok($tf->stop_proc == 0, "Stopping lighttpd");