mod-proxy.t 2.2 KB

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