Annotation of embedaddon/lighttpd/tests/core-condition.t, revision 1.1

1.1     ! misho       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;
        !             7: }
        !             8: 
        !             9: use strict;
        !            10: use IO::Socket;
        !            11: use Test::More tests => 19;
        !            12: use LightyTest;
        !            13: 
        !            14: my $tf = LightyTest->new();
        !            15: my $t;
        !            16: 
        !            17: $tf->{CONFIGFILE} = 'condition.conf';
        !            18: ok($tf->start_proc == 0, "Starting lighttpd") or die();
        !            19: 
        !            20: $t->{REQUEST}  = ( <<EOF
        !            21: GET /index.html HTTP/1.0
        !            22: Host: www.example.org
        !            23: EOF
        !            24:  );
        !            25: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => "/match_1" } ];
        !            26: ok($tf->handle_http($t) == 0, 'config deny');
        !            27: 
        !            28: $t->{REQUEST}  = ( <<EOF
        !            29: GET /index.html HTTP/1.0
        !            30: Host: test1.example.org
        !            31: EOF
        !            32:  );
        !            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');
        !            35: 
        !            36: $t->{REQUEST}  = ( <<EOF
        !            37: GET /index.html HTTP/1.0
        !            38: Host: test2.example.org
        !            39: EOF
        !            40:  );
        !            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');
        !            43: 
        !            44: $t->{REQUEST}  = ( <<EOF
        !            45: GET /index.html HTTP/1.0
        !            46: Host: test3.example.org
        !            47: EOF
        !            48:  );
        !            49: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => "/match_5" } ];
        !            50: ok($tf->handle_http($t) == 0, 'nesting');
        !            51: 
        !            52: $t->{REQUEST}  = ( <<EOF
        !            53: GET /subdir/index.html HTTP/1.0
        !            54: Host: test4.example.org
        !            55: EOF
        !            56:  );
        !            57: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => "/match_7" } ];
        !            58: ok($tf->handle_http($t) == 0, 'url subdir');
        !            59: 
        !            60: $t->{REQUEST}  = ( <<EOF
        !            61: GET /subdir/../css/index.html HTTP/1.0
        !            62: Host: test4.example.org
        !            63: EOF
        !            64:  );
        !            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');
        !            67: 
        !            68: ok($tf->stop_proc == 0, "Stopping lighttpd");
        !            69: 
        !            70: $tf->{CONFIGFILE} = 'lighttpd.conf';
        !            71: ok($tf->start_proc == 0, "Starting lighttpd") or die();
        !            72: 
        !            73: $t->{REQUEST}  = ( <<EOF
        !            74: GET /nofile.png HTTP/1.0
        !            75: Host: referer.example.org
        !            76: EOF
        !            77:  );
        !            78: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ];
        !            79: ok($tf->handle_http($t) == 0, 'condition: Referer - no referer');
        !            80: 
        !            81: $t->{REQUEST}  = ( <<EOF
        !            82: GET /nofile.png HTTP/1.0
        !            83: Host: referer.example.org
        !            84: Referer: http://referer.example.org/
        !            85: EOF
        !            86:  );
        !            87: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ];
        !            88: ok($tf->handle_http($t) == 0, 'condition: Referer - referer matches regex');
        !            89: 
        !            90: $t->{REQUEST}  = ( <<EOF
        !            91: GET /image.jpg HTTP/1.0
        !            92: Host: www.example.org
        !            93: EOF
        !            94:  );
        !            95: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
        !            96: ok($tf->handle_http($t) == 0, 'condition: Referer - no referer');
        !            97: 
        !            98: $t->{REQUEST}  = ( <<EOF
        !            99: GET /image.jpg HTTP/1.0
        !           100: Host: www.example.org
        !           101: Referer: http://referer.example.org/
        !           102: EOF
        !           103:  );
        !           104: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
        !           105: ok($tf->handle_http($t) == 0, 'condition: Referer - referer matches regex');
        !           106: 
        !           107: $t->{REQUEST}  = ( <<EOF
        !           108: GET /image.jpg HTTP/1.0
        !           109: Host: www.example.org
        !           110: Referer: http://evil-referer.example.org/
        !           111: EOF
        !           112:  );
        !           113: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 403 } ];
        !           114: ok($tf->handle_http($t) == 0, 'condition: Referer - referer doesn\'t match');
        !           115: 
        !           116: $t->{REQUEST} = ( <<EOF
        !           117: GET /nofile HTTP/1.1
        !           118: Host: bug255.example.org
        !           119: 
        !           120: GET /nofile HTTP/1.1
        !           121: Host: bug255.example.org
        !           122: Connection: close
        !           123: EOF
        !           124:  );
        !           125: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 403 },  { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 403 } ];
        !           126: ok($tf->handle_http($t) == 0, 'remote ip cache (#255)');
        !           127: 
        !           128: $t->{REQUEST}  = ( <<EOF
        !           129: GET /empty-ref.noref HTTP/1.0
        !           130: Cookie: empty-ref
        !           131: EOF
        !           132:  );
        !           133: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 403 } ];
        !           134: ok($tf->handle_http($t) == 0, 'condition: $HTTP["referer"] == "" and Referer is no set');
        !           135: 
        !           136: $t->{REQUEST}  = ( <<EOF
        !           137: GET /empty-ref.noref HTTP/1.0
        !           138: Cookie: empty-ref
        !           139: Referer:
        !           140: EOF
        !           141:  );
        !           142: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 403 } ];
        !           143: ok($tf->handle_http($t) == 0, 'condition: $HTTP["referer"] == "" and Referer is empty');
        !           144: 
        !           145: $t->{REQUEST}  = ( <<EOF
        !           146: GET /empty-ref.noref HTTP/1.0
        !           147: Cookie: empty-ref
        !           148: Referer: foobar
        !           149: EOF
        !           150:  );
        !           151: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ];
        !           152: ok($tf->handle_http($t) == 0, 'condition: $HTTP["referer"] == "" and Referer: foobar');
        !           153: 
        !           154: ok($tf->stop_proc == 0, "Stopping lighttpd");
        !           155: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>