annotate proxy_cache_bypass.t @ 1989:bf027a972ccf default tip

Tests: proxy_no_cache tests.
author Maxim Dounin <mdounin@mdounin.ru>
date Tue, 25 Jun 2024 21:46:50 +0300
parents 766bcbb632ee
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
929
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
1 #!/usr/bin/perl
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
2
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
3 # (C) Maxim Dounin
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
4
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
5 # Tests for http proxy cache, proxy_cache_bypass.
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
6
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
7 ###############################################################################
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
8
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
9 use warnings;
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
10 use strict;
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
11
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
12 use Test::More;
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
13
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
14 BEGIN { use FindBin; chdir($FindBin::Bin); }
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
15
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
16 use lib 'lib';
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
17 use Test::Nginx;
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
18
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
19 ###############################################################################
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
20
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
21 select STDERR; $| = 1;
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
22 select STDOUT; $| = 1;
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
23
1989
bf027a972ccf Tests: proxy_no_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1251
diff changeset
24 my $t = Test::Nginx->new()->has(qw/http proxy cache rewrite/)->plan(12)
929
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
25 ->write_file_expand('nginx.conf', <<'EOF');
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
26
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
27 %%TEST_GLOBALS%%
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
28
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
29 daemon off;
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
30
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
31 events {
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
32 }
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
33
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
34 http {
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
35 %%TEST_GLOBALS_HTTP%%
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
36
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
37 proxy_cache_path %%TESTDIR%%/cache keys_zone=one:1m;
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
38
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
39 server {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
40 listen 127.0.0.1:8080;
929
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
41 server_name localhost;
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
42
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
43 location / {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
44 proxy_pass http://127.0.0.1:8081;
929
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
45
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
46 proxy_cache one;
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
47 proxy_cache_key $uri;
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
48 proxy_cache_bypass $arg_bypass;
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
49 proxy_cache_valid any 1y;
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
50
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
51 proxy_intercept_errors on;
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
52 error_page 404 = @fallback;
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
53 }
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
54
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
55 location @fallback {
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
56 return 403;
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
57 }
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
58
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
59 add_header X-Cache-Status $upstream_cache_status;
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
60 }
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
61
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
62 server {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
63 listen 127.0.0.1:8081;
929
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
64 server_name localhost;
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
65
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
66 location / {
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
67 }
1989
bf027a972ccf Tests: proxy_no_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1251
diff changeset
68
bf027a972ccf Tests: proxy_no_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1251
diff changeset
69 location /t3 {
bf027a972ccf Tests: proxy_no_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1251
diff changeset
70 add_header Transfer-Encoding $arg_bypass;
bf027a972ccf Tests: proxy_no_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1251
diff changeset
71 }
929
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
72 }
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
73 }
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
74
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
75 EOF
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
76
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
77 $t->write_file('t', 'SEE-THIS');
1989
bf027a972ccf Tests: proxy_no_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1251
diff changeset
78 $t->write_file('t3', 'SEE-THIS');
929
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
79
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
80 $t->run();
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
81
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
82 ###############################################################################
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
83
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
84 like(http_get('/t'), qr/SEE-THIS/, 'request');
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
85
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
86 $t->write_file('t', 'NOOP');
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
87
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
88 like(http_get('/t'), qr/SEE-THIS/, 'request cached');
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
89 like(http_get('/t?bypass=1'), qr/NOOP/, 'cache bypassed');
1989
bf027a972ccf Tests: proxy_no_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1251
diff changeset
90
bf027a972ccf Tests: proxy_no_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1251
diff changeset
91 unlink $t->testdir() . '/t';
bf027a972ccf Tests: proxy_no_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1251
diff changeset
92
929
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
93 like(http_get('/t'), qr/NOOP/, 'cached after bypass');
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
94
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
95 # ticket #827, cache item "error" field was not cleared
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
96 # on cache bypass
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
97
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
98 like(http_get('/t2'), qr/403 Forbidden/, 'intercepted error');
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
99
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
100 $t->write_file('t2', 'NOOP');
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
101
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
102 like(http_get('/t2'), qr/403 Forbidden/, 'error cached');
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
103 like(http_get('/t2?bypass=1'), qr/NOOP/, 'error cache bypassed');
1989
bf027a972ccf Tests: proxy_no_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1251
diff changeset
104
bf027a972ccf Tests: proxy_no_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1251
diff changeset
105 unlink $t->testdir() . '/t2';
bf027a972ccf Tests: proxy_no_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1251
diff changeset
106
bf027a972ccf Tests: proxy_no_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1251
diff changeset
107 like(http_get('/t2'), qr/NOOP/, 'file cached after bypass');
bf027a972ccf Tests: proxy_no_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1251
diff changeset
108
bf027a972ccf Tests: proxy_no_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1251
diff changeset
109 # make sure the error is cached after bypass
bf027a972ccf Tests: proxy_no_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1251
diff changeset
110
bf027a972ccf Tests: proxy_no_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1251
diff changeset
111 like(http_get('/t2?bypass=1'), qr/403 Forbidden/, 'file cache bypassed');
bf027a972ccf Tests: proxy_no_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1251
diff changeset
112
bf027a972ccf Tests: proxy_no_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1251
diff changeset
113 $t->write_file('t2', 'NOOP');
bf027a972ccf Tests: proxy_no_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1251
diff changeset
114
bf027a972ccf Tests: proxy_no_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1251
diff changeset
115 TODO: {
bf027a972ccf Tests: proxy_no_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1251
diff changeset
116 local $TODO = 'not yet' unless $t->has_version('1.27.2');
bf027a972ccf Tests: proxy_no_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1251
diff changeset
117
bf027a972ccf Tests: proxy_no_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1251
diff changeset
118 like(http_get('/t2'), qr/403 Forbidden/, 'error cached again');
bf027a972ccf Tests: proxy_no_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1251
diff changeset
119
bf027a972ccf Tests: proxy_no_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1251
diff changeset
120 }
bf027a972ccf Tests: proxy_no_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1251
diff changeset
121
bf027a972ccf Tests: proxy_no_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1251
diff changeset
122 # similarly, internal 502/504 is cached after bypass
bf027a972ccf Tests: proxy_no_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1251
diff changeset
123
bf027a972ccf Tests: proxy_no_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1251
diff changeset
124 like(http_get('/t3?bypass=1'), qr/502 Bad/, 'internal 502');
bf027a972ccf Tests: proxy_no_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1251
diff changeset
125
bf027a972ccf Tests: proxy_no_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1251
diff changeset
126 TODO: {
bf027a972ccf Tests: proxy_no_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1251
diff changeset
127 local $TODO = 'not yet' unless $t->has_version('1.27.2');
bf027a972ccf Tests: proxy_no_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1251
diff changeset
128
bf027a972ccf Tests: proxy_no_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1251
diff changeset
129 like(http_get('/t3'), qr/502 Bad/, 'internal 502 cached');
bf027a972ccf Tests: proxy_no_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1251
diff changeset
130
bf027a972ccf Tests: proxy_no_cache tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1251
diff changeset
131 }
929
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
132
15abee29016e Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
133 ###############################################################################