Mercurial > hg > nginx-tests
annotate proxy_cache_variables.t @ 1571:1b4ceab9cb1c
Tests: fixed ssl_certificate.t with LibreSSL client.
Net::SSLeay::connect() that manages TLS handshake could return unexpected
error when receiving server alert, as seen in server certificate tests if
it could not been selected. Typically, it returns the expected error -1,
but with certain libssl implementations it can be 0, as explained below.
The error is propagated from libssl's SSL_connect(), which is usually -1.
In modern OpenSSL versions, it is the default error code used in the state
machine returned when something went wrong with parsing TLS message header.
In versions up to OpenSSL 1.0.2, with SSLv23_method() used by default, -1
is the only error code in the ssl_connect() method implementation which is
used as well if receiving alert while parsing ServerHello. BoringSSL also
seems to return -1. But it is not so with LibreSSL that returns zero.
Previously, tests failed with client built with LibreSSL with SSLv3 removed.
Here, the error is propagated directly from ssl_read_bytes() method, which
is always implemented as ssl3_read_bytes() in all TLS methods. It could be
also seen with OpenSSL up to 1.0.2 with non-default methods explicitly set.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Fri, 29 May 2020 23:10:20 +0300 |
parents | 196d33c2bb45 |
children |
rev | line source |
---|---|
517
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for http proxy cache, proxy_cache directive with variables. |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 ############################################################################### |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 |
1020
196d33c2bb45
Tests: removed TODO and try_run() checks for legacy versions.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
974
diff
changeset
|
25 my $t = Test::Nginx->new()->has(qw/http proxy cache/)->plan(8) |
517
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 ->write_file_expand('nginx.conf', <<'EOF'); |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 %%TEST_GLOBALS%% |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 daemon off; |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 events { |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 } |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 http { |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 %%TEST_GLOBALS_HTTP%% |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 proxy_cache_path %%TESTDIR%%/cache1 levels=1:2 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 keys_zone=NAME1:1m; |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 proxy_cache_path %%TESTDIR%%/cache2 levels=1:2 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 keys_zone=NAME2:1m; |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
44 listen 127.0.0.1:8080; |
517
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 server_name localhost; |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 location / { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
48 proxy_pass http://127.0.0.1:8081; |
517
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 proxy_cache $arg_c; |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 proxy_cache_valid any 1m; |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 add_header X-Cache-Status $upstream_cache_status; |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 } |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 } |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
59 listen 127.0.0.1:8081; |
517
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 server_name localhost; |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 location / { |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 } |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 } |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 } |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 EOF |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 $t->write_file('index.html', 'SEE-THIS'); |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 |
568
907e89fba9c3
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
517
diff
changeset
|
71 $t->run(); |
517
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 ############################################################################### |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 like(http_get('/?c=NAME1'), qr/MISS.*SEE-THIS/ms, 'proxy request'); |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 like(http_get('/?c=NAME1'), qr/HIT.*SEE-THIS/ms, 'proxy request cached'); |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 unlike(http_head('/?c=NAME1'), qr/SEE-THIS/, 'head request'); |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 $t->write_file('index.html', 'SEE-THAT'); |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 like(http_get('/?c=NAME2'), qr/MISS.*SEE-THAT/ms, 'proxy request 2'); |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 like(http_get('/?c=NAME2'), qr/HIT.*SEE-THAT/ms, 'proxy request 2 cached'); |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 # some invalid cases |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 like(http_get('/?c=NAME'), qr/ 500 /, 'proxy_cache unknown'); |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 like(http_get('/'), qr/(?<!X-Cache).*SEE-THAT/ms, 'proxy_cache empty'); |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
90 $t->write_file('index.html', 'SEE-THOSE'); |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
91 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
92 like(http_get('/'), qr/SEE-THOSE/, 'proxy_cache empty - not cached'); |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
93 |
b2c3d509b2f9
Tests: proxy_cache with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
94 ############################################################################### |