mod-rewrite.t 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 => 8;
  11. use LightyTest;
  12. my $tf = LightyTest->new();
  13. my $t;
  14. my $php_child = -1;
  15. my $phpbin = (defined $ENV{'PHP'} ? $ENV{'PHP'} : '/usr/bin/php-cgi');
  16. SKIP: {
  17. skip "PHP already running on port 1026", 1 if $tf->listening_on(1026);
  18. skip "no php binary found", 1 unless -x $phpbin;
  19. ok(-1 != ($php_child = $tf->spawnfcgi($phpbin, 1026)), "Spawning php");
  20. }
  21. SKIP: {
  22. skip "no PHP running on port 1026", 6 unless $tf->listening_on(1026);
  23. ok($tf->start_proc == 0, "Starting lighttpd") or goto cleanup;
  24. $t->{REQUEST} = ( <<EOF
  25. GET /rewrite/foo HTTP/1.0
  26. Host: www.example.org
  27. EOF
  28. );
  29. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '' } ];
  30. ok($tf->handle_http($t) == 0, 'valid request');
  31. $t->{REQUEST} = ( <<EOF
  32. GET /rewrite/foo?a=b HTTP/1.0
  33. Host: www.example.org
  34. EOF
  35. );
  36. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'a=b' } ];
  37. ok($tf->handle_http($t) == 0, 'valid request');
  38. $t->{REQUEST} = ( <<EOF
  39. GET /rewrite/bar?a=b HTTP/1.0
  40. Host: www.example.org
  41. EOF
  42. );
  43. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'bar&a=b' } ];
  44. ok($tf->handle_http($t) == 0, 'valid request');
  45. $t->{REQUEST} = ( <<EOF
  46. GET /rewrite/nofile?a=b HTTP/1.0
  47. Host: www.example.org
  48. EOF
  49. );
  50. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'file=/rewrite/nofile&a=b' } ];
  51. ok($tf->handle_http($t) == 0, 'not existing file rewrite');
  52. ok($tf->stop_proc == 0, "Stopping lighttpd");
  53. }
  54. SKIP: {
  55. skip "PHP not started, cannot stop it", 1 unless $php_child != -1;
  56. ok(0 == $tf->endspawnfcgi($php_child), "Stopping php");
  57. }
  58. exit 0;
  59. cleanup: ;
  60. $tf->endspawnfcgi($php_child) if $php_child != -1;
  61. die();