1#!/usr/bin/env perl
2#
3# combinations we have to test:
4# plain 404 case
5# 404-handler -> static file (verify content)
6# 404-handler -> fastcgi
7#   returning 200
8#   returning 302 + Location
9#   returning 404
10#   returning no status -> 200
11#
12BEGIN {
13	# add current source dir to the include-path
14	# we need this for make distcheck
15	(my $srcdir = $0) =~ s,/[^/]+$,/,;
16	unshift @INC, $srcdir;
17}
18
19use strict;
20use IO::Socket;
21use Test::More tests => 8;
22use LightyTest;
23
24my $tf = LightyTest->new();
25my $t;
26$tf->{CONFIGFILE} = '404-handler.conf';
27
28ok($tf->start_proc == 0, "Starting lighttpd") or die();
29
30$t->{REQUEST}  = ( <<EOF
31GET /static/notfound HTTP/1.0
32EOF
33 );
34$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => "static not found\n" } ];
35ok($tf->handle_http($t) == 0, '404 handler => static');
36
37#
38#
39#
40$t->{REQUEST}  = ( <<EOF
41GET /dynamic/200/notfound HTTP/1.0
42EOF
43 );
44$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => "found here\n" } ];
45ok($tf->handle_http($t) == 0, '404 handler => dynamic(200)');
46
47$t->{REQUEST}  = ( <<EOF
48GET /dynamic/302/notfound HTTP/1.0
49EOF
50 );
51$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 302, 'Location' => "http://www.example.org/" } ];
52ok($tf->handle_http($t) == 0, '404 handler => dynamic(302)');
53
54$t->{REQUEST}  = ( <<EOF
55GET /dynamic/404/notfound HTTP/1.0
56EOF
57 );
58$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404, 'HTTP-Content' => "Not found here\n" } ];
59ok($tf->handle_http($t) == 0, '404 handler => dynamic(404)');
60
61$t->{REQUEST}  = ( <<EOF
62GET /dynamic/nostatus/notfound HTTP/1.0
63EOF
64 );
65$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => "found here\n" } ];
66ok($tf->handle_http($t) == 0, '404 handler => dynamic(nostatus)');
67
68$t->{REQUEST}  = ( <<EOF
69GET /send404.pl HTTP/1.0
70EOF
71 );
72$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404, 'HTTP-Content' => "send404\n" } ];
73ok($tf->handle_http($t) == 0, '404 generated by CGI should stay 404');
74
75ok($tf->stop_proc == 0, "Stopping lighttpd");
76
77