2005-09-01 11:44:57 +00:00
|
|
|
#!/usr/bin/env perl
|
2005-06-26 10:27:41 +00:00
|
|
|
BEGIN {
|
2008-01-15 22:03:59 +00:00
|
|
|
# add current source dir to the include-path
|
|
|
|
# we need this for make distcheck
|
|
|
|
(my $srcdir = $0) =~ s,/[^/]+$,/,;
|
|
|
|
unshift @INC, $srcdir;
|
2005-06-26 10:27:41 +00:00
|
|
|
}
|
2005-03-02 11:27:02 +00:00
|
|
|
|
|
|
|
use strict;
|
2020-12-23 05:38:43 +00:00
|
|
|
use Test::More tests => 24;
|
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();
|
2005-03-02 11:27:02 +00:00
|
|
|
|
2005-06-15 09:37:18 +00:00
|
|
|
my $t;
|
2008-07-29 21:22:28 +00:00
|
|
|
|
|
|
|
SKIP: {
|
2020-12-23 05:38:43 +00:00
|
|
|
skip "no fcgi-responder found", 24
|
|
|
|
unless ( -x $tf->{BASEDIR}."/tests/fcgi-responder"
|
|
|
|
|| -x $tf->{BASEDIR}."/tests/fcgi-responder.exe");
|
2005-03-02 11:27:02 +00:00
|
|
|
|
2020-12-23 05:38:43 +00:00
|
|
|
$tf->{CONFIGFILE} = 'fastcgi-responder.conf';
|
|
|
|
ok($tf->start_proc == 0, "Starting lighttpd with $tf->{CONFIGFILE}") or die();
|
2005-03-02 11:27:02 +00:00
|
|
|
|
2005-06-15 09:37:18 +00:00
|
|
|
$t->{REQUEST} = ( <<EOF
|
2020-12-23 05:38:43 +00:00
|
|
|
GET /prefix.fcgi-nonexistent HTTP/1.0
|
2005-03-02 11:27:02 +00:00
|
|
|
Host: www.example.org
|
|
|
|
EOF
|
|
|
|
);
|
2005-08-31 12:55:44 +00:00
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ];
|
2005-06-15 09:37:18 +00:00
|
|
|
ok($tf->handle_http($t) == 0, 'file not found');
|
2005-03-02 11:27:02 +00:00
|
|
|
|
2005-06-15 09:37:18 +00:00
|
|
|
$t->{REQUEST} = ( <<EOF
|
2020-12-23 05:38:43 +00:00
|
|
|
GET /prefix.fcgi?env=SCRIPT_NAME HTTP/1.0
|
2005-03-02 11:27:02 +00:00
|
|
|
EOF
|
|
|
|
);
|
2020-12-23 05:38:43 +00:00
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/prefix.fcgi' } ];
|
|
|
|
ok($tf->handle_http($t) == 0, 'SCRIPT_NAME');
|
2005-03-02 11:27:02 +00:00
|
|
|
|
2005-06-15 09:37:18 +00:00
|
|
|
$t->{REQUEST} = ( <<EOF
|
2020-12-23 05:38:43 +00:00
|
|
|
GET /prefix.fcgi/foo/bar?env=SCRIPT_NAME HTTP/1.0
|
2005-03-02 11:27:02 +00:00
|
|
|
EOF
|
|
|
|
);
|
2020-12-23 05:38:43 +00:00
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/prefix.fcgi' } ];
|
|
|
|
ok($tf->handle_http($t) == 0, 'SCRIPT_NAME w/ PATH_INFO');
|
2005-03-02 11:27:02 +00:00
|
|
|
|
2005-08-09 06:42:33 +00:00
|
|
|
$t->{REQUEST} = ( <<EOF
|
2020-12-23 05:38:43 +00:00
|
|
|
GET /prefix.fcgi/foo/bar?env=PATH_INFO HTTP/1.0
|
2005-08-09 06:42:33 +00:00
|
|
|
EOF
|
|
|
|
);
|
2020-12-23 05:38:43 +00:00
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/foo/bar' } ];
|
|
|
|
ok($tf->handle_http($t) == 0, 'PATH_INFO');
|
2005-08-09 06:42:33 +00:00
|
|
|
|
2020-12-23 05:38:43 +00:00
|
|
|
$t->{REQUEST} = ( <<EOF
|
|
|
|
GET /phpinfo.php HTTP/1.0
|
2005-03-02 11:27:02 +00:00
|
|
|
Host: www.example.org
|
|
|
|
EOF
|
|
|
|
);
|
2005-08-31 12:55:44 +00:00
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
|
2020-12-23 05:38:43 +00:00
|
|
|
ok($tf->handle_http($t) == 0, 'valid request');
|
2005-07-28 10:24:49 +00:00
|
|
|
|
2009-10-14 17:32:38 +00:00
|
|
|
$t->{REQUEST} = ( <<EOF
|
2020-12-23 05:38:43 +00:00
|
|
|
GET /get-server-env.php?env=USER HTTP/1.0
|
|
|
|
Host: bin-env.example.org
|
2009-10-14 17:32:38 +00:00
|
|
|
EOF
|
|
|
|
);
|
2020-12-23 05:38:43 +00:00
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 , 'HTTP-Content' => $ENV{USER} } ];
|
|
|
|
ok($tf->handle_http($t) == 0, 'FastCGI + bin-copy-environment');
|
2009-10-14 17:32:38 +00:00
|
|
|
|
|
|
|
$t->{REQUEST} = ( <<EOF
|
2020-12-23 05:38:43 +00:00
|
|
|
GET /get-server-env.php?env=MAIL HTTP/1.0
|
|
|
|
Host: bin-env.example.org
|
2009-10-14 17:32:38 +00:00
|
|
|
EOF
|
|
|
|
);
|
2020-12-23 05:38:43 +00:00
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 , 'HTTP-Content' => '' } ];
|
|
|
|
ok($tf->handle_http($t) == 0, 'FastCGI + bin-copy-environment');
|
2009-10-14 17:32:38 +00:00
|
|
|
|
2020-12-26 08:47:02 +00:00
|
|
|
SKIP: {
|
|
|
|
skip "no crypt-des under openbsd", 2 if $^O eq 'openbsd';
|
|
|
|
|
2012-04-19 13:02:11 +00:00
|
|
|
$t->{REQUEST} = ( <<EOF
|
|
|
|
GET /get-server-env.php?env=REMOTE_USER HTTP/1.0
|
|
|
|
Host: auth.example.org
|
|
|
|
Authorization: Basic ZGVzOmRlcw==
|
|
|
|
EOF
|
|
|
|
);
|
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'des' } ];
|
|
|
|
ok($tf->handle_http($t) == 0, '$_SERVER["REMOTE_USER"]');
|
|
|
|
|
|
|
|
$t->{REQUEST} = ( <<EOF
|
|
|
|
GET /get-server-env.php?env=AUTH_TYPE HTTP/1.0
|
|
|
|
Host: auth.example.org
|
|
|
|
Authorization: Basic ZGVzOmRlcw==
|
|
|
|
EOF
|
|
|
|
);
|
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'Basic' } ];
|
|
|
|
ok($tf->handle_http($t) == 0, '$_SERVER["AUTH_TYPE"]');
|
2020-12-26 08:47:02 +00:00
|
|
|
}
|
2012-04-19 13:02:11 +00:00
|
|
|
|
2005-06-15 09:37:18 +00:00
|
|
|
$t->{REQUEST} = ( <<EOF
|
2020-12-21 02:32:50 +00:00
|
|
|
GET /index.html?auth-ok HTTP/1.0
|
2018-12-11 03:35:21 +00:00
|
|
|
Host: auth.example.org
|
2005-03-02 11:27:02 +00:00
|
|
|
EOF
|
|
|
|
);
|
2005-08-31 12:55:44 +00:00
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
|
2005-06-15 09:37:18 +00:00
|
|
|
ok($tf->handle_http($t) == 0, 'FastCGI - Auth');
|
2005-03-02 11:27:02 +00:00
|
|
|
|
2005-06-15 09:37:18 +00:00
|
|
|
$t->{REQUEST} = ( <<EOF
|
2020-12-21 02:32:50 +00:00
|
|
|
GET /index.html?auth-fail HTTP/1.0
|
2018-12-11 03:35:21 +00:00
|
|
|
Host: auth.example.org
|
2005-03-02 11:27:02 +00:00
|
|
|
EOF
|
|
|
|
);
|
2005-08-31 12:55:44 +00:00
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 403 } ];
|
2005-06-15 09:37:18 +00:00
|
|
|
ok($tf->handle_http($t) == 0, 'FastCGI - Auth');
|
2005-03-02 11:27:02 +00:00
|
|
|
|
2008-10-01 20:08:23 +00:00
|
|
|
$t->{REQUEST} = ( <<EOF
|
2020-12-21 02:32:50 +00:00
|
|
|
GET /expire/access.txt?auth-ok HTTP/1.0
|
2018-12-11 03:35:21 +00:00
|
|
|
Host: auth.example.org
|
2008-10-01 20:08:23 +00:00
|
|
|
EOF
|
|
|
|
);
|
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
|
|
|
|
ok($tf->handle_http($t) == 0, 'FastCGI - Auth in subdirectory');
|
|
|
|
|
2016-08-12 07:58:48 +00:00
|
|
|
$t->{REQUEST} = ( <<EOF
|
2020-12-21 02:32:50 +00:00
|
|
|
GET /index.fcgi?auth-varfail HTTP/1.0
|
2018-12-11 03:35:21 +00:00
|
|
|
Host: auth.example.org
|
2016-08-12 07:58:48 +00:00
|
|
|
EOF
|
|
|
|
);
|
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 403 } ];
|
|
|
|
ok($tf->handle_http($t) == 0, 'FastCGI - Auth Fail with FastCGI responder afterwards');
|
|
|
|
|
|
|
|
$t->{REQUEST} = ( <<EOF
|
2020-12-21 02:32:50 +00:00
|
|
|
GET /index.fcgi?auth-var HTTP/1.0
|
2018-12-11 03:35:21 +00:00
|
|
|
Host: auth.example.org
|
2016-08-12 07:58:48 +00:00
|
|
|
EOF
|
|
|
|
);
|
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'LighttpdTestContent' } ];
|
|
|
|
ok($tf->handle_http($t) == 0, 'FastCGI - Auth Success with Variable- to Env expansion');
|
|
|
|
|
2005-06-15 09:37:18 +00:00
|
|
|
$t->{REQUEST} = ( <<EOF
|
2005-03-02 11:27:02 +00:00
|
|
|
GET /index.fcgi?lf HTTP/1.0
|
|
|
|
Host: www.example.org
|
|
|
|
EOF
|
|
|
|
);
|
2005-08-31 12:55:44 +00:00
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } ];
|
2005-06-15 09:37:18 +00:00
|
|
|
ok($tf->handle_http($t) == 0, 'line-ending \n\n');
|
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 /index.fcgi?crlf HTTP/1.0
|
|
|
|
Host: www.example.org
|
|
|
|
EOF
|
|
|
|
);
|
2005-08-31 12:55:44 +00:00
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } ];
|
2005-06-15 09:37:18 +00:00
|
|
|
ok($tf->handle_http($t) == 0, 'line-ending \r\n\r\n');
|
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 /index.fcgi?slow-lf HTTP/1.0
|
|
|
|
Host: www.example.org
|
|
|
|
EOF
|
|
|
|
);
|
2005-08-31 12:55:44 +00:00
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } ];
|
2005-06-15 09:37:18 +00:00
|
|
|
ok($tf->handle_http($t) == 0, 'line-ending \n + \n');
|
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 /index.fcgi?slow-crlf HTTP/1.0
|
|
|
|
Host: www.example.org
|
|
|
|
EOF
|
|
|
|
);
|
2005-08-31 12:55:44 +00:00
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } ];
|
2005-06-15 09:37:18 +00:00
|
|
|
ok($tf->handle_http($t) == 0, 'line-ending \r\n + \r\n');
|
2005-03-02 11:27:02 +00:00
|
|
|
|
2009-04-01 17:35:17 +00:00
|
|
|
$t->{REQUEST} = ( <<EOF
|
2020-12-23 05:38:43 +00:00
|
|
|
GET /abc/def/ghi?env=PATH_INFO HTTP/1.0
|
2009-04-01 17:35:17 +00:00
|
|
|
Host: wsgi.example.org
|
|
|
|
EOF
|
|
|
|
);
|
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/abc/def/ghi' } ];
|
|
|
|
ok($tf->handle_http($t) == 0, 'PATH_INFO (wsgi)');
|
|
|
|
|
|
|
|
$t->{REQUEST} = ( <<EOF
|
2020-12-23 05:38:43 +00:00
|
|
|
GET /abc/def/ghi?env=SCRIPT_NAME HTTP/1.0
|
2009-04-01 17:35:17 +00:00
|
|
|
Host: wsgi.example.org
|
|
|
|
EOF
|
|
|
|
);
|
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '' } ];
|
|
|
|
ok($tf->handle_http($t) == 0, 'SCRIPT_NAME (wsgi)');
|
|
|
|
|
|
|
|
|
2005-06-15 09:37:18 +00:00
|
|
|
$t->{REQUEST} = ( <<EOF
|
2005-03-02 11:27:02 +00:00
|
|
|
GET /index.fcgi?die-at-end HTTP/1.0
|
|
|
|
Host: www.example.org
|
|
|
|
EOF
|
|
|
|
);
|
2005-08-31 12:55:44 +00:00
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } ];
|
2005-06-15 09:37:18 +00:00
|
|
|
ok($tf->handle_http($t) == 0, 'killing fastcgi and wait for restart');
|
2005-03-02 11:27:02 +00:00
|
|
|
|
2017-01-11 00:18:36 +00:00
|
|
|
# (might take lighttpd 1 sec to detect backend exit)
|
2017-03-19 02:35:31 +00:00
|
|
|
select(undef, undef, undef, .5);
|
|
|
|
for (my $c = 2*20; $c && 0 == $tf->listening_on(10000); --$c) {
|
|
|
|
select(undef, undef, undef, 0.05);
|
|
|
|
}
|
2005-06-15 09:37:18 +00:00
|
|
|
$t->{REQUEST} = ( <<EOF
|
2005-03-02 11:27:02 +00:00
|
|
|
GET /index.fcgi?crlf HTTP/1.0
|
|
|
|
Host: www.example.org
|
|
|
|
EOF
|
|
|
|
);
|
2005-08-31 12:55:44 +00:00
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } ];
|
2005-06-15 09:37:18 +00:00
|
|
|
ok($tf->handle_http($t) == 0, 'regular response of after restart');
|
2005-03-02 11:27:02 +00:00
|
|
|
|
|
|
|
|
2005-06-15 09:37:18 +00:00
|
|
|
ok($tf->stop_proc == 0, "Stopping lighttpd");
|
2005-03-03 11:35:27 +00:00
|
|
|
}
|