Mercurial > hg > nginx-tests
annotate gunzip_static.t @ 1990:85d88cd5091c
Tests: SSI include stub tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 04 Jul 2024 17:42:55 +0300 |
parents | 882267679006 |
children |
rev | line source |
---|---|
231
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
2 |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
3 # (C) Maxim Dounin |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
4 |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
5 # Tests for gunzip filter module with gzip_static always. It is basically |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
6 # the copy of gunzip.t with minor modifications. |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
7 |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
8 ############################################################################### |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
9 |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
10 use warnings; |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
11 use strict; |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
12 |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
13 use Test::More; |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
14 |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
16 |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
17 use lib 'lib'; |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
18 use Test::Nginx qw/ :DEFAULT :gzip /; |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
19 |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
20 ############################################################################### |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
21 |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
24 |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
25 eval { require IO::Compress::Gzip; }; |
773 | 26 plan(skip_all => "IO::Compress::Gzip not found") if $@; |
231
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
27 |
914
3ac4036b139d
Tests: fixed proxy prerequisites.
Sergey Kandaurov <pluknet@nginx.com>
parents:
777
diff
changeset
|
28 my $t = Test::Nginx->new()->has(qw/http gunzip gzip_static rewrite/); |
231
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
29 |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
30 $t->write_file_expand('nginx.conf', <<'EOF'); |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
31 |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
32 %%TEST_GLOBALS%% |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
33 |
249
6a0d934950bc
Tests: remove extra spaces in "daemon off".
Maxim Dounin <mdounin@mdounin.ru>
parents:
238
diff
changeset
|
34 daemon off; |
231
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
35 |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
36 events { |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
37 } |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
38 |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
39 http { |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
40 %%TEST_GLOBALS_HTTP%% |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
41 |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
42 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
43 listen 127.0.0.1:8080; |
231
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
44 server_name localhost; |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
45 location / { |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
46 gunzip on; |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
47 gzip_vary on; |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
48 gzip_static always; |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
49 } |
238
96387f409880
Tests: tests to catch incorrect r->gzip_ok check in gunzip.
Maxim Dounin <mdounin@mdounin.ru>
parents:
231
diff
changeset
|
50 location = /double { |
96387f409880
Tests: tests to catch incorrect r->gzip_ok check in gunzip.
Maxim Dounin <mdounin@mdounin.ru>
parents:
231
diff
changeset
|
51 error_page 404 @double; |
96387f409880
Tests: tests to catch incorrect r->gzip_ok check in gunzip.
Maxim Dounin <mdounin@mdounin.ru>
parents:
231
diff
changeset
|
52 gzip_static on; |
96387f409880
Tests: tests to catch incorrect r->gzip_ok check in gunzip.
Maxim Dounin <mdounin@mdounin.ru>
parents:
231
diff
changeset
|
53 } |
96387f409880
Tests: tests to catch incorrect r->gzip_ok check in gunzip.
Maxim Dounin <mdounin@mdounin.ru>
parents:
231
diff
changeset
|
54 location @double { |
96387f409880
Tests: tests to catch incorrect r->gzip_ok check in gunzip.
Maxim Dounin <mdounin@mdounin.ru>
parents:
231
diff
changeset
|
55 rewrite ^ /t1 break; |
96387f409880
Tests: tests to catch incorrect r->gzip_ok check in gunzip.
Maxim Dounin <mdounin@mdounin.ru>
parents:
231
diff
changeset
|
56 gunzip on; |
96387f409880
Tests: tests to catch incorrect r->gzip_ok check in gunzip.
Maxim Dounin <mdounin@mdounin.ru>
parents:
231
diff
changeset
|
57 gzip_static always; |
96387f409880
Tests: tests to catch incorrect r->gzip_ok check in gunzip.
Maxim Dounin <mdounin@mdounin.ru>
parents:
231
diff
changeset
|
58 } |
231
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
59 location /error { |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
60 error_page 500 /t1; |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
61 return 500; |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
62 } |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
63 } |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
64 } |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
65 |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
66 EOF |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
67 |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
68 my $in = join('', map { sprintf "X%03dXXXXXX", $_ } (0 .. 99)); |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
69 my $out; |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
70 |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
71 IO::Compress::Gzip::gzip(\$in => \$out); |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
72 |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
73 $t->write_file('t1.gz', $out); |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
74 $t->write_file('t2.gz', $out . $out); |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
75 $t->write_file('t3', 'not compressed'); |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
76 |
397
847ea345becb
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
392
diff
changeset
|
77 $t->run()->plan(12); |
231
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
78 |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
79 ############################################################################### |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
80 |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
81 pass('runs'); |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
82 |
238
96387f409880
Tests: tests to catch incorrect r->gzip_ok check in gunzip.
Maxim Dounin <mdounin@mdounin.ru>
parents:
231
diff
changeset
|
83 like(http_get('/t1'), qr/(?!Content-Encoding).*^(X\d\d\dXXXXXX){100}$/m, |
96387f409880
Tests: tests to catch incorrect r->gzip_ok check in gunzip.
Maxim Dounin <mdounin@mdounin.ru>
parents:
231
diff
changeset
|
84 'correct gunzipped response'); |
96387f409880
Tests: tests to catch incorrect r->gzip_ok check in gunzip.
Maxim Dounin <mdounin@mdounin.ru>
parents:
231
diff
changeset
|
85 like(http_gzip_request('/t1'), qr/Content-Encoding: gzip.*\Q$out\E/ms, |
96387f409880
Tests: tests to catch incorrect r->gzip_ok check in gunzip.
Maxim Dounin <mdounin@mdounin.ru>
parents:
231
diff
changeset
|
86 'gzip still works'); |
231
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
87 |
238
96387f409880
Tests: tests to catch incorrect r->gzip_ok check in gunzip.
Maxim Dounin <mdounin@mdounin.ru>
parents:
231
diff
changeset
|
88 like(http_get('/double'), qr/(?!Content-Encoding).^(X\d\d\dXXXXXX){100}$/ms, |
96387f409880
Tests: tests to catch incorrect r->gzip_ok check in gunzip.
Maxim Dounin <mdounin@mdounin.ru>
parents:
231
diff
changeset
|
89 'gunzip with gzip_tested'); |
96387f409880
Tests: tests to catch incorrect r->gzip_ok check in gunzip.
Maxim Dounin <mdounin@mdounin.ru>
parents:
231
diff
changeset
|
90 like(http_gzip_request('/double'), qr/Content-Encoding: gzip.*\Q$out\E/ms, |
96387f409880
Tests: tests to catch incorrect r->gzip_ok check in gunzip.
Maxim Dounin <mdounin@mdounin.ru>
parents:
231
diff
changeset
|
91 'gzip still works with gzip_tested'); |
231
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
92 |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
93 like(http_get('/t2'), qr/^(X\d\d\dXXXXXX){200}$/m, 'multiple gzip members'); |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
94 |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
95 like(http_get('/error'), qr/^(X\d\d\dXXXXXX){100}$/m, 'errors gunzipped'); |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
96 |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
97 unlike(http_head('/t1'), qr/Content-Encoding/, 'head - no content encoding'); |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
98 |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
99 like(http_get('/t1'), qr/Vary/, 'get vary'); |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
100 like(http_head('/t1'), qr/Vary/, 'head vary'); |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
101 unlike(http_get('/t3'), qr/Vary/, 'no vary on non-gzipped get'); |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
102 unlike(http_head('/t3'), qr/Vary/, 'no vary on non-gzipped head'); |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
103 |
bc1861122d0c
Tests: gunzip filter tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
104 ############################################################################### |