Mercurial > hg > nginx-tests
annotate stream_proxy_complex.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 | 766bcbb632ee |
children | f3ba4c74de31 |
rev | line source |
---|---|
987
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for stream proxy module with complex value. |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 use Test::Nginx::Stream qw/ stream /; |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 ############################################################################### |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 select STDERR; $| = 1; |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 select STDOUT; $| = 1; |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 my $t = Test::Nginx->new()->has(qw/stream stream_return/) |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 ->write_file_expand('nginx.conf', <<'EOF'); |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 %%TEST_GLOBALS%% |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 daemon off; |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 events { |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 } |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 stream { |
991
6246d69857cc
Tests: fixed stream_proxy_complex.t when run in parallel.
Sergey Kandaurov <pluknet@nginx.com>
parents:
987
diff
changeset
|
37 upstream %%PORT_8081%% { |
987
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 server 127.0.0.1:8091; |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 } |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 |
991
6246d69857cc
Tests: fixed stream_proxy_complex.t when run in parallel.
Sergey Kandaurov <pluknet@nginx.com>
parents:
987
diff
changeset
|
41 upstream %%PORT_8082%% { |
987
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 server 127.0.0.1:8092; |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 server 127.0.0.1:8093; |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 } |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 server { |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 listen 127.0.0.1:8081; |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 listen 127.0.0.1:8082; |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 proxy_pass $server_port; |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 } |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 server { |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 listen 127.0.0.1:8083; |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 proxy_pass $server_addr:%%PORT_8093%%; |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 } |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 server { |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 listen 127.0.0.1:8091; |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 listen 127.0.0.1:8092; |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 listen 127.0.0.1:8093; |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 return $server_port; |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 } |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 } |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 EOF |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 |
1251
766bcbb632ee
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
992
diff
changeset
|
67 $t->run()->plan(5); |
987
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 ############################################################################### |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 |
992
1beb641e21c9
Tests: fixed tests on win32 with stream return module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
991
diff
changeset
|
71 is(stream('127.0.0.1:' . port(8081))->read(), port(8091), 'upstream'); |
1beb641e21c9
Tests: fixed tests on win32 with stream return module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
991
diff
changeset
|
72 is(stream('127.0.0.1:' . port(8081))->read(), port(8091), 'upstream again'); |
987
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 |
992
1beb641e21c9
Tests: fixed tests on win32 with stream return module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
991
diff
changeset
|
74 is(stream('127.0.0.1:' . port(8082))->read(), port(8092), 'upstream 2'); |
1beb641e21c9
Tests: fixed tests on win32 with stream return module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
991
diff
changeset
|
75 is(stream('127.0.0.1:' . port(8082))->read(), port(8093), 'upstream second'); |
987
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 |
992
1beb641e21c9
Tests: fixed tests on win32 with stream return module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
991
diff
changeset
|
77 is(stream('127.0.0.1:' . port(8083))->read(), port(8093), 'implicit'); |
987
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 |
d6a2c7bcdc4c
Tests: stream proxy tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 ############################################################################### |