mod-cgi.t 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 => 18;
  11. use LightyTest;
  12. my $tf = LightyTest->new();
  13. my $t;
  14. ok($tf->start_proc == 0, "Starting lighttpd") or die();
  15. # mod-cgi
  16. #
  17. $t->{REQUEST} = ( <<EOF
  18. GET /cgi.pl HTTP/1.0
  19. EOF
  20. );
  21. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
  22. ok($tf->handle_http($t) == 0, 'perl via cgi');
  23. $t->{REQUEST} = ( <<EOF
  24. GET /cgi.pl/foo HTTP/1.0
  25. EOF
  26. );
  27. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/cgi.pl' } ];
  28. ok($tf->handle_http($t) == 0, 'perl via cgi + pathinfo');
  29. $t->{REQUEST} = ( <<EOF
  30. GET /cgi-pathinfo.pl/foo HTTP/1.0
  31. EOF
  32. );
  33. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/foo' } ];
  34. ok($tf->handle_http($t) == 0, 'perl via cgi + pathinfo');
  35. $t->{REQUEST} = ( <<EOF
  36. GET /nph-status.pl?30 HTTP/1.0
  37. EOF
  38. );
  39. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
  40. ok($tf->handle_http($t) == 0, 'NPH + perl, invalid status-code (#14)');
  41. $t->{REQUEST} = ( <<EOF
  42. GET /nph-status.pl?304 HTTP/1.0
  43. EOF
  44. );
  45. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304 } ];
  46. ok($tf->handle_http($t) == 0, 'NPH + perl, setting status-code (#1125)');
  47. $t->{REQUEST} = ( <<EOF
  48. GET /nph-status.pl?200 HTTP/1.0
  49. EOF
  50. );
  51. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
  52. ok($tf->handle_http($t) == 0, 'NPH + perl, setting status-code');
  53. $t->{REQUEST} = ( <<EOF
  54. GET /get-header.pl?GATEWAY_INTERFACE HTTP/1.0
  55. EOF
  56. );
  57. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'CGI/1.1' } ];
  58. ok($tf->handle_http($t) == 0, 'cgi-env: GATEWAY_INTERFACE');
  59. $t->{REQUEST} = ( <<EOF
  60. GET /get-header.pl?QUERY_STRING HTTP/1.0
  61. EOF
  62. );
  63. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'QUERY_STRING' } ];
  64. ok($tf->handle_http($t) == 0, 'cgi-env: QUERY_STRING');
  65. $t->{REQUEST} = ( <<EOF
  66. GET /get-header.pl?GATEWAY_INTERFACE HTTP/1.0
  67. EOF
  68. );
  69. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'CGI/1.1' } ];
  70. ok($tf->handle_http($t) == 0, 'cgi-env: GATEWAY_INTERFACE');
  71. $t->{REQUEST} = ( <<EOF
  72. GET /get-header.pl?HTTP_HOST HTTP/1.0
  73. Host: www.example.org
  74. EOF
  75. );
  76. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'www.example.org' } ];
  77. ok($tf->handle_http($t) == 0, 'cgi-env: HTTP_HOST');
  78. $t->{REQUEST} = ( <<EOF
  79. GET /get-header.pl?HTTP_XX_YY123 HTTP/1.0
  80. xx-yy123: foo
  81. EOF
  82. );
  83. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'foo' } ];
  84. ok($tf->handle_http($t) == 0, 'cgi-env: quoting headers with numbers');
  85. $t->{REQUEST} = ( <<EOF
  86. GET /get-header.pl?HTTP_HOST HTTP/1.0
  87. Host: www.example.org
  88. EOF
  89. );
  90. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'www.example.org' } ];
  91. ok($tf->handle_http($t) == 0, 'cgi-env: HTTP_HOST');
  92. $t->{REQUEST} = ( <<EOF
  93. GET /get-header.pl?HTTP_HOST HTTP/1.0
  94. Host: www.example.org
  95. EOF
  96. );
  97. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'www.example.org' } ];
  98. ok($tf->handle_http($t) == 0, 'cgi-env: HTTP_HOST');
  99. $t->{REQUEST} = ( <<EOF
  100. GET /get-header.pl?HTTP_HOST HTTP/1.0
  101. Host: www.example.org
  102. EOF
  103. );
  104. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'Content-Type' => 'text/plain' } ];
  105. ok($tf->handle_http($t) == 0, 'cgi-env: HTTP_HOST');
  106. $t->{REQUEST} = ( <<EOF
  107. GET /get-header.pl?HTTP_HOST HTTP/1.1
  108. Host: www.example.org
  109. Connection: close
  110. EOF
  111. );
  112. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 200, '+Content-Length' => '' } ];
  113. ok($tf->handle_http($t) == 0, 'cgi-env: HTTP_HOST');
  114. # broken header crash
  115. $t->{REQUEST} = ( <<EOF
  116. GET /crlfcrash.pl HTTP/1.0
  117. EOF
  118. );
  119. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 302, 'Location' => 'http://www.example.org/' } ];
  120. ok($tf->handle_http($t) == 0, 'broken header via perl cgi');
  121. ok($tf->stop_proc == 0, "Stopping lighttpd");