Mercurial > hg > nginx-tests
annotate proxy_cache_bypass.t @ 1606:e4e0695552ed
Tests: fixed stream_proxy_ssl_conf_command.t.
The stream_proxy_ssl_conf_command.t test used stream return module
to return the response. Since this ignores actual request, but the
perl test code used http_get(). This might result in the request being
sent after the response is returned and the connection closed by the server,
resulting in RST being generated and no response seen by the client at all.
Fix is to use "stream(...)->read()" instead of http_get(), so
no request is sent at all, eliminating possibility of RST being
generated.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Tue, 10 Nov 2020 05:03:29 +0300 |
parents | 766bcbb632ee |
children |
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 |
1020
196d33c2bb45
Tests: removed TODO and try_run() checks for legacy versions.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
974
diff
changeset
|
24 my $t = Test::Nginx->new()->has(qw/http proxy cache rewrite/)->plan(8) |
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 } |
15abee29016e
Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
68 } |
15abee29016e
Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
69 } |
15abee29016e
Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
70 |
15abee29016e
Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
71 EOF |
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 $t->write_file('t', 'SEE-THIS'); |
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 $t->run(); |
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 ############################################################################### |
15abee29016e
Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
78 |
15abee29016e
Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
79 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
|
80 |
15abee29016e
Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
81 $t->write_file('t', 'NOOP'); |
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 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
|
84 like(http_get('/t?bypass=1'), qr/NOOP/, 'cache bypassed'); |
15abee29016e
Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
85 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
|
86 |
15abee29016e
Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
87 # 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
|
88 # on cache bypass |
15abee29016e
Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
89 |
15abee29016e
Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
90 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
|
91 |
15abee29016e
Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
92 $t->write_file('t2', 'NOOP'); |
15abee29016e
Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
93 |
15abee29016e
Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
94 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
|
95 like(http_get('/t2?bypass=1'), qr/NOOP/, 'error cache bypassed'); |
15abee29016e
Tests: proxy_cache_bypass and ticket #827 tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
96 like(http_get('/t2'), qr/NOOP/, 'error cached after 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 ############################################################################### |