core-404-handler.t 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/usr/bin/env perl
  2. #
  3. # combinations we have to test:
  4. # plain 404 case
  5. # 404-handler -> static file (verify content)
  6. # 404-handler -> fastcgi
  7. # returning 200
  8. # returning 302 + Location
  9. # returning 404
  10. # returning no status -> 200
  11. #
  12. BEGIN {
  13. # add current source dir to the include-path
  14. # we need this for make distcheck
  15. (my $srcdir = $0) =~ s,/[^/]+$,/,;
  16. unshift @INC, $srcdir;
  17. }
  18. use strict;
  19. use IO::Socket;
  20. use Test::More tests => 8;
  21. use LightyTest;
  22. my $tf = LightyTest->new();
  23. my $t;
  24. $tf->{CONFIGFILE} = '404-handler.conf';
  25. ok($tf->start_proc == 0, "Starting lighttpd") or die();
  26. $t->{REQUEST} = ( <<EOF
  27. GET /static/notfound HTTP/1.0
  28. EOF
  29. );
  30. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => "static not found\n" } ];
  31. ok($tf->handle_http($t) == 0, '404 handler => static');
  32. #
  33. #
  34. #
  35. $t->{REQUEST} = ( <<EOF
  36. GET /dynamic/200/notfound HTTP/1.0
  37. EOF
  38. );
  39. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => "found here\n" } ];
  40. ok($tf->handle_http($t) == 0, '404 handler => dynamic(200)');
  41. $t->{REQUEST} = ( <<EOF
  42. GET /dynamic/302/notfound HTTP/1.0
  43. EOF
  44. );
  45. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 302, 'Location' => "http://www.example.org/" } ];
  46. ok($tf->handle_http($t) == 0, '404 handler => dynamic(302)');
  47. $t->{REQUEST} = ( <<EOF
  48. GET /dynamic/404/notfound HTTP/1.0
  49. EOF
  50. );
  51. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404, 'HTTP-Content' => "Not found here\n" } ];
  52. ok($tf->handle_http($t) == 0, '404 handler => dynamic(404)');
  53. $t->{REQUEST} = ( <<EOF
  54. GET /dynamic/nostatus/notfound HTTP/1.0
  55. EOF
  56. );
  57. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => "found here\n" } ];
  58. ok($tf->handle_http($t) == 0, '404 handler => dynamic(nostatus)');
  59. $t->{REQUEST} = ( <<EOF
  60. GET /send404.pl HTTP/1.0
  61. EOF
  62. );
  63. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404, 'HTTP-Content' => "send404\n" } ];
  64. ok($tf->handle_http($t) == 0, '404 generated by CGI should stay 404');
  65. ok($tf->stop_proc == 0, "Stopping lighttpd");