[core] fix buffer_copy_string_hex() assert (fixes #2742)
[lighttpd.git] / tests / mod-proxy.t
blob2362489b891d2bb14fac3753114abce5e61090a3
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 => 9;
12 use LightyTest;
14 my $tf_real = LightyTest->new();
15 my $tf_proxy = LightyTest->new();
17 my $t;
18 my $php_child = -1;
20 SKIP: {
21 skip "PHP already running on port 1026", 1 if $tf_real->listening_on(1026);
22 skip "no php binary found", 1 unless $LightyTest::HAVE_PHP;
23 ok(-1 != ($php_child = $tf_real->spawnfcgi($ENV{'PHP'}, 1026)), "Spawning php");
26 ## we need two procs
27 ## 1. the real webserver
28 ## 2. the proxy server
30 $tf_real->{PORT} = 2048;
31 $tf_real->{CONFIGFILE} = 'lighttpd.conf';
33 $tf_proxy->{PORT} = 2050;
34 $tf_proxy->{CONFIGFILE} = 'proxy.conf';
36 ok($tf_real->start_proc == 0, "Starting lighttpd") or goto cleanup;
38 ok($tf_proxy->start_proc == 0, "Starting lighttpd as proxy") or goto cleanup;
40 $t->{REQUEST} = ( <<EOF
41 GET /index.html HTTP/1.0
42 Host: www.example.org
43 EOF
45 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
46 ok($tf_proxy->handle_http($t) == 0, 'valid request');
48 $t->{REQUEST} = ( <<EOF
49 GET /index.html HTTP/1.0
50 Host: www.example.org
51 EOF
53 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'Server' => 'Apache 1.3.29' } ];
54 ok($tf_proxy->handle_http($t) == 0, 'drop Server from real server');
56 SKIP: {
57 skip "no PHP running on port 1026", 1 unless $tf_real->listening_on(1026);
58 $t->{REQUEST} = ( <<EOF
59 GET /rewrite/all/some+test%3axxx%20with%20space HTTP/1.0
60 Host: www.example.org
61 EOF
63 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/some+test%3axxx%20with%20space' } ];
64 ok($tf_proxy->handle_http($t) == 0, 'rewrited urls work with encoded path');
67 ok($tf_proxy->stop_proc == 0, "Stopping lighttpd proxy");
69 ok($tf_real->stop_proc == 0, "Stopping lighttpd");
71 SKIP: {
72 skip "PHP not started, cannot stop it", 1 unless $php_child != -1;
73 ok(0 == $tf_real->endspawnfcgi($php_child), "Stopping php");
74 $php_child = -1;
77 exit 0;
79 cleanup:
81 $tf_real->endspawnfcgi($php_child) if $php_child != -1;
82 $tf_real->stop_proc;
83 $tf_proxy->stop_proc;
85 die();