lighttpd 1.4.x https://www.lighttpd.net/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

122 lines
3.5 KiB

  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 => 14;
  11. use LightyTest;
  12. my $tf = LightyTest->new();
  13. my $t;
  14. ok($tf->start_proc == 0, "Starting lighttpd") or die();
  15. ## Low-Level Response-Header Parsing - HTTP/1.1
  16. $t->{REQUEST} = ( <<EOF
  17. GET / HTTP/1.1
  18. Host: www.example.org
  19. Connection: close
  20. EOF
  21. );
  22. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 200, '+Date' => '' } ];
  23. ok($tf->handle_http($t) == 0, 'Date header');
  24. $t->{REQUEST} = ( <<EOF
  25. GET / HTTP/1.1
  26. EOF
  27. );
  28. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 400, 'Connection' => 'close' } ];
  29. ok($tf->handle_http($t) == 0, 'Host missing');
  30. $t->{REQUEST} = ( <<EOF
  31. GET / HTTP/1.0
  32. EOF
  33. );
  34. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, '+ETag' => '' } ];
  35. ok($tf->handle_http($t) == 0, 'ETag is set');
  36. $t->{REQUEST} = ( <<EOF
  37. GET / HTTP/1.0
  38. EOF
  39. );
  40. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'ETag' => '/^".+"$/' } ];
  41. ok($tf->handle_http($t) == 0, 'ETag has quotes');
  42. ## Low-Level Response-Header Parsing - Content-Length
  43. $t->{REQUEST} = ( <<EOF
  44. GET /12345.html HTTP/1.0
  45. Host: 123.example.org
  46. EOF
  47. );
  48. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'Content-Length' => '6' } ];
  49. ok($tf->handle_http($t) == 0, 'Content-Length for text/html');
  50. $t->{REQUEST} = ( <<EOF
  51. GET /12345.txt HTTP/1.0
  52. Host: 123.example.org
  53. EOF
  54. );
  55. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'Content-Length' => '6' } ];
  56. ok($tf->handle_http($t) == 0, 'Content-Length for text/plain');
  57. ## Low-Level Response-Header Parsing - Location
  58. $t->{REQUEST} = ( <<EOF
  59. GET /dummydir HTTP/1.0
  60. EOF
  61. );
  62. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => 'http://'.$tf->{HOSTNAME}.':'.$tf->{PORT}.'/dummydir/' } ];
  63. ok($tf->handle_http($t) == 0, 'internal redirect in directory');
  64. $t->{REQUEST} = ( <<EOF
  65. GET /dummydir?foo HTTP/1.0
  66. EOF
  67. );
  68. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => 'http://'.$tf->{HOSTNAME}.':'.$tf->{PORT}.'/dummydir/?foo' } ];
  69. ok($tf->handle_http($t) == 0, 'internal redirect in directory + querystring');
  70. $t->{REQUEST} = ( <<EOF
  71. GET /~test%20ä_ HTTP/1.0
  72. EOF
  73. );
  74. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => 'http://'.$tf->{HOSTNAME}.':'.$tf->{PORT}.'/~test%20%c3%a4_/' } ];
  75. ok($tf->handle_http($t) == 0, 'internal redirect in directory with special characters');
  76. $t->{REQUEST} = ( <<EOF
  77. GET /~test%20ä_?foo HTTP/1.0
  78. EOF
  79. );
  80. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => 'http://'.$tf->{HOSTNAME}.':'.$tf->{PORT}.'/~test%20%c3%a4_/?foo' } ];
  81. ok($tf->handle_http($t) == 0, 'internal redirect in directory with special characters + querystring');
  82. ## simple-vhost
  83. $t->{REQUEST} = ( <<EOF
  84. GET /12345.txt HTTP/1.0
  85. Host: no-simple.example.org
  86. EOF
  87. );
  88. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'Content-Length' => '6' } ];
  89. ok($tf->handle_http($t) == 0, 'disabling simple-vhost via conditionals');
  90. $t->{REQUEST} = ( <<EOF
  91. GET /12345.txt HTTP/1.0
  92. Host: simple.example.org
  93. EOF
  94. );
  95. $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ];
  96. ok($tf->handle_http($t) == 0, 'simple-vhost via conditionals');
  97. ok($tf->stop_proc == 0, "Stopping lighttpd");