mod-fastcgi.t 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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 Test::More tests => 24;
  10. use LightyTest;
  11. my $tf = LightyTest->new();
  12. my $t;
  13. SKIP: {
  14. skip "no fcgi-responder found", 24
  15. unless ( -x $tf->{BASEDIR}."/tests/fcgi-responder"
  16. || -x $tf->{BASEDIR}."/tests/fcgi-responder.exe");
  17. my $ephemeral_port = LightyTest->get_ephemeral_tcp_port();
  18. $ENV{EPHEMERAL_PORT} = $ephemeral_port;
  19. $tf->{CONFIGFILE} = 'fastcgi-responder.conf';
  20. ok($tf->start_proc == 0, "Starting lighttpd with $tf->{CONFIGFILE}") or die();
  21. $t->{REQUEST} = ( <<EOF
  22. GET /prefix.fcgi-nonexistent HTTP/1.0
  23. Host: www.example.org
  24. EOF
  25. );
  26. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ];
  27. ok($tf->handle_http($t) == 0, 'file not found');
  28. $t->{REQUEST} = ( <<EOF
  29. GET /prefix.fcgi?env=SCRIPT_NAME HTTP/1.0
  30. EOF
  31. );
  32. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/prefix.fcgi' } ];
  33. ok($tf->handle_http($t) == 0, 'SCRIPT_NAME');
  34. $t->{REQUEST} = ( <<EOF
  35. GET /prefix.fcgi/foo/bar?env=SCRIPT_NAME HTTP/1.0
  36. EOF
  37. );
  38. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/prefix.fcgi' } ];
  39. ok($tf->handle_http($t) == 0, 'SCRIPT_NAME w/ PATH_INFO');
  40. $t->{REQUEST} = ( <<EOF
  41. GET /prefix.fcgi/foo/bar?env=PATH_INFO HTTP/1.0
  42. EOF
  43. );
  44. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/foo/bar' } ];
  45. ok($tf->handle_http($t) == 0, 'PATH_INFO');
  46. $t->{REQUEST} = ( <<EOF
  47. GET /phpinfo.php HTTP/1.0
  48. Host: www.example.org
  49. EOF
  50. );
  51. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
  52. ok($tf->handle_http($t) == 0, 'valid request');
  53. $t->{REQUEST} = ( <<EOF
  54. GET /get-server-env.php?env=USER HTTP/1.0
  55. Host: bin-env.example.org
  56. EOF
  57. );
  58. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 , 'HTTP-Content' => $ENV{USER} } ];
  59. ok($tf->handle_http($t) == 0, 'FastCGI + bin-copy-environment');
  60. $t->{REQUEST} = ( <<EOF
  61. GET /get-server-env.php?env=MAIL HTTP/1.0
  62. Host: bin-env.example.org
  63. EOF
  64. );
  65. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 , 'HTTP-Content' => '' } ];
  66. ok($tf->handle_http($t) == 0, 'FastCGI + bin-copy-environment');
  67. SKIP: {
  68. skip "no crypt-des under openbsd", 2 if $^O eq 'openbsd';
  69. $t->{REQUEST} = ( <<EOF
  70. GET /get-server-env.php?env=REMOTE_USER HTTP/1.0
  71. Host: auth.example.org
  72. Authorization: Basic ZGVzOmRlcw==
  73. EOF
  74. );
  75. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'des' } ];
  76. ok($tf->handle_http($t) == 0, '$_SERVER["REMOTE_USER"]');
  77. $t->{REQUEST} = ( <<EOF
  78. GET /get-server-env.php?env=AUTH_TYPE HTTP/1.0
  79. Host: auth.example.org
  80. Authorization: Basic ZGVzOmRlcw==
  81. EOF
  82. );
  83. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'Basic' } ];
  84. ok($tf->handle_http($t) == 0, '$_SERVER["AUTH_TYPE"]');
  85. }
  86. $t->{REQUEST} = ( <<EOF
  87. GET /index.html?auth-ok HTTP/1.0
  88. Host: auth.example.org
  89. EOF
  90. );
  91. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
  92. ok($tf->handle_http($t) == 0, 'FastCGI - Auth');
  93. $t->{REQUEST} = ( <<EOF
  94. GET /index.html?auth-fail HTTP/1.0
  95. Host: auth.example.org
  96. EOF
  97. );
  98. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 403 } ];
  99. ok($tf->handle_http($t) == 0, 'FastCGI - Auth');
  100. $t->{REQUEST} = ( <<EOF
  101. GET /expire/access.txt?auth-ok HTTP/1.0
  102. Host: auth.example.org
  103. EOF
  104. );
  105. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
  106. ok($tf->handle_http($t) == 0, 'FastCGI - Auth in subdirectory');
  107. $t->{REQUEST} = ( <<EOF
  108. GET /index.fcgi?auth-varfail HTTP/1.0
  109. Host: auth.example.org
  110. EOF
  111. );
  112. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 403 } ];
  113. ok($tf->handle_http($t) == 0, 'FastCGI - Auth Fail with FastCGI responder afterwards');
  114. $t->{REQUEST} = ( <<EOF
  115. GET /index.fcgi?auth-var HTTP/1.0
  116. Host: auth.example.org
  117. EOF
  118. );
  119. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'LighttpdTestContent' } ];
  120. ok($tf->handle_http($t) == 0, 'FastCGI - Auth Success with Variable- to Env expansion');
  121. $t->{REQUEST} = ( <<EOF
  122. GET /index.fcgi?lf HTTP/1.0
  123. Host: www.example.org
  124. EOF
  125. );
  126. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } ];
  127. ok($tf->handle_http($t) == 0, 'line-ending \n\n');
  128. $t->{REQUEST} = ( <<EOF
  129. GET /index.fcgi?crlf HTTP/1.0
  130. Host: www.example.org
  131. EOF
  132. );
  133. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } ];
  134. ok($tf->handle_http($t) == 0, 'line-ending \r\n\r\n');
  135. $t->{REQUEST} = ( <<EOF
  136. GET /index.fcgi?slow-lf HTTP/1.0
  137. Host: www.example.org
  138. EOF
  139. );
  140. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } ];
  141. ok($tf->handle_http($t) == 0, 'line-ending \n + \n');
  142. $t->{REQUEST} = ( <<EOF
  143. GET /index.fcgi?slow-crlf HTTP/1.0
  144. Host: www.example.org
  145. EOF
  146. );
  147. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } ];
  148. ok($tf->handle_http($t) == 0, 'line-ending \r\n + \r\n');
  149. $t->{REQUEST} = ( <<EOF
  150. GET /abc/def/ghi?env=PATH_INFO HTTP/1.0
  151. Host: wsgi.example.org
  152. EOF
  153. );
  154. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/abc/def/ghi' } ];
  155. ok($tf->handle_http($t) == 0, 'PATH_INFO (wsgi)');
  156. $t->{REQUEST} = ( <<EOF
  157. GET /abc/def/ghi?env=SCRIPT_NAME HTTP/1.0
  158. Host: wsgi.example.org
  159. EOF
  160. );
  161. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '' } ];
  162. ok($tf->handle_http($t) == 0, 'SCRIPT_NAME (wsgi)');
  163. # skip timing-sensitive test during CI testing, but run for user 'gps'
  164. my $user = `id -un`;
  165. chomp($user) if $user;
  166. if (($user || "") eq "gps") {
  167. $t->{REQUEST} = ( <<EOF
  168. GET /index.fcgi?die-at-end HTTP/1.0
  169. Host: www.example.org
  170. EOF
  171. );
  172. }
  173. else {
  174. $t->{REQUEST} = ( <<EOF
  175. GET /index.fcgi?crlf HTTP/1.0
  176. Host: www.example.org
  177. EOF
  178. );
  179. }
  180. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } ];
  181. ok($tf->handle_http($t) == 0, 'killing fastcgi and wait for restart');
  182. # (might take lighttpd 1 sec to detect backend exit)
  183. for (my $c = 2*30; $c && 0 == $tf->listening_on($ephemeral_port); --$c) {
  184. select(undef, undef, undef, 0.05);
  185. }
  186. $t->{REQUEST} = ( <<EOF
  187. GET /index.fcgi?crlf HTTP/1.0
  188. Host: www.example.org
  189. EOF
  190. );
  191. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } ];
  192. ok($tf->handle_http($t) == 0, 'regular response of after restart');
  193. ok($tf->stop_proc == 0, "Stopping lighttpd");
  194. }