Mercurial > hg > nginx-tests
comparison proxy_cache_bypass.t @ 929:15abee29016e
Tests: proxy_cache_bypass and ticket #827 tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Fri, 13 May 2016 19:50:13 +0300 |
parents | |
children | bf86f9ad0c23 |
comparison
equal
deleted
inserted
replaced
928:856a37b4f47d | 929:15abee29016e |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 # (C) Maxim Dounin | |
4 | |
5 # Tests for http proxy cache, proxy_cache_bypass. | |
6 | |
7 ############################################################################### | |
8 | |
9 use warnings; | |
10 use strict; | |
11 | |
12 use Test::More; | |
13 | |
14 BEGIN { use FindBin; chdir($FindBin::Bin); } | |
15 | |
16 use lib 'lib'; | |
17 use Test::Nginx; | |
18 | |
19 ############################################################################### | |
20 | |
21 select STDERR; $| = 1; | |
22 select STDOUT; $| = 1; | |
23 | |
24 my $t = Test::Nginx->new()->has(qw/http proxy cache shmem rewrite/)->plan(8) | |
25 ->write_file_expand('nginx.conf', <<'EOF'); | |
26 | |
27 %%TEST_GLOBALS%% | |
28 | |
29 daemon off; | |
30 | |
31 events { | |
32 } | |
33 | |
34 http { | |
35 %%TEST_GLOBALS_HTTP%% | |
36 | |
37 proxy_cache_path %%TESTDIR%%/cache keys_zone=one:1m; | |
38 | |
39 server { | |
40 listen 127.0.0.1:8080; | |
41 server_name localhost; | |
42 | |
43 location / { | |
44 proxy_pass http://127.0.0.1:8081; | |
45 | |
46 proxy_cache one; | |
47 proxy_cache_key $uri; | |
48 proxy_cache_bypass $arg_bypass; | |
49 proxy_cache_valid any 1y; | |
50 | |
51 proxy_intercept_errors on; | |
52 error_page 404 = @fallback; | |
53 } | |
54 | |
55 location @fallback { | |
56 return 403; | |
57 } | |
58 | |
59 add_header X-Cache-Status $upstream_cache_status; | |
60 } | |
61 | |
62 server { | |
63 listen 127.0.0.1:8081; | |
64 server_name localhost; | |
65 | |
66 location / { | |
67 } | |
68 } | |
69 } | |
70 | |
71 EOF | |
72 | |
73 $t->write_file('t', 'SEE-THIS'); | |
74 | |
75 $t->run(); | |
76 | |
77 ############################################################################### | |
78 | |
79 like(http_get('/t'), qr/SEE-THIS/, 'request'); | |
80 | |
81 $t->write_file('t', 'NOOP'); | |
82 | |
83 like(http_get('/t'), qr/SEE-THIS/, 'request cached'); | |
84 like(http_get('/t?bypass=1'), qr/NOOP/, 'cache bypassed'); | |
85 like(http_get('/t'), qr/NOOP/, 'cached after bypass'); | |
86 | |
87 # ticket #827, cache item "error" field was not cleared | |
88 # on cache bypass | |
89 | |
90 like(http_get('/t2'), qr/403 Forbidden/, 'intercepted error'); | |
91 | |
92 $t->write_file('t2', 'NOOP'); | |
93 | |
94 like(http_get('/t2'), qr/403 Forbidden/, 'error cached'); | |
95 like(http_get('/t2?bypass=1'), qr/NOOP/, 'error cache bypassed'); | |
96 | |
97 TODO: { | |
98 local $TODO = 'not yet'; | |
99 | |
100 like(http_get('/t2'), qr/NOOP/, 'error cached after bypass'); | |
101 | |
102 } | |
103 | |
104 ############################################################################### |