mod-scgi.t 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 => 10;
  10. use LightyTest;
  11. my $tf = LightyTest->new();
  12. my $t;
  13. SKIP: {
  14. skip "no scgi-responder found", 10 unless -x $tf->{BASEDIR}."/tests/scgi-responder" || -x $tf->{BASEDIR}."/tests/scgi-responder.exe";
  15. my $ephemeral_port = LightyTest->get_ephemeral_tcp_port();
  16. $ENV{EPHEMERAL_PORT} = $ephemeral_port;
  17. $tf->{CONFIGFILE} = 'scgi-responder.conf';
  18. ok($tf->start_proc == 0, "Starting lighttpd with $tf->{CONFIGFILE}") or die();
  19. $t->{REQUEST} = ( <<EOF
  20. GET /index.scgi?lf HTTP/1.0
  21. Host: www.example.org
  22. EOF
  23. );
  24. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } ];
  25. ok($tf->handle_http($t) == 0, 'line-ending \n\n');
  26. $t->{REQUEST} = ( <<EOF
  27. GET /index.scgi?crlf HTTP/1.0
  28. Host: www.example.org
  29. EOF
  30. );
  31. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } ];
  32. ok($tf->handle_http($t) == 0, 'line-ending \r\n\r\n');
  33. $t->{REQUEST} = ( <<EOF
  34. GET /index.scgi?slow-lf HTTP/1.0
  35. Host: www.example.org
  36. EOF
  37. );
  38. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } ];
  39. ok($tf->handle_http($t) == 0, 'line-ending \n + \n');
  40. $t->{REQUEST} = ( <<EOF
  41. GET /index.scgi?slow-crlf HTTP/1.0
  42. Host: www.example.org
  43. EOF
  44. );
  45. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } ];
  46. ok($tf->handle_http($t) == 0, 'line-ending \r\n + \r\n');
  47. $t->{REQUEST} = ( <<EOF
  48. GET /abc/def/ghi?env=PATH_INFO HTTP/1.0
  49. Host: wsgi.example.org
  50. EOF
  51. );
  52. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/abc/def/ghi' } ];
  53. ok($tf->handle_http($t) == 0, 'PATH_INFO (wsgi)');
  54. $t->{REQUEST} = ( <<EOF
  55. GET /abc/def/ghi?env=SCRIPT_NAME HTTP/1.0
  56. Host: wsgi.example.org
  57. EOF
  58. );
  59. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '' } ];
  60. ok($tf->handle_http($t) == 0, 'SCRIPT_NAME (wsgi)');
  61. # skip timing-sensitive test during CI testing, but run for user 'gps'
  62. my $user = `id -un`;
  63. chomp($user) if $user;
  64. if (($user || "") eq "gps") {
  65. $t->{REQUEST} = ( <<EOF
  66. GET /index.scgi?die-at-end HTTP/1.0
  67. Host: www.example.org
  68. EOF
  69. );
  70. }
  71. else {
  72. $t->{REQUEST} = ( <<EOF
  73. GET /index.scgi?crlf HTTP/1.0
  74. Host: www.example.org
  75. EOF
  76. );
  77. }
  78. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } ];
  79. ok($tf->handle_http($t) == 0, 'killing scgi and wait for restart');
  80. # (might take lighttpd 1 sec to detect backend exit)
  81. for (my $c = 2*30; $c && 0 == $tf->listening_on($ephemeral_port); --$c) {
  82. select(undef, undef, undef, 0.05);
  83. }
  84. $t->{REQUEST} = ( <<EOF
  85. GET /index.scgi?crlf HTTP/1.0
  86. Host: www.example.org
  87. EOF
  88. );
  89. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } ];
  90. ok($tf->handle_http($t) == 0, 'regular response of after restart');
  91. ok($tf->stop_proc == 0, "Stopping lighttpd");
  92. }