Annotation of embedaddon/lighttpd/tests/mod-auth.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 => 17;
                     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 /server-status HTTP/1.0
                     21: EOF
                     22:  );
                     23: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 401 } ];
                     24: ok($tf->handle_http($t) == 0, 'Missing Auth-token');
                     25: 
                     26: $t->{REQUEST}  = ( <<EOF
                     27: GET /server-status HTTP/1.0
                     28: Authorization: Basic \x80mFuOmphb
                     29: EOF
                     30:  );
                     31: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 401 } ];
                     32: ok($tf->handle_http($t) == 0, 'Basic-Auth: Invalid base64 Auth-token');
                     33: 
                     34: $t->{REQUEST}  = ( <<EOF
                     35: GET /server-status HTTP/1.0
                     36: Authorization: Basic amFuOmphb
                     37: EOF
                     38:  );
                     39: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 401 } ];
                     40: ok($tf->handle_http($t) == 0, 'Basic-Auth: Wrong Auth-token');
                     41: 
                     42: $t->{REQUEST}  = ( <<EOF
                     43: GET /server-config HTTP/1.0
                     44: Authorization: Basic amFuOmphbg==
                     45: EOF
                     46:  );
                     47: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
                     48: ok($tf->handle_http($t) == 0, 'Basic-Auth: Valid Auth-token - plain');
                     49: 
                     50: $t->{REQUEST}  = ( <<EOF
                     51: GET /server-config HTTP/1.0
                     52: Host: auth-htpasswd.example.org
                     53: Authorization: Basic ZGVzOmRlcw==
                     54: EOF
                     55:  );
                     56: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
                     57: ok($tf->handle_http($t) == 0, 'Basic-Auth: Valid Auth-token - htpasswd (des)');
                     58: 
                     59: $t->{REQUEST}  = ( <<EOF
                     60: GET /server-config HTTP/1.0
                     61: Host: auth-htpasswd.example.org
                     62: Authorization: basic ZGVzOmRlcw==
                     63: EOF
                     64:  );
                     65: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
                     66: ok($tf->handle_http($t) == 0, 'Basic-Auth: Valid Auth-token - htpasswd (des) (lowercase)');
                     67: 
                     68: $t->{REQUEST}  = ( <<EOF
                     69: GET /server-config HTTP/1.0
                     70: Host: auth-htpasswd.example.org
                     71: Authorization: Basic c2hhOnNoYQ==
                     72: EOF
                     73:  );
                     74: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
                     75: ok($tf->handle_http($t) == 0, 'Basic-Auth: Valid Auth-token - htpasswd (sha)');
                     76: 
                     77: $t->{REQUEST}  = ( <<EOF
                     78: GET /server-config HTTP/1.0
                     79: Host: auth-htpasswd.example.org
                     80: Authorization: Basic c2hhOnNoYg==
                     81: EOF
                     82:  );
                     83: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 401 } ];
                     84: ok($tf->handle_http($t) == 0, 'Basic-Auth: Valid Auth-token - htpasswd (sha, wrong password)');
                     85: 
                     86: 
                     87: SKIP: {
                     88:        skip "no md5 for crypt under cygwin", 1 if $^O eq 'cygwin';
                     89: $t->{REQUEST}  = ( <<EOF
                     90: GET /server-config HTTP/1.0
                     91: Host: auth-htpasswd.example.org
                     92: Authorization: Basic bWQ1Om1kNQ==
                     93: EOF
                     94:  );
                     95: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
                     96: ok($tf->handle_http($t) == 0, 'Basic-Auth: Valid Auth-token - htpasswd (md5)');
                     97: }
                     98: 
                     99: $t->{REQUEST}  = ( <<EOF
                    100: GET /server-config HTTP/1.0
                    101: Authorization: Basic bWQ1Om1kNA==
                    102: EOF
                    103:  );
                    104: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 401 } ];
                    105: ok($tf->handle_http($t) == 0, 'Basic-Auth: Valid Auth-token');
                    106: 
                    107: ## this should not crash
                    108: $t->{REQUEST}  = ( <<EOF
                    109: GET /server-status HTTP/1.0
                    110: User-Agent: Wget/1.9.1
                    111: Authorization: Digest username="jan", realm="jan", nonce="9a5428ccc05b086a08d918e73b01fc6f",
                    112:                 uri="/server-status", response="ea5f7d9a30b8b762f9610ccb87dea74f"
                    113: EOF
                    114:  );
                    115: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 401 } ];
                    116: ok($tf->handle_http($t) == 0, 'Digest-Auth: missing qop, no crash');
                    117: 
                    118: ## this should not crash
                    119: $t->{REQUEST}  = ( <<EOF
                    120: GET /server-status HTTP/1.0
                    121: User-Agent: Wget/1.9.1
                    122: Authorization: Digest username="jan", realm="jan",
                    123:        nonce="b1d12348b4620437c43dd61c50ae4639",
                    124:        uri="/MJ-BONG.xm.mpc", qop=auth, noncecount=00000001",
                    125:        cnonce="036FCA5B86F7E7C4965C7F9B8FE714B7",
                    126:        response="29B32C2953C763C6D033C8A49983B87E"
                    127: EOF
                    128:  );
                    129: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
                    130: ok($tf->handle_http($t) == 0, 'Digest-Auth: missing nc (noncecount instead), no crash');
                    131: 
                    132: $t->{REQUEST}  = ( <<EOF
                    133: GET /server-status HTTP/1.0
                    134: Authorization: Basic =
                    135: EOF
                    136:  );
                    137: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 401 } ];
                    138: ok($tf->handle_http($t) == 0, 'Basic-Auth: Invalid Base64');
                    139: 
                    140: 
                    141: $t->{REQUEST}  = ( <<EOF
                    142: GET /server-status HTTP/1.0
                    143: User-Agent: Wget/1.9.1
                    144: Authorization: Digest username="jan", realm="jan",
                    145:        nonce="b1d12348b4620437c43dd61c50ae4639", algorithm="md5-sess",
                    146:        uri="/MJ-BONG.xm.mpc", qop=auth, noncecount=00000001",
                    147:        cnonce="036FCA5B86F7E7C4965C7F9B8FE714B7",
                    148:        nc="asd",
                    149:        response="29B32C2953C763C6D033C8A49983B87E"
                    150: EOF
                    151:  );
                    152: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 401 } ];
                    153: ok($tf->handle_http($t) == 0, 'Digest-Auth: md5-sess + missing cnonce');
                    154: 
                    155: $t->{REQUEST}  = ( <<EOF
                    156: GET /server-status HTTP/1.0
                    157: User-Agent: Wget/1.9.1
                    158: Authorization: Digest username="jan", realm="jan",
                    159:        nonce="b1d12348b4620437c43dd61c50ae4639", algorithm="md5-sess",
                    160:        uri="/MJ-BONG.xm.mpc", qop=auth, noncecount=00000001",
                    161:        cnonce="036FCA5B86F7E7C4965C7F9B8FE714B7",
                    162:        nc="asd",
                    163:        response="29B32C2953C763C6D033C8A49983B87E"     
                    164: EOF
                    165:  );
                    166: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 401 } ];
                    167: ok($tf->handle_http($t) == 0, 'Digest-Auth: trailing WS');
                    168: 
                    169: 
                    170: 
                    171: ok($tf->stop_proc == 0, "Stopping lighttpd");
                    172: 

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