File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / lighttpd / tests / mod-proxy.t
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Mon Oct 14 10:32:47 2013 UTC (10 years, 8 months ago) by misho
Branches: lighttpd, MAIN
CVS tags: v1_4_35p0, v1_4_35, v1_4_33, HEAD
1.4.33

    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 => 9;
   12: use LightyTest;
   13: 
   14: my $tf_real = LightyTest->new();
   15: my $tf_proxy = LightyTest->new();
   16: 
   17: my $t;
   18: my $php_child = -1;
   19: 
   20: my $phpbin = (defined $ENV{'PHP'} ? $ENV{'PHP'} : '/usr/bin/php-cgi');
   21: $ENV{'PHP'} = $phpbin;
   22: 
   23: SKIP: {
   24: 	skip "PHP already running on port 1026", 1 if $tf_real->listening_on(1026);
   25: 	skip "no php binary found", 1 unless -x $phpbin;
   26: 	ok(-1 != ($php_child = $tf_real->spawnfcgi($phpbin, 1026)), "Spawning php");
   27: }
   28: 
   29: ## we need two procs
   30: ## 1. the real webserver
   31: ## 2. the proxy server
   32: 
   33: $tf_real->{PORT} = 2048;
   34: $tf_real->{CONFIGFILE} = 'lighttpd.conf';
   35: 
   36: $tf_proxy->{PORT} = 2050;
   37: $tf_proxy->{CONFIGFILE} = 'proxy.conf';
   38: 
   39: ok($tf_real->start_proc == 0, "Starting lighttpd") or goto cleanup;
   40: 
   41: ok($tf_proxy->start_proc == 0, "Starting lighttpd as proxy") or goto cleanup;
   42: 
   43: $t->{REQUEST}  = ( <<EOF
   44: GET /index.html HTTP/1.0
   45: Host: www.example.org
   46: EOF
   47:  );
   48: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
   49: ok($tf_proxy->handle_http($t) == 0, 'valid request');
   50: 
   51: $t->{REQUEST}  = ( <<EOF
   52: GET /index.html HTTP/1.0
   53: Host: www.example.org
   54: EOF
   55:  );
   56: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'Server' => 'Apache 1.3.29' } ];
   57: ok($tf_proxy->handle_http($t) == 0, 'drop Server from real server');
   58: 
   59: SKIP: {
   60: 	skip "no PHP running on port 1026", 1 unless $tf_real->listening_on(1026);
   61: 	$t->{REQUEST}  = ( <<EOF
   62: GET /rewrite/all/some+test%3axxx%20with%20space HTTP/1.0
   63: Host: www.example.org
   64: EOF
   65:  );
   66: 	$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/some+test%3axxx%20with%20space' } ];
   67: 	ok($tf_proxy->handle_http($t) == 0, 'rewrited urls work with encoded path');
   68: }
   69: 
   70: ok($tf_proxy->stop_proc == 0, "Stopping lighttpd proxy");
   71: 
   72: ok($tf_real->stop_proc == 0, "Stopping lighttpd");
   73: 
   74: SKIP: {
   75: 	skip "PHP not started, cannot stop it", 1 unless $php_child != -1;
   76: 	ok(0 == $tf_real->endspawnfcgi($php_child), "Stopping php");
   77: 	$php_child = -1;
   78: }
   79: 
   80: exit 0;
   81: 
   82: cleanup:
   83: 
   84: $tf_real->endspawnfcgi($php_child) if $php_child != -1;
   85: $tf_real->stop_proc;
   86: $tf_proxy->stop_proc;
   87: 
   88: die();

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