comparison sub_filter_multi.t @ 648:2f1b10b3ff61

Tests: sub filter tests with multiple strings to replace.
author Dmitry Volyntsev <xeioex@nginx.com>
date Mon, 17 Aug 2015 19:35:52 +0300
parents
children e9064d691790
comparison
equal deleted inserted replaced
647:4e36550410b3 648:2f1b10b3ff61
1 #!/usr/bin/perl
2
3 # (C) Dmitry Volyntsev
4 # (C) Nginx, Inc.
5
6 # Tests for multiple patterns in sub filter.
7
8 ###############################################################################
9
10 use warnings;
11 use strict;
12
13 use Test::More;
14
15 BEGIN { use FindBin; chdir($FindBin::Bin); }
16
17 use lib 'lib';
18 use Test::Nginx;
19
20 ###############################################################################
21
22 select STDERR; $| = 1;
23 select STDOUT; $| = 1;
24
25 my $t = Test::Nginx->new()->has(qw/http rewrite sub proxy/);
26
27 my $long_pattern = '0123456789abcdef' x 17;
28
29 (my $conf = <<'EOF') =~ s/%%LONG_PATTERN%%/$long_pattern/g;
30
31 %%TEST_GLOBALS%%
32
33 daemon off;
34
35 events {
36 }
37
38 http {
39 %%TEST_GLOBALS_HTTP%%
40
41 server {
42 listen 127.0.0.1:8080;
43 server_name localhost;
44
45 sub_filter_types *;
46 sub_filter foo bar;
47
48 location /multi {
49 sub_filter_once off;
50 sub_filter aab +;
51 sub_filter yyz -;
52 return 200 $arg_a;
53 }
54
55 location /multi2 {
56 sub_filter_once off;
57 sub_filter aabb +;
58 sub_filter aaabb -;
59 return 200 $arg_a;
60 }
61
62 location /multi3 {
63 sub_filter_once off;
64 sub_filter aacbb +;
65 sub_filter aadbb -;
66 return 200 $arg_a;
67 }
68
69 location /case {
70 sub_filter_once off;
71 sub_filter AAB +;
72 sub_filter YYZ -;
73 return 200 $arg_a;
74 }
75
76 location /case2 {
77 sub_filter_once off;
78 sub_filter ABCDEFGHIJKLMNOPQRSTUVWXYZ +;
79 return 200 $arg_a;
80 }
81
82 location /case3 {
83 sub_filter_once off;
84 sub_filter abcdefghijklmnopqrstuvwxyz +;
85 return 200 $arg_a;
86 }
87
88 location /minimal {
89 sub_filter_once off;
90 sub_filter ab +;
91 sub_filter cd -;
92 sub_filter ef *;
93 sub_filter gh !;
94 sub_filter x _;
95 return 200 $arg_a;
96 }
97
98 location /once {
99 sub_filter aab +;
100 sub_filter yyz -;
101 return 200 $arg_a;
102 }
103
104 location /table/inheritance {
105 sub_filter_once off;
106 return 200 $arg_a;
107 }
108
109 location /utf8 {
110 sub_filter_once off;
111 sub_filter 模様 замена1;
112 sub_filter पैटर्न замена2;
113 sub_filter паттерн replaced;
114 return 200 $arg_a;
115 }
116
117 location /var/replacement/multi {
118 sub_filter_once off;
119 sub_filter aab '${arg_a}_replaced';
120 sub_filter yyz '${arg_b}_replaced';
121 return 200 $arg_c;
122 }
123
124 location /crossbuf/match1 {
125 sub_filter_once off;
126 sub_filter abpattyz +;
127 alias %%TESTDIR%%/;
128 }
129
130 location /crossbuf/match2 {
131 sub_filter_once off;
132 sub_filter abpattrnyz +;
133 alias %%TESTDIR%%/;
134 }
135
136 location /crossbuf/match3 {
137 sub_filter_once off;
138 sub_filter abpatternyz +;
139 alias %%TESTDIR%%/;
140 }
141
142 location /crossbuf/match4 {
143 sub_filter_once off;
144 sub_filter abpattternyz +;
145 alias %%TESTDIR%%/;
146 }
147
148 location /crossbuf/match5-01 {
149 sub_filter_once off;
150 sub_filter abyz +;
151 sub_filter abpattternyz -;
152 alias %%TESTDIR%%/;
153 }
154
155 location /crossbuf/match5-02 {
156 sub_filter_once off;
157 sub_filter abpayz +;
158 sub_filter abpattternyz -;
159 alias %%TESTDIR%%/;
160 }
161
162 location /crossbuf/match6 {
163 sub_filter_once off;
164 sub_filter abpattxernyz +;
165 sub_filter abpattternyz -;
166 alias %%TESTDIR%%/;
167 }
168
169 location /crossbuf/superlong/match1 {
170 sub_filter_once off;
171 sub_filter %%LONG_PATTERN%% +;
172 alias %%TESTDIR%%/;
173 }
174
175 location /crossbuf/superlong/match2 {
176 sub_filter_once off;
177 sub_filter %%LONG_PATTERN%% +;
178 sub_filter yz -;
179 alias %%TESTDIR%%/;
180 }
181
182 location /crossbuf/superlong/match3 {
183 sub_filter_once off;
184 sub_filter %%LONG_PATTERN%% +;
185 sub_filter 01ef -;
186 alias %%TESTDIR%%/;
187 }
188
189 location /crossbuf/superlong/match4 {
190 sub_filter_once off;
191 sub_filter %%LONG_PATTERN%% +;
192 sub_filter 01ef -;
193 sub_filter _ *;
194 alias %%TESTDIR%%/;
195 }
196
197 location /shortbuf/match1 {
198 sub_filter_once off;
199 sub_filter abpatternyz +;
200
201 proxy_pass http://127.0.0.1:8081/;
202 proxy_buffering off;
203 }
204
205 location /shortbuf/match2 {
206 sub_filter_once off;
207 sub_filter abpatternyz +;
208 sub_filter abpaernyz -;
209
210 proxy_pass http://127.0.0.1:8081/;
211 proxy_buffering off;
212 }
213
214 location /shortbuf/match3 {
215 sub_filter_once off;
216 sub_filter abpatternyz +;
217 sub_filter abpaernyz -;
218 sub_filter _ *;
219
220 proxy_pass http://127.0.0.1:8081/;
221 proxy_buffering off;
222 }
223
224 location /shortbuf/match4 {
225 sub_filter_once off;
226 sub_filter patt +;
227
228 proxy_pass http://127.0.0.1:8081/;
229 proxy_buffering off;
230 }
231
232 location /shortbuf/match5 {
233 sub_filter_once off;
234 sub_filter abpatternyz +;
235 sub_filter abpa -;
236 sub_filter tter *;
237
238 proxy_pass http://127.0.0.1:8081/;
239 proxy_buffering off;
240 }
241 }
242
243 server {
244 listen 127.0.0.1:8081;
245
246 limit_rate 4;
247 limit_rate_after 160;
248
249 location / {
250 return 200 $arg_a;
251 }
252 }
253 }
254
255 EOF
256
257 $t->write_file_expand('nginx.conf', $conf);
258
259 $t->write_file('huge1.html', 'abpattyz' x 6000);
260 $t->write_file('huge2.html', 'abpattrnyz' x 5000);
261 $t->write_file('huge3.html', 'abpatternyz' x 4000);
262 $t->write_file('huge4.html', 'abpattternyz' x 4000);
263
264 $t->write_file('huge5-01.html', 'abpatternyzA' x 4000);
265 $t->write_file('huge5-02.html', 'abpatternyzABCDEFGHIJ' x 4000);
266 $t->write_file('huge5-03.html', 'abpatternyzABCDEFGHIJK' x 4000);
267 $t->write_file('huge5-04.html', 'abpatternyzABCDEFGHIJKL' x 4000);
268
269 $t->write_file('huge6-01.html', 'abyzAabpattternyz' x 3000);
270 $t->write_file('huge6-02.html', 'abpayzAabpattternyz' x 3000);
271
272 $t->write_file('huge7-01.html', 'abpattxernyzabpattternyz' x 3000);
273 $t->write_file('huge7-02.html', 'abpattxernyzAabpattternyz' x 3000);
274 $t->write_file('huge7-03.html', 'abpattxernyzABCDEFGHIJabpattternyz' x 3000);
275 $t->write_file('huge7-04.html', 'abpattxernyzABCDEFGHIJKabpattternyz' x 3000);
276 $t->write_file('huge7-05.html', 'abpattxernyzABCDEFGHIJKLabpattternyz' x 3000);
277
278 $t->write_file('huge8.html', scalar ('ABC' . $long_pattern . 'XYZ') x 1000);
279 $t->write_file('huge9.html', scalar ('ABC' . $long_pattern . 'yz') x 1000);
280 $t->write_file('huge10-01.html', scalar ($long_pattern . 'ABC01ef') x 1000);
281 $t->write_file('huge10-02.html', scalar ('01efABC' . $long_pattern) x 1000);
282 $t->write_file('huge11.html', scalar ('01efA_Z' . $long_pattern) x 1000);
283
284 $t->try_run('no multiple sub_filter')->plan(42);
285
286 ###############################################################################
287
288 like(http_get('/multi?a=aabAyyzBaab'), qr/\+A-B\+/, 'simple match');
289 like(http_get('/multi2?a=aabbaaabbaabb'), qr/\+-\+/, 'partial match');
290 like(http_get('/multi3?a=aadbbaacbb'), qr/-\+/, 'exact match');
291
292 like(http_get('/multi?a=AABYYZAAB'), qr/\+-\+/, 'case insensivity 1');
293 like(http_get('/case?a=aabyyzaab'), qr/\+-\+/, 'case insensivity 2');
294 like(http_get('/case2?a=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'),
295 qr/\+\+/, 'case insensivity 3');
296 like(http_get('/case3?a=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'),
297 qr/\+\+/, 'case insensivity 4');
298
299 like(http_get('/minimal?a=AAabcdefghBxBabCxCcdDDefEEghFF'),
300 qr/AA\+-\*!B_B\+C_C-DD\*EE!FF/, 'minimal match');
301
302 like(http_get('/utf8?a=ТЕКСТ模様ТЕКСТ2पैटर्नТЕКСТ3паттерн'),
303 qr/ТЕКСТзамена1ТЕКСТ2замена2ТЕКСТ3replaced/, 'utf8 match');
304
305 like(http_get('/once?a=aabyyzaab'), qr/\+-aab/, 'once 1');
306 like(http_get('/once?a=yyzaabyyz'), qr/-\+yyz/, 'once 2');
307 like(http_get('/once?a=yyzyyzaabaabyyz'), qr/-yyz\+aabyyz/, 'once 3');
308
309 like(http_get('/table/inheritance?a=foofoo'), qr/barbar/, 'table inheritance');
310
311 like(http_get('/var/replacement/multi?a=A&b=B&c=aabyyzaab'),
312 qr/A_replacedB_replacedA_replaced/, 'complex multiple replace');
313
314 like(http_get('/crossbuf/match1/huge1.html'), qr/\+{6000}/,
315 'crossbuf match 1 (simple match len 8)');
316 like(http_get('/crossbuf/match2/huge2.html'), qr/\+{5000}/,
317 'crossbuf match 2 (simple match len 9)');
318 like(http_get('/crossbuf/match3/huge3.html'), qr/\+{4000}/,
319 'crossbuf match 3 (simple match len 10)');
320 like(http_get('/crossbuf/match4/huge4.html'), qr/\+{4000}/,
321 'crossbuf match 4 (simple match len 11)');
322
323 like(http_get('/crossbuf/match3/huge5-01.html'), qr/(\+A){4000}/,
324 'crossbuf match 5.1');
325 like(http_get('/crossbuf/match3/huge5-02.html'), qr/(\+ABCDEFGHIJ){4000}/,
326 'crossbuf match 5.2');
327 like(http_get('/crossbuf/match3/huge5-03.html'), qr/(\+ABCDEFGHIJK){4000}/,
328 'crossbuf match 5.3');
329 like(http_get('/crossbuf/match3/huge5-04.html'), qr/(\+ABCDEFGHIJKL){4000}/,
330 'crossbuf match 5.4');
331
332 like(http_get('/crossbuf/match5-01/huge6-01.html'), qr/(\+A-){3000}/,
333 'crossbuf match 6.1 (multiple replace)');
334 like(http_get('/crossbuf/match5-02/huge6-02.html'), qr/(\+A-){3000}/,
335 'crossbuf match 6.2 (multiple replace)');
336
337 like(http_get('/crossbuf/match6/huge7-01.html'), qr/(\+-){3000}/,
338 'crossbuf match 7.1 (multiple replace)');
339 like(http_get('/crossbuf/match6/huge7-02.html'), qr/(\+A-){3000}/,
340 'crossbuf match 7.2 (multiple replace)');
341 like(http_get('/crossbuf/match6/huge7-03.html'), qr/(\+ABCDEFGHIJ-){3000}/,
342 'crossbuf match 7.3 (multiple replace)');
343 like(http_get('/crossbuf/match6/huge7-04.html'), qr/(\+ABCDEFGHIJK-){3000}/,
344 'crossbuf match 7.4 (multiple replace)');
345 like(http_get('/crossbuf/match6/huge7-05.html'), qr/(\+ABCDEFGHIJKL-){3000}/,
346 'crossbuf match 7.5 (multiple replace)');
347
348 like(http_get('/crossbuf/superlong/match1/huge8.html'), qr/(ABC\+XYZ){1000}/,
349 'crossbuf superlong match 1');
350 like(http_get('/crossbuf/superlong/match2/huge9.html'), qr/(ABC\+-){1000}/,
351 'crossbuf superlong match 2 (multiple replace)');
352 like(http_get('/crossbuf/superlong/match3/huge10-01.html'), qr/(\+ABC-){1000}/,
353 'crossbuf superlong match 3.1 (multiple replace)');
354 like(http_get('/crossbuf/superlong/match3/huge10-02.html'), qr/(-ABC\+){1000}/,
355 'crossbuf superlong match 3.2 (multiple replace)');
356 like(http_get('/crossbuf/superlong/match4/huge11.html'), qr/(-A\*Z\+){1000}/,
357 'crossbuf superlong match 4 (1 byte search pattern)');
358
359 SKIP: {
360 skip 'long tests', 8 unless $ENV{TEST_NGINX_UNSAFE};
361
362 like(http_get('/shortbuf/match1?a=' . 'abpatternyzA' x 3),
363 qr/(\+A){3}/, 'shortbuf match 1.1');
364 like(http_get('/shortbuf/match1?a=' . 'abpatternyzABCD' x 3),
365 qr/(\+ABCD){3}/, 'shortbuf match 1.2');
366 like(http_get('/shortbuf/match1?a=' . 'abpatternyzABCDE' x 3),
367 qr/(\+ABCDE){3}/, 'shortbuf match 1.3');
368 like(http_get('/shortbuf/match2?a=' . 'abpatternyzAabpaernyzB' x 2),
369 qr/(\+A-B){2}/, 'shortbuf match 2.1 (multiple replace)');
370 like(http_get('/shortbuf/match2?a=' . 'abpatternyzAabpaernyz' x 2),
371 qr/(\+A-){2}/, 'shortbuf match 2.2 (multiple replace)');
372 like(http_get('/shortbuf/match3?a=' . 'abpatternyzA_' x 3),
373 qr/(\+A\*){3}/, 'shortbuf match 3 (1 byte search pattern)');
374 like(http_get('/shortbuf/match4?a=' . 'pattABCDEFGHI' x 3),
375 qr/(\+ABCDEFGHI){3}/, 'shortbuf match 4');
376 like(http_get('/shortbuf/match5?a=abpatternyzABCDE' . 'abpatternyABCDE' x 2),
377 qr/\+ABCDE(-\*nyABCDE){2}/, 'shortbuf match 5');
378 }
379
380 ###############################################################################