ssi.t 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #!/usr/bin/perl
  2. # (C) Maxim Dounin
  3. # Tests for nginx ssi 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 ssi cache proxy rewrite/)->plan(18);
  15. $t->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. proxy_cache_path %%TESTDIR%%/cache levels=1:2
  24. keys_zone=NAME:10m;
  25. server {
  26. listen 127.0.0.1:8080;
  27. server_name localhost;
  28. if ($args = "found") {
  29. return 204;
  30. }
  31. location / {
  32. ssi on;
  33. }
  34. location /proxy/ {
  35. ssi on;
  36. proxy_pass http://127.0.0.1:8080/local/;
  37. }
  38. location /cache/ {
  39. proxy_pass http://127.0.0.1:8080/local/;
  40. proxy_cache NAME;
  41. proxy_cache_valid 200 1h;
  42. }
  43. location /local/ {
  44. ssi off;
  45. alias %%TESTDIR%%/;
  46. }
  47. }
  48. }
  49. EOF
  50. $t->write_file('test1.html', 'X<!--#echo var="arg_test" -->X');
  51. $t->write_file('test2.html',
  52. 'X<!--#include virtual="/test1.html?test=test" -->X');
  53. $t->write_file('test3.html',
  54. 'X<!--#set var="blah" value="test" --><!--#echo var="blah" -->X');
  55. $t->write_file('test-args-rewrite.html',
  56. 'X<!--#include virtual="/check?found" -->X');
  57. $t->write_file('test-empty1.html', 'X<!--#include virtual="/empty.html" -->X');
  58. $t->write_file('test-empty2.html',
  59. 'X<!--#include virtual="/local/empty.html" -->X');
  60. $t->write_file('test-empty3.html',
  61. 'X<!--#include virtual="/cache/empty.html" -->X');
  62. $t->write_file('empty.html', '');
  63. $t->run();
  64. ###############################################################################
  65. like(http_get('/test1.html'), qr/^X\(none\)X$/m, 'echo no argument');
  66. like(http_get('/test1.html?test='), qr/^XX$/m, 'empty argument');
  67. like(http_get('/test1.html?test=test'), qr/^XtestX$/m, 'argument');
  68. like(http_get('/test1.html?test=test&a=b'), qr/^XtestX$/m, 'argument 2');
  69. like(http_get('/test1.html?a=b&test=test'), qr/^XtestX$/m, 'argument 3');
  70. like(http_get('/test1.html?a=b&test=test&d=c'), qr/^XtestX$/m, 'argument 4');
  71. like(http_get('/test1.html?atest=a&testb=b&ctestc=c&test=test'), qr/^XtestX$/m,
  72. 'argument 5');
  73. like(http_get('/test2.html'), qr/^XXtestXX$/m, 'argument via include');
  74. like(http_get('/test3.html'), qr/^XtestX$/m, 'set');
  75. # args should be in subrequest even if original request has no args and that
  76. # was queried somehow (e.g. by server rewrites)
  77. TODO: {
  78. local $TODO = 'patch under review';
  79. like(http_get('/test-args-rewrite.html'), qr/^XX$/m, 'args only subrequest');
  80. }
  81. like(http_get('/test-args-rewrite.html?wasargs'), qr/^XX$/m,
  82. 'args was in main request');
  83. # Last-Modified and Accept-Ranges headers should be cleared
  84. unlike(http_get('/test1.html'), qr/Last-Modified|Accept-Ranges/im,
  85. 'cleared headers');
  86. unlike(http_get('/proxy/test1.html'), qr/Last-Modified|Accept-Ranges/im,
  87. 'cleared headers from proxy');
  88. like(http_get('/test-empty1.html'), qr/HTTP/, 'empty with ssi');
  89. like(http_get('/test-empty2.html'), qr/HTTP/, 'empty without ssi');
  90. like(http_get('/test-empty3.html'), qr/HTTP/, 'empty with proxy');
  91. like(http_get('/test-empty3.html'), qr/HTTP/, 'empty with proxy cached');
  92. like(`grep -F '[alert]' ${\($t->testdir())}/error.log`, qr/^$/s, 'no alerts');
  93. ###############################################################################