3 # add current source dir to the include-path
4 # we need this for make distcheck
5 (my $srcdir = $0) =~ s
,/[^/]+$,/,;
11 use Test
::More tests
=> 21;
14 my $tf = LightyTest
->new();
17 ok
($tf->start_proc == 0, "Starting lighttpd") or die();
19 $t->{REQUEST
} = ( <<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
30 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
31 ok
($tf->handle_http($t) == 0, 'missing Protocol');
33 $t->{REQUEST
} = ( <<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
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
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
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
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
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
81 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 501 } ];
82 ok
($tf->handle_http($t) == 0, 'unknown method');
84 $t->{REQUEST
} = ( <<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
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
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
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
120 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
121 ok
($tf->handle_http($t) == 0, 'no whitespace');
123 $t->{REQUEST
} = ( <<EOF
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
151 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
152 ok
($tf->handle_http($t) == 0, 'OPTIONS');
154 $t->{REQUEST
} = ( <<EOF
156 Host: www.example.org
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");