2005-09-01 11:44:57 +00:00
|
|
|
#!/usr/bin/env perl
|
2005-08-08 13:48:33 +00:00
|
|
|
BEGIN {
|
2008-01-15 22:03:59 +00:00
|
|
|
# add current source dir to the include-path
|
|
|
|
# we need this for make distcheck
|
|
|
|
(my $srcdir = $0) =~ s,/[^/]+$,/,;
|
|
|
|
unshift @INC, $srcdir;
|
2005-08-08 13:48:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use IO::Socket;
|
2011-02-10 07:56:11 +00:00
|
|
|
use Test::More tests => 19;
|
2005-08-08 13:48:33 +00:00
|
|
|
use LightyTest;
|
|
|
|
|
|
|
|
my $tf = LightyTest->new();
|
|
|
|
my $t;
|
|
|
|
|
|
|
|
$tf->{CONFIGFILE} = 'condition.conf';
|
|
|
|
ok($tf->start_proc == 0, "Starting lighttpd") or die();
|
|
|
|
|
|
|
|
$t->{REQUEST} = ( <<EOF
|
|
|
|
GET /index.html HTTP/1.0
|
|
|
|
Host: www.example.org
|
|
|
|
EOF
|
|
|
|
);
|
2005-08-31 12:55:44 +00:00
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => "/match_1" } ];
|
2005-08-08 13:48:33 +00:00
|
|
|
ok($tf->handle_http($t) == 0, 'config deny');
|
|
|
|
|
|
|
|
$t->{REQUEST} = ( <<EOF
|
|
|
|
GET /index.html HTTP/1.0
|
|
|
|
Host: test1.example.org
|
|
|
|
EOF
|
|
|
|
);
|
2005-08-31 12:55:44 +00:00
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => "/match_2" } ];
|
2005-08-08 13:48:33 +00:00
|
|
|
ok($tf->handle_http($t) == 0, '2nd child of chaining');
|
|
|
|
|
|
|
|
$t->{REQUEST} = ( <<EOF
|
|
|
|
GET /index.html HTTP/1.0
|
|
|
|
Host: test2.example.org
|
|
|
|
EOF
|
|
|
|
);
|
2005-08-31 12:55:44 +00:00
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => "/match_3" } ];
|
2005-08-08 13:48:33 +00:00
|
|
|
ok($tf->handle_http($t) == 0, '3rd child of chaining');
|
|
|
|
|
|
|
|
$t->{REQUEST} = ( <<EOF
|
|
|
|
GET /index.html HTTP/1.0
|
|
|
|
Host: test3.example.org
|
|
|
|
EOF
|
|
|
|
);
|
2005-08-31 12:55:44 +00:00
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => "/match_5" } ];
|
2005-08-08 13:48:33 +00:00
|
|
|
ok($tf->handle_http($t) == 0, 'nesting');
|
|
|
|
|
2011-02-10 07:56:11 +00:00
|
|
|
$t->{REQUEST} = ( <<EOF
|
|
|
|
GET /subdir/index.html HTTP/1.0
|
|
|
|
Host: test4.example.org
|
|
|
|
EOF
|
|
|
|
);
|
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => "/match_7" } ];
|
|
|
|
ok($tf->handle_http($t) == 0, 'url subdir');
|
|
|
|
|
|
|
|
$t->{REQUEST} = ( <<EOF
|
|
|
|
GET /subdir/../css/index.html HTTP/1.0
|
|
|
|
Host: test4.example.org
|
|
|
|
EOF
|
|
|
|
);
|
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => "/match_6" } ];
|
|
|
|
ok($tf->handle_http($t) == 0, 'url subdir with path traversal');
|
|
|
|
|
2005-08-08 13:48:33 +00:00
|
|
|
ok($tf->stop_proc == 0, "Stopping lighttpd");
|
|
|
|
|
2005-08-24 07:22:03 +00:00
|
|
|
$tf->{CONFIGFILE} = 'lighttpd.conf';
|
|
|
|
ok($tf->start_proc == 0, "Starting lighttpd") or die();
|
|
|
|
|
|
|
|
$t->{REQUEST} = ( <<EOF
|
|
|
|
GET /nofile.png HTTP/1.0
|
2005-09-16 12:44:29 +00:00
|
|
|
Host: referer.example.org
|
2005-08-24 07:22:03 +00:00
|
|
|
EOF
|
|
|
|
);
|
2005-08-31 12:55:44 +00:00
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ];
|
2005-08-24 07:22:03 +00:00
|
|
|
ok($tf->handle_http($t) == 0, 'condition: Referer - no referer');
|
|
|
|
|
|
|
|
$t->{REQUEST} = ( <<EOF
|
|
|
|
GET /nofile.png HTTP/1.0
|
2005-09-16 12:44:29 +00:00
|
|
|
Host: referer.example.org
|
|
|
|
Referer: http://referer.example.org/
|
2005-08-24 07:22:03 +00:00
|
|
|
EOF
|
|
|
|
);
|
2005-08-31 12:55:44 +00:00
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ];
|
2005-08-24 07:22:03 +00:00
|
|
|
ok($tf->handle_http($t) == 0, 'condition: Referer - referer matches regex');
|
|
|
|
|
2005-09-16 12:44:29 +00:00
|
|
|
$t->{REQUEST} = ( <<EOF
|
|
|
|
GET /image.jpg HTTP/1.0
|
2005-08-24 07:22:03 +00:00
|
|
|
Host: www.example.org
|
2005-09-16 12:44:29 +00:00
|
|
|
EOF
|
|
|
|
);
|
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
|
|
|
|
ok($tf->handle_http($t) == 0, 'condition: Referer - no referer');
|
|
|
|
|
|
|
|
$t->{REQUEST} = ( <<EOF
|
|
|
|
GET /image.jpg HTTP/1.0
|
|
|
|
Host: www.example.org
|
|
|
|
Referer: http://referer.example.org/
|
|
|
|
EOF
|
|
|
|
);
|
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
|
|
|
|
ok($tf->handle_http($t) == 0, 'condition: Referer - referer matches regex');
|
|
|
|
|
|
|
|
$t->{REQUEST} = ( <<EOF
|
|
|
|
GET /image.jpg HTTP/1.0
|
|
|
|
Host: www.example.org
|
|
|
|
Referer: http://evil-referer.example.org/
|
2005-08-24 07:22:03 +00:00
|
|
|
EOF
|
|
|
|
);
|
2005-08-31 12:55:44 +00:00
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 403 } ];
|
2005-08-24 07:22:03 +00:00
|
|
|
ok($tf->handle_http($t) == 0, 'condition: Referer - referer doesn\'t match');
|
|
|
|
|
2005-09-20 05:54:19 +00:00
|
|
|
$t->{REQUEST} = ( <<EOF
|
|
|
|
GET /nofile HTTP/1.1
|
|
|
|
Host: bug255.example.org
|
|
|
|
|
|
|
|
GET /nofile HTTP/1.1
|
|
|
|
Host: bug255.example.org
|
|
|
|
Connection: close
|
|
|
|
EOF
|
|
|
|
);
|
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 403 }, { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 403 } ];
|
|
|
|
ok($tf->handle_http($t) == 0, 'remote ip cache (#255)');
|
2005-09-16 12:44:29 +00:00
|
|
|
|
2005-09-29 13:30:25 +00:00
|
|
|
$t->{REQUEST} = ( <<EOF
|
2005-09-29 14:42:35 +00:00
|
|
|
GET /empty-ref.noref HTTP/1.0
|
|
|
|
Cookie: empty-ref
|
2005-09-29 13:30:25 +00:00
|
|
|
EOF
|
|
|
|
);
|
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 403 } ];
|
2005-09-29 14:42:35 +00:00
|
|
|
ok($tf->handle_http($t) == 0, 'condition: $HTTP["referer"] == "" and Referer is no set');
|
2005-09-29 13:30:25 +00:00
|
|
|
|
|
|
|
$t->{REQUEST} = ( <<EOF
|
2005-09-29 14:42:35 +00:00
|
|
|
GET /empty-ref.noref HTTP/1.0
|
|
|
|
Cookie: empty-ref
|
2005-09-29 13:30:25 +00:00
|
|
|
Referer:
|
|
|
|
EOF
|
|
|
|
);
|
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 403 } ];
|
2005-09-29 14:42:35 +00:00
|
|
|
ok($tf->handle_http($t) == 0, 'condition: $HTTP["referer"] == "" and Referer is empty');
|
2005-09-29 13:30:25 +00:00
|
|
|
|
|
|
|
$t->{REQUEST} = ( <<EOF
|
2005-09-29 14:42:35 +00:00
|
|
|
GET /empty-ref.noref HTTP/1.0
|
|
|
|
Cookie: empty-ref
|
2005-09-29 13:30:25 +00:00
|
|
|
Referer: foobar
|
|
|
|
EOF
|
|
|
|
);
|
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ];
|
2005-09-29 14:42:35 +00:00
|
|
|
ok($tf->handle_http($t) == 0, 'condition: $HTTP["referer"] == "" and Referer: foobar');
|
2005-09-29 13:30:25 +00:00
|
|
|
|
2005-08-24 07:22:03 +00:00
|
|
|
ok($tf->stop_proc == 0, "Stopping lighttpd");
|
|
|
|
|