[doc] add mimetype.use-xattr to create-mime.conf.pl
[lighttpd.git] / tests / mod-auth.t
blobcc03aa8a22c8865f622870d569c98243f9a1a7ac
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;
9 use strict;
10 use IO::Socket;
11 use Test::More tests => 19;
12 use LightyTest;
14 my $tf = LightyTest->new();
15 my $t;
17 ok($tf->start_proc == 0, "Starting lighttpd") or die();
19 $t->{REQUEST} = ( <<EOF
20 GET /server-status HTTP/1.0
21 EOF
23 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 401 } ];
24 ok($tf->handle_http($t) == 0, 'Missing Auth-token');
26 $t->{REQUEST} = ( <<EOF
27 GET /server-status HTTP/1.0
28 Authorization: Basic \x80mFuOmphb
29 EOF
31 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 401 } ];
32 ok($tf->handle_http($t) == 0, 'Basic-Auth: Invalid base64 Auth-token');
34 $t->{REQUEST} = ( <<EOF
35 GET /server-status HTTP/1.0
36 Authorization: Basic amFuOmphb
37 EOF
39 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 401 } ];
40 ok($tf->handle_http($t) == 0, 'Basic-Auth: Wrong Auth-token');
42 $t->{REQUEST} = ( <<EOF
43 GET /server-config HTTP/1.0
44 Authorization: Basic amFuOmphbg==
45 EOF
47 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
48 ok($tf->handle_http($t) == 0, 'Basic-Auth: Valid Auth-token - plain');
50 $t->{REQUEST} = ( <<EOF
51 GET /server-config HTTP/1.0
52 Host: auth-htpasswd.example.org
53 Authorization: Basic ZGVzOmRlcw==
54 EOF
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)');
59 $t->{REQUEST} = ( <<EOF
60 GET /server-config HTTP/1.0
61 Host: auth-htpasswd.example.org
62 Authorization: basic ZGVzOmRlcw==
63 EOF
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)');
68 $t->{REQUEST} = ( <<EOF
69 GET /server-config HTTP/1.0
70 Host: auth-htpasswd.example.org
71 Authorization: Basic c2hhOnNoYQ==
72 EOF
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)');
77 $t->{REQUEST} = ( <<EOF
78 GET /server-config HTTP/1.0
79 Host: auth-htpasswd.example.org
80 Authorization: Basic c2hhOnNoYg==
81 EOF
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)');
86 $t->{REQUEST} = ( <<EOF
87 GET /server-config HTTP/1.0
88 Host: auth-htpasswd.example.org
89 Authorization: Basic YXByLW1kNTphcHItbWQ1
90 EOF
92 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
93 ok($tf->handle_http($t) == 0, 'Basic-Auth: Valid Auth-token - htpasswd (apr-md5)');
95 $t->{REQUEST} = ( <<EOF
96 GET /server-config HTTP/1.0
97 Host: auth-htpasswd.example.org
98 Authorization: Basic YXByLW1kNTphcHItbWQ2
99 EOF
101 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 401 } ];
102 ok($tf->handle_http($t) == 0, 'Basic-Auth: Valid Auth-token - htpasswd (apr-md5, wrong password)');
104 SKIP: {
105 skip "no crypt-md5 under cygwin", 1 if $^O eq 'cygwin';
106 skip "no crypt-md5 under darwin", 1 if $^O eq 'darwin';
107 $t->{REQUEST} = ( <<EOF
108 GET /server-config HTTP/1.0
109 Host: auth-htpasswd.example.org
110 Authorization: Basic bWQ1Om1kNQ==
113 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
114 ok($tf->handle_http($t) == 0, 'Basic-Auth: Valid Auth-token - htpasswd (crypt-md5)');
117 $t->{REQUEST} = ( <<EOF
118 GET /server-config HTTP/1.0
119 Authorization: Basic bWQ1Om1kNA==
122 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 401 } ];
123 ok($tf->handle_http($t) == 0, 'Basic-Auth: Valid Auth-token');
125 ## this should not crash
126 $t->{REQUEST} = ( <<EOF
127 GET /server-status HTTP/1.0
128 User-Agent: Wget/1.9.1
129 Authorization: Digest username="jan", realm="jan", nonce="9a5428ccc05b086a08d918e73b01fc6f",
130 uri="/server-status", response="ea5f7d9a30b8b762f9610ccb87dea74f"
133 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 401 } ];
134 ok($tf->handle_http($t) == 0, 'Digest-Auth: missing qop, no crash');
136 ## this should not crash
137 $t->{REQUEST} = ( <<EOF
138 GET /server-status HTTP/1.0
139 User-Agent: Wget/1.9.1
140 Authorization: Digest username="jan", realm="jan",
141 nonce="b1d12348b4620437c43dd61c50ae4639",
142 uri="/MJ-BONG.xm.mpc", qop=auth, noncecount=00000001",
143 cnonce="036FCA5B86F7E7C4965C7F9B8FE714B7",
144 response="29B32C2953C763C6D033C8A49983B87E"
147 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
148 ok($tf->handle_http($t) == 0, 'Digest-Auth: missing nc (noncecount instead), no crash');
150 $t->{REQUEST} = ( <<EOF
151 GET /server-status HTTP/1.0
152 Authorization: Basic =
155 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 401 } ];
156 ok($tf->handle_http($t) == 0, 'Basic-Auth: Invalid Base64');
159 $t->{REQUEST} = ( <<EOF
160 GET /server-status HTTP/1.0
161 User-Agent: Wget/1.9.1
162 Authorization: Digest username="jan", realm="jan",
163 nonce="b1d12348b4620437c43dd61c50ae4639", algorithm="md5-sess",
164 uri="/MJ-BONG.xm.mpc", qop=auth, noncecount=00000001",
165 cnonce="036FCA5B86F7E7C4965C7F9B8FE714B7",
166 nc="asd",
167 response="29B32C2953C763C6D033C8A49983B87E"
170 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 401 } ];
171 ok($tf->handle_http($t) == 0, 'Digest-Auth: md5-sess + missing cnonce');
173 $t->{REQUEST} = ( <<EOF
174 GET /server-status HTTP/1.0
175 User-Agent: Wget/1.9.1
176 Authorization: Digest username="jan", realm="jan",
177 nonce="b1d12348b4620437c43dd61c50ae4639", algorithm="md5-sess",
178 uri="/MJ-BONG.xm.mpc", qop=auth, noncecount=00000001",
179 cnonce="036FCA5B86F7E7C4965C7F9B8FE714B7",
180 nc="asd",
181 response="29B32C2953C763C6D033C8A49983B87E"
184 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 401 } ];
185 ok($tf->handle_http($t) == 0, 'Digest-Auth: trailing WS');
189 ok($tf->stop_proc == 0, "Stopping lighttpd");