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