view ssi.t @ 391:915ef26ac6eb

Tests: fix proxy_unfinished.t failures with big buffers. With newer systems it becomes common to use huge socket buffers, and the "no proxy temp" test may unexpectedly fail because disk buffering will not be used. To reduce this possibility, the "listen ... sndbuf=32k" was added. Additionally, regular expression was changed to silently allow full responses.
author Maxim Dounin <mdounin@mdounin.ru>
date Tue, 15 Apr 2014 22:04:08 +0400
parents 4ac3588485f5
children 847ea345becb
line wrap: on
line source

#!/usr/bin/perl

# (C) Maxim Dounin

# Tests for nginx ssi module.

###############################################################################

use warnings;
use strict;

use Test::More;

BEGIN { use FindBin; chdir($FindBin::Bin); }

use lib 'lib';
use Test::Nginx;

###############################################################################

select STDERR; $| = 1;
select STDOUT; $| = 1;

plan(skip_all => 'win32') if $^O eq 'MSWin32';

my $t = Test::Nginx->new()->has(qw/http ssi cache proxy rewrite/)->plan(27);

$t->write_file_expand('nginx.conf', <<'EOF');

%%TEST_GLOBALS%%

daemon off;

events {
}

http {
    %%TEST_GLOBALS_HTTP%%

    proxy_cache_path       %%TESTDIR%%/cache levels=1:2
                           keys_zone=NAME:10m;

    server {
        listen       127.0.0.1:8080;
        server_name  localhost;

        if ($args = "found") {
            return 204;
        }

        location / {
            ssi on;
        }
        location /proxy/ {
            ssi on;
            proxy_pass http://127.0.0.1:8080/local/;
        }
        location /cache/ {
            proxy_pass http://127.0.0.1:8080/local/;
            proxy_cache NAME;
            proxy_cache_valid 200 1h;
        }
        location /local/ {
            ssi off;
            alias %%TESTDIR%%/;
        }
        location /var {
            ssi on;
            add_header X-Var $date_gmt;
        }
        location /var_noformat {
            ssi on;
            add_header X-Var $date_gmt;
            return 200;
        }
        location /var_nossi {
            add_header X-Var $date_gmt;
            return 200;
        }
    }
}

EOF

$t->write_file('test1.html', 'X<!--#echo var="arg_test" -->X');
$t->write_file('test2.html',
	'X<!--#include virtual="/test1.html?test=test" -->X');
$t->write_file('test3.html',
	'X<!--#set var="blah" value="test" --><!--#echo var="blah" -->X');
$t->write_file('test-args-rewrite.html',
	'X<!--#include virtual="/check?found" -->X');
$t->write_file('test-empty1.html', 'X<!--#include virtual="/empty.html" -->X');
$t->write_file('test-empty2.html',
	'X<!--#include virtual="/local/empty.html" -->X');
$t->write_file('test-empty3.html',
	'X<!--#include virtual="/cache/empty.html" -->X');
$t->write_file('empty.html', '');

$t->write_file('unescape.html?', 'SEE-THIS');
$t->write_file('unescape1.html',
	'X<!--#include virtual="/tes%741.html?test=test" -->X');
$t->write_file('unescape2.html',
	'X<!--#include virtual="/unescape.html%3f" -->X');
$t->write_file('unescape3.html',
	'X<!--#include virtual="/test1.html%3ftest=test" -->X');

$t->write_file('var_format.html',
	'x<!--#if expr="$arg_custom" -->'
		. '<!--#config timefmt="%A, %H:%M:%S" -->'
		. '<!--#set var="v" value="$date_gmt" -->'
		. '<!--#echo var="v" -->'
	. '<!--#else -->'
		. '<!--#set var="v" value="$date_gmt" -->'
		. '<!--#echo var="v" -->'
	. '<!--#endif -->x');

$t->run();

###############################################################################

like(http_get('/test1.html'), qr/^X\(none\)X$/m, 'echo no argument');
like(http_get('/test1.html?test='), qr/^XX$/m, 'empty argument');
like(http_get('/test1.html?test=test'), qr/^XtestX$/m, 'argument');
like(http_get('/test1.html?test=test&a=b'), qr/^XtestX$/m, 'argument 2');
like(http_get('/test1.html?a=b&test=test'), qr/^XtestX$/m, 'argument 3');
like(http_get('/test1.html?a=b&test=test&d=c'), qr/^XtestX$/m, 'argument 4');
like(http_get('/test1.html?atest=a&testb=b&ctestc=c&test=test'), qr/^XtestX$/m,
	'argument 5');

like(http_get('/test2.html'), qr/^XXtestXX$/m, 'argument via include');

like(http_get('/test3.html'), qr/^XtestX$/m, 'set');

# args should be in subrequest even if original request has no args and that
# was queried somehow (e.g. by server rewrites)

like(http_get('/test-args-rewrite.html'), qr/^XX$/m, 'args only subrequest');

like(http_get('/test-args-rewrite.html?wasargs'), qr/^XX$/m,
	'args was in main request');

# Last-Modified and Accept-Ranges headers should be cleared

unlike(http_get('/test1.html'), qr/Last-Modified|Accept-Ranges/im,
	'cleared headers');
unlike(http_get('/proxy/test1.html'), qr/Last-Modified|Accept-Ranges/im,
	'cleared headers from proxy');

like(http_get('/test-empty1.html'), qr/HTTP/, 'empty with ssi');
like(http_get('/test-empty2.html'), qr/HTTP/, 'empty without ssi');
like(http_get('/test-empty3.html'), qr/HTTP/, 'empty with proxy');
like(http_get('/test-empty3.html'), qr/HTTP/, 'empty with proxy cached');

# handling of escaped URIs

like(http_get('/unescape1.html'), qr/^XXtestXX$/m, 'escaped in path');

TODO: {
local $TODO = 'not yet' unless $t->has_version('1.5.9');

like(http_get('/unescape2.html'), qr/^XSEE-THISX$/m,
	'escaped question in path');
like(http_get('/unescape3.html'), qr/404 Not Found/,
	'escaped query separator');

}

# handling of embedded date variables

TODO: {
local $TODO = 'not yet' unless $t->has_version('1.5.10');

like(http_get('/var_nossi.html'),
	qr/X-Var: \w+, \d\d-\w{3}-\d{4} \d\d:\d\d:\d\d \w+/, 'no ssi');
like(http_get('/var_noformat.html'),
	qr/X-Var: \w+, \d\d-\w{3}-\d{4} \d\d:\d\d:\d\d \w+/, 'no format');

like(http_get('/var_format.html?custom=1'),
	qr/X-Var: \w+, \d\d-\w{3}-\d{4} \d\d:\d\d:\d\d \w+/, 'custom header');
like(http_get('/var_format.html'),
	qr/X-Var: \w+, \d\d-\w{3}-\d{4} \d\d:\d\d:\d\d \w+/, 'default header');

}

like(http_get('/var_format.html?custom=1'),
	qr/x\w+, \d\d:\d\d:\d\dx/, 'custom ssi');
like(http_get('/var_format.html'),
	qr/x\w+, \d\d-\w{3}-\d{4} \d\d:\d\d:\d\d \w+x/, 'default ssi');

like(`grep -F '[alert]' ${\($t->testdir())}/error.log`, qr/^$/s, 'no alerts');

###############################################################################