4
use Test::Nginx::Socket;
8
plan tests => repeat_each() * (blocks() * 4 + 6 * 1);
10
our $http_config = <<'_EOC_';
11
proxy_cache_path /tmp/ngx_cache_purge_cache keys_zone=test_cache:10m;
12
proxy_temp_path /tmp/ngx_cache_purge_temp 1 2;
15
our $config = <<'_EOC_';
17
set $cache test_cache;
20
proxy_pass $scheme://127.0.0.1:$server_port/etc/passwd;
22
proxy_cache_key $uri$is_args$args;
24
add_header X-Cache-Status $upstream_cache_status;
29
location = /etc/passwd {
34
our $config_allowed = <<'_EOC_';
35
proxy_cache_purge PURGE from 1.0.0.0/8 127.0.0.0/8 3.0.0.0/8;
36
set $cache test_cache;
39
proxy_pass $scheme://127.0.0.1:$server_port/etc/passwd;
41
proxy_cache_key $uri$is_args$args;
43
add_header X-Cache-Status $upstream_cache_status;
46
location = /etc/passwd {
51
our $config_forbidden = <<'_EOC_';
52
proxy_cache_purge PURGE from 1.0.0.0/8;
53
set $cache test_cache;
56
proxy_pass $scheme://127.0.0.1:$server_port/etc/passwd;
58
proxy_cache_key $uri$is_args$args;
60
add_header X-Cache-Status $upstream_cache_status;
63
location = /etc/passwd {
68
worker_connections(128);
77
--- http_config eval: $::http_config
78
--- config eval: $::config
83
Content-Type: text/plain
84
--- response_body_like: root
87
qr/\[(warn|error|crit|alert|emerg)\]/
88
--- skip_nginx: 4: < 1.7.9
92
=== TEST 2: get from cache
93
--- http_config eval: $::http_config
94
--- config eval: $::config
99
Content-Type: text/plain
101
--- response_body_like: root
103
--- no_error_log eval
104
qr/\[(warn|error|crit|alert|emerg)\]/
105
--- skip_nginx: 5: < 1.7.9
109
=== TEST 3: purge from cache
110
--- http_config eval: $::http_config
111
--- config eval: $::config
116
Content-Type: text/html
117
--- response_body_like: Successful purge
119
--- no_error_log eval
120
qr/\[(warn|error|crit|alert|emerg)\]/
121
--- skip_nginx: 4: < 1.7.9
125
=== TEST 4: purge from empty cache
126
--- http_config eval: $::http_config
127
--- config eval: $::config
132
Content-Type: text/html
133
--- response_body_like: 404 Not Found
135
--- no_error_log eval
136
qr/\[(warn|error|crit|alert|emerg)\]/
137
--- skip_nginx: 4: < 1.7.9
141
=== TEST 5: get from source
142
--- http_config eval: $::http_config
143
--- config eval: $::config
148
Content-Type: text/plain
150
--- response_body_like: root
152
--- no_error_log eval
153
qr/\[(warn|error|crit|alert|emerg)\]/
154
--- skip_nginx: 5: < 1.7.9
158
=== TEST 6: get from cache
159
--- http_config eval: $::http_config
160
--- config eval: $::config
165
Content-Type: text/plain
167
--- response_body_like: root
169
--- no_error_log eval
170
qr/\[(warn|error|crit|alert|emerg)\]/
171
--- skip_nginx: 5: < 1.7.9
175
=== TEST 7: purge from cache (PURGE allowed)
176
--- http_config eval: $::http_config
177
--- config eval: $::config_allowed
182
Content-Type: text/html
183
--- response_body_like: Successful purge
185
--- no_error_log eval
186
qr/\[(warn|error|crit|alert|emerg)\]/
187
--- skip_nginx: 4: < 1.7.9
191
=== TEST 8: purge from empty cache (PURGE allowed)
192
--- http_config eval: $::http_config
193
--- config eval: $::config_allowed
198
Content-Type: text/html
199
--- response_body_like: 404 Not Found
201
--- no_error_log eval
202
qr/\[(warn|error|crit|alert|emerg)\]/
203
--- skip_nginx: 4: < 1.7.9
207
=== TEST 9: get from source (PURGE allowed)
208
--- http_config eval: $::http_config
209
--- config eval: $::config_allowed
214
Content-Type: text/plain
216
--- response_body_like: root
218
--- no_error_log eval
219
qr/\[(warn|error|crit|alert|emerg)\]/
220
--- skip_nginx: 5: < 1.7.9
224
=== TEST 10: get from cache (PURGE allowed)
225
--- http_config eval: $::http_config
226
--- config eval: $::config_allowed
231
Content-Type: text/plain
233
--- response_body_like: root
235
--- no_error_log eval
236
qr/\[(warn|error|crit|alert|emerg)\]/
237
--- skip_nginx: 5: < 1.7.9
241
=== TEST 11: purge from cache (PURGE not allowed)
242
--- http_config eval: $::http_config
243
--- config eval: $::config_forbidden
248
Content-Type: text/html
249
--- response_body_like: 403 Forbidden
251
--- no_error_log eval
252
qr/\[(warn|error|crit|alert|emerg)\]/
253
--- skip_nginx: 4: < 1.7.9
257
=== TEST 12: get from cache (PURGE not allowed)
258
--- http_config eval: $::http_config
259
--- config eval: $::config_forbidden
264
Content-Type: text/plain
266
--- response_body_like: root
268
--- no_error_log eval
269
qr/\[(warn|error|crit|alert|emerg)\]/
270
--- skip_nginx: 5: < 1.7.9
274
=== TEST 13: no cache (PURGE allowed)
275
--- http_config eval: $::http_config
277
proxy_cache_purge PURGE from 1.0.0.0/8 127.0.0.0/8 3.0.0.0/8;
280
proxy_pass $scheme://127.0.0.1:$server_port/etc/passwd;
283
location = /etc/passwd {
290
Content-Type: text/html
291
--- response_body_like: 404 Not Found
293
--- no_error_log eval
294
qr/\[(warn|error|crit|alert|emerg)\]/
295
--- skip_nginx: 4: < 1.7.9
299
=== TEST 14: no cache (PURGE not allowed)
300
--- http_config eval: $::http_config
302
proxy_cache_purge PURGE from 1.0.0.0/8;
305
proxy_pass $scheme://127.0.0.1:$server_port/etc/passwd;
308
location = /etc/passwd {
315
Content-Type: text/html
316
--- response_body_like: 403 Forbidden
318
--- no_error_log eval
319
qr/\[(warn|error|crit|alert|emerg)\]/
320
--- skip_nginx: 4: < 1.7.9
324
=== TEST 15: multiple cache purge directives
325
--- http_config eval: $::http_config
327
fastcgi_cache_purge on;
328
proxy_cache_purge on;
329
set $cache test_cache;
332
proxy_pass $scheme://127.0.0.1:$server_port/etc/passwd;
334
proxy_cache_key $uri$is_args$args;
335
proxy_cache_valid 3m;
336
add_header X-Cache-Status $upstream_cache_status;
341
location = /etc/passwd {
348
Content-Type: text/html
349
--- response_body_like: Successful purge
351
--- no_error_log eval
352
qr/\[(warn|error|crit|alert|emerg)\]/
353
--- skip_nginx: 4: < 1.7.9