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 $tf->{CONFIGFILE
} = 'condition.conf';
18 ok
($tf->start_proc == 0, "Starting lighttpd") or die();
20 $t->{REQUEST
} = ( <<EOF
21 GET /index.html HTTP/1.0
25 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => "/match_1" } ];
26 ok
($tf->handle_http($t) == 0, 'config deny');
28 $t->{REQUEST
} = ( <<EOF
29 GET /index.html HTTP/1.0
30 Host: test1.example.org
33 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => "/match_2" } ];
34 ok
($tf->handle_http($t) == 0, '2nd child of chaining');
36 $t->{REQUEST
} = ( <<EOF
37 GET /index.html HTTP/1.0
38 Host: test2.example.org
41 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => "/match_3" } ];
42 ok
($tf->handle_http($t) == 0, '3rd child of chaining');
44 $t->{REQUEST
} = ( <<EOF
45 GET /index.html HTTP/1.0
46 Host: test3.example.org
49 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => "/match_5" } ];
50 ok
($tf->handle_http($t) == 0, 'nesting');
52 $t->{REQUEST
} = ( <<EOF
53 GET /subdir/index.html HTTP/1.0
54 Host: test4.example.org
57 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => "/match_7" } ];
58 ok
($tf->handle_http($t) == 0, 'url subdir');
60 $t->{REQUEST
} = ( <<EOF
61 GET /subdir/../css/index.html HTTP/1.0
62 Host: test4.example.org
65 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => "/match_6" } ];
66 ok
($tf->handle_http($t) == 0, 'url subdir with path traversal');
68 $t->{REQUEST
} = ( <<EOF
72 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Server' => 'Apache 1.3.29' } ];
73 ok
($tf->handle_http($t) == 0, 'condition: handle if before else branches');
75 $t->{REQUEST
} = ( <<EOF
76 GET /show/other/server-tag HTTP/1.0
79 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Server' => 'special tag' } ];
80 ok
($tf->handle_http($t) == 0, 'condition: handle if before else branches #2');
82 ok
($tf->stop_proc == 0, "Stopping lighttpd");
84 $tf->{CONFIGFILE
} = 'lighttpd.conf';
85 ok
($tf->start_proc == 0, "Starting lighttpd") or die();
87 $t->{REQUEST
} = ( <<EOF
88 GET /nofile.png HTTP/1.0
89 Host: referer.example.org
92 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ];
93 ok
($tf->handle_http($t) == 0, 'condition: Referer - no referer');
95 $t->{REQUEST
} = ( <<EOF
96 GET /nofile.png HTTP/1.0
97 Host: referer.example.org
98 Referer: http://referer.example.org/
101 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ];
102 ok
($tf->handle_http($t) == 0, 'condition: Referer - referer matches regex');
104 $t->{REQUEST
} = ( <<EOF
105 GET /image.jpg HTTP/1.0
106 Host: www.example.org
109 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
110 ok
($tf->handle_http($t) == 0, 'condition: Referer - no referer');
112 $t->{REQUEST
} = ( <<EOF
113 GET /image.jpg HTTP/1.0
114 Host: www.example.org
115 Referer: http://referer.example.org/
118 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
119 ok
($tf->handle_http($t) == 0, 'condition: Referer - referer matches regex');
121 $t->{REQUEST
} = ( <<EOF
122 GET /image.jpg HTTP/1.0
123 Host: www.example.org
124 Referer: http://evil-referer.example.org/
127 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 403 } ];
128 ok
($tf->handle_http($t) == 0, 'condition: Referer - referer doesn\'t match');
130 $t->{REQUEST
} = ( <<EOF
132 Host: bug255.example.org
135 Host: bug255.example.org
139 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 403 }, { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 403 } ];
140 ok
($tf->handle_http($t) == 0, 'remote ip cache (#255)');
142 $t->{REQUEST
} = ( <<EOF
143 GET /empty-ref.noref HTTP/1.0
147 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 403 } ];
148 ok
($tf->handle_http($t) == 0, 'condition: $HTTP["referer"] == "" and Referer is no set');
150 $t->{REQUEST
} = ( <<EOF
151 GET /empty-ref.noref HTTP/1.0
156 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 403 } ];
157 ok
($tf->handle_http($t) == 0, 'condition: $HTTP["referer"] == "" and Referer is empty');
159 $t->{REQUEST
} = ( <<EOF
160 GET /empty-ref.noref HTTP/1.0
165 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ];
166 ok
($tf->handle_http($t) == 0, 'condition: $HTTP["referer"] == "" and Referer: foobar');
168 ok
($tf->stop_proc == 0, "Stopping lighttpd");