2005-09-01 11:44:57 +00:00
|
|
|
#!/usr/bin/env perl
|
2005-06-26 10:27:41 +00:00
|
|
|
BEGIN {
|
|
|
|
# add current source dir to the include-path
|
|
|
|
# we need this for make distcheck
|
|
|
|
(my $srcdir = $0) =~ s#/[^/]+$#/#;
|
|
|
|
unshift @INC, $srcdir;
|
|
|
|
}
|
2005-03-02 11:27:02 +00:00
|
|
|
|
|
|
|
use strict;
|
|
|
|
use IO::Socket;
|
2006-02-01 11:35:08 +00:00
|
|
|
use Test::More tests => 10;
|
2005-06-15 09:37:18 +00:00
|
|
|
use LightyTest;
|
2005-03-02 11:27:02 +00:00
|
|
|
|
2005-06-15 09:37:18 +00:00
|
|
|
my $tf = LightyTest->new();
|
|
|
|
my $t;
|
2006-10-05 00:09:51 +00:00
|
|
|
|
2005-06-15 09:37:18 +00:00
|
|
|
ok($tf->start_proc == 0, "Starting lighttpd") or die();
|
2005-03-02 11:27:02 +00:00
|
|
|
|
2005-06-15 09:37:18 +00:00
|
|
|
$t->{REQUEST} = ( <<EOF
|
2005-03-02 11:27:02 +00:00
|
|
|
GET /server-status HTTP/1.0
|
|
|
|
EOF
|
|
|
|
);
|
2005-08-31 12:55:44 +00:00
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 401 } ];
|
2005-06-15 09:37:18 +00:00
|
|
|
ok($tf->handle_http($t) == 0, 'Missing Auth-token');
|
2005-03-02 11:27:02 +00:00
|
|
|
|
2005-06-15 09:37:18 +00:00
|
|
|
$t->{REQUEST} = ( <<EOF
|
2005-03-02 11:27:02 +00:00
|
|
|
GET /server-status HTTP/1.0
|
|
|
|
Authorization: Basic amFuOmphb
|
|
|
|
EOF
|
|
|
|
);
|
2005-08-31 12:55:44 +00:00
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 401 } ];
|
2005-06-15 09:37:18 +00:00
|
|
|
ok($tf->handle_http($t) == 0, 'Basic-Auth: Wrong Auth-token');
|
2005-03-02 11:27:02 +00:00
|
|
|
|
2005-06-15 09:37:18 +00:00
|
|
|
$t->{REQUEST} = ( <<EOF
|
2005-03-02 11:27:02 +00:00
|
|
|
GET /server-config HTTP/1.0
|
|
|
|
Authorization: Basic amFuOmphbg==
|
|
|
|
EOF
|
|
|
|
);
|
2005-08-31 12:55:44 +00:00
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
|
2005-09-16 12:44:29 +00:00
|
|
|
ok($tf->handle_http($t) == 0, 'Basic-Auth: Valid Auth-token - plain');
|
|
|
|
|
|
|
|
$t->{REQUEST} = ( <<EOF
|
|
|
|
GET /server-config HTTP/1.0
|
|
|
|
Host: auth-htpasswd.example.org
|
|
|
|
Authorization: Basic ZGVzOmRlcw==
|
|
|
|
EOF
|
|
|
|
);
|
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
|
|
|
|
ok($tf->handle_http($t) == 0, 'Basic-Auth: Valid Auth-token - htpasswd (des)');
|
|
|
|
|
2005-10-01 12:35:55 +00:00
|
|
|
SKIP: {
|
2005-10-01 12:47:52 +00:00
|
|
|
skip "no md5 for crypt under cygwin", 1 if $^O eq 'cygwin';
|
2005-09-16 12:44:29 +00:00
|
|
|
$t->{REQUEST} = ( <<EOF
|
|
|
|
GET /server-config HTTP/1.0
|
|
|
|
Host: auth-htpasswd.example.org
|
|
|
|
Authorization: Basic bWQ1Om1kNQ==
|
|
|
|
EOF
|
|
|
|
);
|
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
|
|
|
|
ok($tf->handle_http($t) == 0, 'Basic-Auth: Valid Auth-token - htpasswd (md5)');
|
2005-10-01 12:35:55 +00:00
|
|
|
}
|
2005-09-16 12:44:29 +00:00
|
|
|
|
|
|
|
$t->{REQUEST} = ( <<EOF
|
|
|
|
GET /server-config HTTP/1.0
|
|
|
|
Authorization: Basic bWQ1Om1kNA==
|
|
|
|
EOF
|
|
|
|
);
|
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 401 } ];
|
2005-06-15 09:37:18 +00:00
|
|
|
ok($tf->handle_http($t) == 0, 'Basic-Auth: Valid Auth-token');
|
2005-03-02 11:27:02 +00:00
|
|
|
|
2005-06-11 09:02:34 +00:00
|
|
|
## this should not crash
|
2005-06-15 09:37:18 +00:00
|
|
|
$t->{REQUEST} = ( <<EOF
|
2005-06-11 09:02:34 +00:00
|
|
|
GET /server-status HTTP/1.0
|
2005-06-06 21:21:37 +00:00
|
|
|
User-Agent: Wget/1.9.1
|
2005-06-11 09:02:34 +00:00
|
|
|
Authorization: Digest username="jan", realm="jan", nonce="9a5428ccc05b086a08d918e73b01fc6f",
|
|
|
|
uri="/server-status", response="ea5f7d9a30b8b762f9610ccb87dea74f"
|
2005-06-06 21:21:37 +00:00
|
|
|
EOF
|
|
|
|
);
|
2005-08-31 12:55:44 +00:00
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 401 } ];
|
2005-06-15 09:37:18 +00:00
|
|
|
ok($tf->handle_http($t) == 0, 'Digest-Auth: missing qop, no crash');
|
2005-06-06 21:21:37 +00:00
|
|
|
|
2006-02-01 11:35:08 +00:00
|
|
|
## this should not crash
|
|
|
|
$t->{REQUEST} = ( <<EOF
|
|
|
|
GET /server-status HTTP/1.0
|
|
|
|
User-Agent: Wget/1.9.1
|
2006-10-05 00:09:51 +00:00
|
|
|
Authorization: Digest username="jan", realm="jan",
|
|
|
|
nonce="b1d12348b4620437c43dd61c50ae4639",
|
|
|
|
uri="/MJ-BONG.xm.mpc", qop=auth, noncecount=00000001",
|
|
|
|
cnonce="036FCA5B86F7E7C4965C7F9B8FE714B7",
|
|
|
|
response="29B32C2953C763C6D033C8A49983B87E"
|
2006-02-01 11:35:08 +00:00
|
|
|
EOF
|
|
|
|
);
|
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
|
|
|
|
ok($tf->handle_http($t) == 0, 'Digest-Auth: missing nc (noncecount instead), no crash');
|
|
|
|
|
|
|
|
|
2005-06-06 21:21:37 +00:00
|
|
|
|
2005-06-15 09:37:18 +00:00
|
|
|
ok($tf->stop_proc == 0, "Stopping lighttpd");
|
2005-03-02 11:27:02 +00:00
|
|
|
|