~titusx/nginx/module-cache-purge

« back to all changes in this revision

Viewing changes to t/proxy2_vars.t

  • Committer: Piotr Sikora
  • Date: 2014-12-23 12:01:10 UTC
  • Revision ID: git-v1:065f0cae56fc5720db636885ce5b2fbaf6f09f8c
Fix compatibility with nginx-1.7.9+.

Change-Id: I262a13f007724c40496bf8c44f9518cb1ee75663
Signed-off-by: Piotr Sikora <piotr.sikora@frickle.com>

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# vi:filetype=perl
 
2
 
 
3
use lib 'lib';
 
4
use Test::Nginx::Socket;
 
5
 
 
6
repeat_each(1);
 
7
 
 
8
plan tests => repeat_each() * (blocks() * 4 + 6 * 1);
 
9
 
 
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;
 
13
_EOC_
 
14
 
 
15
our $config = <<'_EOC_';
 
16
    proxy_cache_purge  on;
 
17
    set $cache         test_cache;
 
18
 
 
19
    location /proxy {
 
20
        proxy_pass         $scheme://127.0.0.1:$server_port/etc/passwd;
 
21
        proxy_cache        $cache;
 
22
        proxy_cache_key    $uri$is_args$args;
 
23
        proxy_cache_valid  3m;
 
24
        add_header         X-Cache-Status $upstream_cache_status;
 
25
 
 
26
        if ($uri)          { }
 
27
    }
 
28
 
 
29
    location = /etc/passwd {
 
30
        root               /;
 
31
    }
 
32
_EOC_
 
33
 
 
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;
 
37
 
 
38
    location /proxy {
 
39
        proxy_pass         $scheme://127.0.0.1:$server_port/etc/passwd;
 
40
        proxy_cache        $cache;
 
41
        proxy_cache_key    $uri$is_args$args;
 
42
        proxy_cache_valid  3m;
 
43
        add_header         X-Cache-Status $upstream_cache_status;
 
44
    }
 
45
 
 
46
    location = /etc/passwd {
 
47
        root               /;
 
48
    }
 
49
_EOC_
 
50
 
 
51
our $config_forbidden = <<'_EOC_';
 
52
    proxy_cache_purge  PURGE from 1.0.0.0/8;
 
53
    set $cache         test_cache;
 
54
 
 
55
    location /proxy {
 
56
        proxy_pass         $scheme://127.0.0.1:$server_port/etc/passwd;
 
57
        proxy_cache        $cache;
 
58
        proxy_cache_key    $uri$is_args$args;
 
59
        proxy_cache_valid  3m;
 
60
        add_header         X-Cache-Status $upstream_cache_status;
 
61
    }
 
62
 
 
63
    location = /etc/passwd {
 
64
        root               /;
 
65
    }
 
66
_EOC_
 
67
 
 
68
worker_connections(128);
 
69
no_shuffle();
 
70
run_tests();
 
71
 
 
72
no_diff();
 
73
 
 
74
__DATA__
 
75
 
 
76
=== TEST 1: prepare
 
77
--- http_config eval: $::http_config
 
78
--- config eval: $::config
 
79
--- request
 
80
GET /proxy/passwd
 
81
--- error_code: 200
 
82
--- response_headers
 
83
Content-Type: text/plain
 
84
--- response_body_like: root
 
85
--- timeout: 10
 
86
--- no_error_log eval
 
87
qr/\[(warn|error|crit|alert|emerg)\]/
 
88
--- skip_nginx: 4: < 1.7.9
 
89
 
 
90
 
 
91
 
 
92
=== TEST 2: get from cache
 
93
--- http_config eval: $::http_config
 
94
--- config eval: $::config
 
95
--- request
 
96
GET /proxy/passwd
 
97
--- error_code: 200
 
98
--- response_headers
 
99
Content-Type: text/plain
 
100
X-Cache-Status: HIT
 
101
--- response_body_like: root
 
102
--- timeout: 10
 
103
--- no_error_log eval
 
104
qr/\[(warn|error|crit|alert|emerg)\]/
 
105
--- skip_nginx: 5: < 1.7.9
 
106
 
 
107
 
 
108
 
 
109
=== TEST 3: purge from cache
 
110
--- http_config eval: $::http_config
 
111
--- config eval: $::config
 
112
--- request
 
113
PURGE /proxy/passwd
 
114
--- error_code: 200
 
115
--- response_headers
 
116
Content-Type: text/html
 
117
--- response_body_like: Successful purge
 
118
--- timeout: 10
 
119
--- no_error_log eval
 
120
qr/\[(warn|error|crit|alert|emerg)\]/
 
121
--- skip_nginx: 4: < 1.7.9
 
122
 
 
123
 
 
124
 
 
125
=== TEST 4: purge from empty cache
 
126
--- http_config eval: $::http_config
 
127
--- config eval: $::config
 
128
--- request
 
129
PURGE /proxy/passwd
 
130
--- error_code: 404
 
131
--- response_headers
 
132
Content-Type: text/html
 
133
--- response_body_like: 404 Not Found
 
134
--- timeout: 10
 
135
--- no_error_log eval
 
136
qr/\[(warn|error|crit|alert|emerg)\]/
 
137
--- skip_nginx: 4: < 1.7.9
 
138
 
 
139
 
 
140
 
 
141
=== TEST 5: get from source
 
142
--- http_config eval: $::http_config
 
143
--- config eval: $::config
 
144
--- request
 
145
GET /proxy/passwd
 
146
--- error_code: 200
 
147
--- response_headers
 
148
Content-Type: text/plain
 
149
X-Cache-Status: MISS
 
150
--- response_body_like: root
 
151
--- timeout: 10
 
152
--- no_error_log eval
 
153
qr/\[(warn|error|crit|alert|emerg)\]/
 
154
--- skip_nginx: 5: < 1.7.9
 
155
 
 
156
 
 
157
 
 
158
=== TEST 6: get from cache
 
159
--- http_config eval: $::http_config
 
160
--- config eval: $::config
 
161
--- request
 
162
GET /proxy/passwd
 
163
--- error_code: 200
 
164
--- response_headers
 
165
Content-Type: text/plain
 
166
X-Cache-Status: HIT
 
167
--- response_body_like: root
 
168
--- timeout: 10
 
169
--- no_error_log eval
 
170
qr/\[(warn|error|crit|alert|emerg)\]/
 
171
--- skip_nginx: 5: < 1.7.9
 
172
 
 
173
 
 
174
 
 
175
=== TEST 7: purge from cache (PURGE allowed)
 
176
--- http_config eval: $::http_config
 
177
--- config eval: $::config_allowed
 
178
--- request
 
179
PURGE /proxy/passwd
 
180
--- error_code: 200
 
181
--- response_headers
 
182
Content-Type: text/html
 
183
--- response_body_like: Successful purge
 
184
--- timeout: 10
 
185
--- no_error_log eval
 
186
qr/\[(warn|error|crit|alert|emerg)\]/
 
187
--- skip_nginx: 4: < 1.7.9
 
188
 
 
189
 
 
190
 
 
191
=== TEST 8: purge from empty cache (PURGE allowed)
 
192
--- http_config eval: $::http_config
 
193
--- config eval: $::config_allowed
 
194
--- request
 
195
PURGE /proxy/passwd
 
196
--- error_code: 404
 
197
--- response_headers
 
198
Content-Type: text/html
 
199
--- response_body_like: 404 Not Found
 
200
--- timeout: 10
 
201
--- no_error_log eval
 
202
qr/\[(warn|error|crit|alert|emerg)\]/
 
203
--- skip_nginx: 4: < 1.7.9
 
204
 
 
205
 
 
206
 
 
207
=== TEST 9: get from source (PURGE allowed)
 
208
--- http_config eval: $::http_config
 
209
--- config eval: $::config_allowed
 
210
--- request
 
211
GET /proxy/passwd
 
212
--- error_code: 200
 
213
--- response_headers
 
214
Content-Type: text/plain
 
215
X-Cache-Status: MISS
 
216
--- response_body_like: root
 
217
--- timeout: 10
 
218
--- no_error_log eval
 
219
qr/\[(warn|error|crit|alert|emerg)\]/
 
220
--- skip_nginx: 5: < 1.7.9
 
221
 
 
222
 
 
223
 
 
224
=== TEST 10: get from cache (PURGE allowed)
 
225
--- http_config eval: $::http_config
 
226
--- config eval: $::config_allowed
 
227
--- request
 
228
GET /proxy/passwd
 
229
--- error_code: 200
 
230
--- response_headers
 
231
Content-Type: text/plain
 
232
X-Cache-Status: HIT
 
233
--- response_body_like: root
 
234
--- timeout: 10
 
235
--- no_error_log eval
 
236
qr/\[(warn|error|crit|alert|emerg)\]/
 
237
--- skip_nginx: 5: < 1.7.9
 
238
 
 
239
 
 
240
 
 
241
=== TEST 11: purge from cache (PURGE not allowed)
 
242
--- http_config eval: $::http_config
 
243
--- config eval: $::config_forbidden
 
244
--- request
 
245
PURGE /proxy/passwd
 
246
--- error_code: 403
 
247
--- response_headers
 
248
Content-Type: text/html
 
249
--- response_body_like: 403 Forbidden
 
250
--- timeout: 10
 
251
--- no_error_log eval
 
252
qr/\[(warn|error|crit|alert|emerg)\]/
 
253
--- skip_nginx: 4: < 1.7.9
 
254
 
 
255
 
 
256
 
 
257
=== TEST 12: get from cache (PURGE not allowed)
 
258
--- http_config eval: $::http_config
 
259
--- config eval: $::config_forbidden
 
260
--- request
 
261
GET /proxy/passwd
 
262
--- error_code: 200
 
263
--- response_headers
 
264
Content-Type: text/plain
 
265
X-Cache-Status: HIT
 
266
--- response_body_like: root
 
267
--- timeout: 10
 
268
--- no_error_log eval
 
269
qr/\[(warn|error|crit|alert|emerg)\]/
 
270
--- skip_nginx: 5: < 1.7.9
 
271
 
 
272
 
 
273
 
 
274
=== TEST 13: no cache (PURGE allowed)
 
275
--- http_config eval: $::http_config
 
276
--- config
 
277
    proxy_cache_purge  PURGE from 1.0.0.0/8 127.0.0.0/8 3.0.0.0/8;
 
278
 
 
279
    location /proxy {
 
280
        proxy_pass         $scheme://127.0.0.1:$server_port/etc/passwd;
 
281
    }
 
282
 
 
283
    location = /etc/passwd {
 
284
        root               /;
 
285
    }
 
286
--- request
 
287
PURGE /proxy/passwd
 
288
--- error_code: 404
 
289
--- response_headers
 
290
Content-Type: text/html
 
291
--- response_body_like: 404 Not Found
 
292
--- timeout: 10
 
293
--- no_error_log eval
 
294
qr/\[(warn|error|crit|alert|emerg)\]/
 
295
--- skip_nginx: 4: < 1.7.9
 
296
 
 
297
 
 
298
 
 
299
=== TEST 14: no cache (PURGE not allowed)
 
300
--- http_config eval: $::http_config
 
301
--- config
 
302
    proxy_cache_purge  PURGE from 1.0.0.0/8;
 
303
 
 
304
    location /proxy {
 
305
        proxy_pass         $scheme://127.0.0.1:$server_port/etc/passwd;
 
306
    }
 
307
 
 
308
    location = /etc/passwd {
 
309
        root               /;
 
310
    }
 
311
--- request
 
312
PURGE /proxy/passwd
 
313
--- error_code: 403
 
314
--- response_headers
 
315
Content-Type: text/html
 
316
--- response_body_like: 403 Forbidden
 
317
--- timeout: 10
 
318
--- no_error_log eval
 
319
qr/\[(warn|error|crit|alert|emerg)\]/
 
320
--- skip_nginx: 4: < 1.7.9
 
321
 
 
322
 
 
323
 
 
324
=== TEST 15: multiple cache purge directives
 
325
--- http_config eval: $::http_config
 
326
--- config
 
327
    fastcgi_cache_purge  on;
 
328
    proxy_cache_purge    on;
 
329
    set $cache           test_cache;
 
330
 
 
331
    location /proxy {
 
332
        proxy_pass         $scheme://127.0.0.1:$server_port/etc/passwd;
 
333
        proxy_cache        $cache;
 
334
        proxy_cache_key    $uri$is_args$args;
 
335
        proxy_cache_valid  3m;
 
336
        add_header         X-Cache-Status $upstream_cache_status;
 
337
 
 
338
        if ($uri)          { }
 
339
    }
 
340
 
 
341
    location = /etc/passwd {
 
342
        root               /;
 
343
    }
 
344
--- request
 
345
PURGE /proxy/passwd
 
346
--- error_code: 200
 
347
--- response_headers
 
348
Content-Type: text/html
 
349
--- response_body_like: Successful purge
 
350
--- timeout: 10
 
351
--- no_error_log eval
 
352
qr/\[(warn|error|crit|alert|emerg)\]/
 
353
--- skip_nginx: 4: < 1.7.9