comparison ssi-include-big.t @ 39:fc205d0e052d

Tests: check content returned from ssi tests. Since replies are gzipped, IO::Uncompress::Gunzip required for this (if not installed tests are skipped). This should catch truncated replies as fixed in nginx 0.7.4.
author Maxim Dounin <mdounin@mdounin.ru>
date Sat, 01 Nov 2008 03:29:34 +0300
parents 7bf0e8a1d66c
children d68b85def521
comparison
equal deleted inserted replaced
38:9a7158a8609a 39:fc205d0e052d
19 ############################################################################### 19 ###############################################################################
20 20
21 select STDERR; $| = 1; 21 select STDERR; $| = 1;
22 select STDOUT; $| = 1; 22 select STDOUT; $| = 1;
23 23
24 my $t = Test::Nginx->new()->has('rewrite')->plan(3); 24 my $t = Test::Nginx->new()->has('rewrite')->plan(8);
25 25
26 $t->write_file_expand('nginx.conf', <<'EOF'); 26 $t->write_file_expand('nginx.conf', <<'EOF');
27 27
28 master_process off; 28 master_process off;
29 daemon off; 29 daemon off;
60 EOF 60 EOF
61 61
62 $t->write_file('c1.html', 'X' x 1023); 62 $t->write_file('c1.html', 'X' x 1023);
63 $t->write_file('c2.html', 'X' x 1024); 63 $t->write_file('c2.html', 'X' x 1024);
64 $t->write_file('c3.html', 'X' x 1025); 64 $t->write_file('c3.html', 'X' x 1025);
65 $t->write_file('test1.html', '<!--#include virtual="/proxy/blah" -->' . "\n" 65 $t->write_file('test1.html', '<!--#include virtual="/proxy/blah" -->'
66 . '<!--#include virtual="/c1.html" -->'); 66 . '<!--#include virtual="/c1.html" -->');
67 $t->write_file('test2.html', '<!--#include virtual="/proxy/blah" -->' . "\n" 67 $t->write_file('test2.html', '<!--#include virtual="/proxy/blah" -->'
68 . '<!--#include virtual="/c2.html" -->'); 68 . '<!--#include virtual="/c2.html" -->');
69 $t->write_file('test3.html', '<!--#include virtual="/proxy/blah" -->' . "\n" 69 $t->write_file('test3.html', '<!--#include virtual="/proxy/blah" -->'
70 . '<!--#include virtual="/c3.html" -->'); 70 . '<!--#include virtual="/c3.html" -->');
71 $t->write_file('test4.html', '<!--#include virtual="/proxy/blah" -->'
72 . ('X' x 1025));
71 73
72 $t->run(); 74 $t->run();
73 75
74 ############################################################################### 76 ###############################################################################
75 77
76 my $t1 = http_gzip_request('/test1.html'); 78 my $t1 = http_gzip_request('/test1.html');
77 ok(defined $t1, 'small included file (less than output_buffers)'); 79 ok(defined $t1, 'small included file (less than output_buffers)');
80 http_gzip_like($t1, qr/^X{1023}\Z/, 'small included file content');
78 81
79 my $t2 = http_gzip_request('/test2.html'); 82 my $t2 = http_gzip_request('/test2.html');
80 ok(defined $t2, 'small included file (equal to output_buffers)'); 83 ok(defined $t2, 'small included file (equal to output_buffers)');
84 http_gzip_like($t2, qr/^X{1024}\Z/, 'small included file content');
81 85
82 TODO: { 86 TODO: {
83 local $TODO = 'not fixed yet, patch under review'; 87 local $TODO = 'not fixed yet, patch under review';
84 88
85 my $t3 = http_gzip_request('/test3.html'); 89 my $t3 = http_gzip_request('/test3.html');
86 ok(defined $t3, 'big included file (more than output_buffers)'); 90 ok(defined $t3, 'big included file (more than output_buffers)');
91 http_gzip_like($t3, qr/^X{1025}\Z/, 'big included file content');
87 92
88 } 93 }
94
95 my $t4 = http_gzip_request('/test4.html');
96 ok(defined $t4, 'big ssi main file');
97 http_gzip_like($t4, qr/^X{1025}\Z/, 'big ssi main file content');
98
89 99
90 ############################################################################### 100 ###############################################################################
91 101
92 sub http_gzip_request { 102 sub http_gzip_request {
93 my ($url) = @_; 103 my ($url) = @_;
98 Accept-Encoding: gzip 108 Accept-Encoding: gzip
99 109
100 EOF 110 EOF
101 } 111 }
102 112
113 sub http_content {
114 my ($text) = @_;
115
116 return undef if !defined $text;
117
118 if ($text !~ /(.*?)\x0d\x0a?\x0d\x0a?(.*)/ms) {
119 return undef;
120 }
121
122 my ($headers, $body) = ($1, $2);
123
124 if ($headers !~ /Transfer-Encoding: chunked/i) {
125 return $body;
126 }
127
128 my $content = '';
129 while ($body =~ /\G\x0d?\x0a?([0-9a-f]+)\x0d\x0a?/gcmsi) {
130 my $len = hex($1);
131 $content .= substr($body, pos($body), $len);
132 pos($body) += $len;
133 }
134
135 return $content;
136 }
137
138 sub http_gzip_like {
139 my ($text, $re, $name) = @_;
140
141 SKIP: {
142 eval { require IO::Uncompress::Gunzip; };
143 skip "IO::Uncompress::Gunzip not installed", 1 if $@;
144
145 my $in = http_content($text);
146 my $out;
147
148 IO::Uncompress::Gunzip::gunzip(\$in => \$out);
149
150 like($out, $re, $name);
151 }
152 }
153
103 ############################################################################### 154 ###############################################################################