autoindex.t 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #!/usr/bin/perl
  2. # (C) Maxim Dounin
  3. # Tests for autoindex module.
  4. ###############################################################################
  5. use warnings;
  6. use strict;
  7. use Test::More;
  8. BEGIN { use FindBin; chdir($FindBin::Bin); }
  9. use lib 'lib';
  10. use Test::Nginx;
  11. ###############################################################################
  12. select STDERR; $| = 1;
  13. select STDOUT; $| = 1;
  14. my $t = Test::Nginx->new()->has(qw/http autoindex/)->plan(16)
  15. ->write_file_expand('nginx.conf', <<'EOF');
  16. %%TEST_GLOBALS%%
  17. master_process off;
  18. daemon off;
  19. events {
  20. }
  21. http {
  22. %%TEST_GLOBALS_HTTP%%
  23. server {
  24. listen 127.0.0.1:8080;
  25. server_name localhost;
  26. location / {
  27. autoindex on;
  28. }
  29. location /utf8/ {
  30. autoindex on;
  31. charset utf-8;
  32. }
  33. }
  34. }
  35. EOF
  36. my $d = $t->testdir();
  37. mkdir("$d/test-dir");
  38. symlink("$d/test-dir", "$d/test-dir-link");
  39. $t->write_file('test-file', '');
  40. symlink("$d/test-file", "$d/test-file-link");
  41. $t->write_file('test-colon:blah', '');
  42. $t->write_file('test-long-' . ('0' x 50), '');
  43. $t->write_file('test-long-' . ('>' x 50), '');
  44. $t->write_file('test-escape-url-%', '');
  45. $t->write_file('test-escape-url2-?', '');
  46. $t->write_file('test-escape-html-<>&', '');
  47. mkdir($d . '/utf8');
  48. $t->write_file('utf8/test-utf8-' . ("\xd1\x84" x 3), '');
  49. $t->write_file('utf8/test-utf8-' . ("\xd1\x84" x 45), '');
  50. $t->write_file('utf8/test-utf8-<>&-' . "\xd1\x84", '');
  51. $t->write_file('utf8/test-utf8-<>&-' . ("\xd1\x84" x 45), '');
  52. $t->write_file('utf8/test-utf8-' . ("\xd1\x84" x 3) . '-' . ('>' x 45), '');
  53. mkdir($d . '/test-dir-escape-<>&');
  54. $t->run();
  55. ###############################################################################
  56. my $r = http_get('/');
  57. like($r, qr!href="test-file"!ms, 'file');
  58. like($r, qr!href="test-file-link"!ms, 'symlink to file');
  59. like($r, qr!href="test-dir/"!ms, 'directory');
  60. like($r, qr!href="test-dir-link/"!ms, 'symlink to directory');
  61. unlike($r, qr!href="test-colon:blah"!ms, 'colon not scheme');
  62. like($r, qr!test-long-0{37}\.\.&gt;!ms, 'long name');
  63. like($r, qr!href="test-escape-url-%25"!ms, 'escaped url');
  64. {
  65. local $TODO = 'not fixed yet';
  66. like($r, qr!href="test-escape-url2-%3f"!ms, 'escaped ? in url');
  67. }
  68. {
  69. local $TODO = 'patch under review';
  70. like($r, qr!test-escape-html-&lt;&gt;&amp;!ms, 'escaped html');
  71. like($r, qr!test-long-(&gt;){37}\.\.&gt;!ms, 'long escaped html');
  72. }
  73. $r = http_get('/utf8/');
  74. like($r, qr!test-utf8-(\xd1\x84){3}</a>!ms, 'utf8');
  75. like($r, qr!test-utf8-(\xd1\x84){37}\.\.!ms, 'utf8 long');
  76. {
  77. local $TODO = 'patch under review';
  78. like($r, qr!test-utf8-&lt;&gt;&amp;-\xd1\x84</a>!ms, 'utf8 escaped');
  79. like($r, qr!test-utf8-&lt;&gt;&amp;-(\xd1\x84){33}\.\.!ms,
  80. 'utf8 escaped long');
  81. like($r, qr!test-utf8-(\xd1\x84){3}-(&gt;){33}\.\.!ms, 'utf8 long escaped');
  82. like(http_get('/test-dir-escape-<>&/'), qr!test-dir-escape-&lt;&gt;&amp;!ms,
  83. 'escaped title');
  84. }
  85. ###############################################################################