Annotation of embedaddon/lighttpd/tests/core.t, revision 1.1.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 => 21;
                     12: use LightyTest;
                     13: 
                     14: my $tf = LightyTest->new();
                     15: my $t;
                     16: 
                     17: ok($tf->start_proc == 0, "Starting lighttpd") or die();
                     18: 
                     19: $t->{REQUEST}  = ( <<EOF
                     20: GET / HTTP/1.0
                     21: EOF
                     22:  );
                     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();
                     25: 
                     26: $t->{REQUEST}  = ( <<EOF
                     27: GET /
                     28: EOF
                     29:  );
                     30: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
                     31: ok($tf->handle_http($t) == 0, 'missing Protocol');
                     32: 
                     33: $t->{REQUEST}  = ( <<EOF
                     34: GET / HTTP/01.01
                     35: Host: foo
                     36: Connection: close
                     37: EOF
                     38:  );
                     39: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 200 } ];
                     40: ok($tf->handle_http($t) == 0, 'zeros in protocol version');
                     41: 
                     42: $t->{REQUEST}  = ( <<EOF
                     43: GET / HTTP/.01
                     44: EOF
                     45:  );
                     46: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
                     47: ok($tf->handle_http($t) == 0, 'missing major version');
                     48: 
                     49: $t->{REQUEST}  = ( <<EOF
                     50: GET / HTTP/01.
                     51: EOF
                     52:  );
                     53: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
                     54: ok($tf->handle_http($t) == 0, 'missing minor version');
                     55: 
                     56: $t->{REQUEST}  = ( <<EOF
                     57: GET / HTTP/a.b
                     58: EOF
                     59:  );
                     60: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
                     61: ok($tf->handle_http($t) == 0, 'strings as version');
                     62: 
                     63: $t->{REQUEST}  = ( <<EOF
                     64: BC /
                     65: EOF
                     66:  );
                     67: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
                     68: ok($tf->handle_http($t) == 0, 'missing protocol + unknown method');
                     69: 
                     70: $t->{REQUEST}  = ( <<EOF
                     71: ABC
                     72: EOF
                     73:  );
                     74: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
                     75: ok($tf->handle_http($t) == 0, 'missing protocol + unknown method + missing URI');
                     76: 
                     77: $t->{REQUEST}  = ( <<EOF
                     78: ABC / HTTP/1.0
                     79: EOF
                     80:  );
                     81: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 501 } ];
                     82: ok($tf->handle_http($t) == 0, 'unknown method');
                     83: 
                     84: $t->{REQUEST}  = ( <<EOF
                     85: GET / HTTP/1.3
                     86: EOF
                     87:  );
                     88: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 505 } ];
                     89: ok($tf->handle_http($t) == 0, 'unknown protocol');
                     90: 
                     91: $t->{REQUEST}  = ( <<EOF
                     92: GET http://www.example.org/ HTTP/1.0
                     93: EOF
                     94:  );
                     95: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
                     96: ok($tf->handle_http($t) == 0, 'absolute URI');
                     97: 
                     98: print "\nLow-Level Request-Header Parsing\n";
                     99: $t->{REQUEST}  = ( <<EOF
                    100: GET / HTTP/1.0
                    101: ABC : foo
                    102: EOF
                    103:  );
                    104: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
                    105: ok($tf->handle_http($t) == 0, 'whitespace after key');
                    106: 
                    107: $t->{REQUEST}  = ( <<EOF
                    108: GET / HTTP/1.0
                    109: ABC a: foo
                    110: EOF
                    111:  );
                    112: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
                    113: ok($tf->handle_http($t) == 0, 'whitespace with-in key');
                    114: 
                    115: $t->{REQUEST}  = ( <<EOF
                    116: GET / HTTP/1.0
                    117: ABC:foo
                    118: EOF
                    119:  );
                    120: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
                    121: ok($tf->handle_http($t) == 0, 'no whitespace');
                    122: 
                    123: $t->{REQUEST}  = ( <<EOF
                    124: GET / HTTP/1.0
                    125: ABC:foo
                    126:   bc
                    127: EOF
                    128:  );
                    129: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
                    130: ok($tf->handle_http($t) == 0, 'line-folding');
                    131: 
                    132: print "\nLow-Level Request-Header Parsing - URI\n";
                    133: $t->{REQUEST}  = ( <<EOF
                    134: GET /index%2ehtml HTTP/1.0
                    135: EOF
                    136:  );
                    137: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
                    138: ok($tf->handle_http($t) == 0, 'URL-encoding');
                    139: 
                    140: $t->{REQUEST}  = ( <<EOF
                    141: GET /index.html%00 HTTP/1.0
                    142: EOF
                    143:  );
                    144: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ];
                    145: ok($tf->handle_http($t) == 0, 'URL-encoding, %00');
                    146: 
                    147: $t->{REQUEST}  = ( <<EOF
                    148: OPTIONS * HTTP/1.0
                    149: EOF
                    150:  );
                    151: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
                    152: ok($tf->handle_http($t) == 0, 'OPTIONS');
                    153: 
                    154: $t->{REQUEST}  = ( <<EOF
                    155: OPTIONS / HTTP/1.1
                    156: Host: www.example.org
                    157: Connection: close
                    158: EOF
                    159:  );
                    160: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 200 } ];
                    161: ok($tf->handle_http($t) == 0, 'OPTIONS');
                    162: 
                    163: 
                    164: 
                    165: ok($tf->stop_proc == 0, "Stopping lighttpd");
                    166: 

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