Mercurial > hg > nginx-tests
annotate stream_proxy_bind.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 | 882267679006 |
children | f3ba4c74de31 |
rev | line source |
---|---|
622
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
2 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
3 # (C) Andrey Zelenkov |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
5 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
6 # Test for stream proxy_bind directive. |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
7 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
9 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
11 use strict; |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
12 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
14 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
16 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
19 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
20 ############################################################################### |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
21 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
24 |
626
5f9dfe85a1f2
Tests: skipped proxy_bind tests on win32.
Sergey Kandaurov <pluknet@nginx.com>
parents:
622
diff
changeset
|
25 plan(skip_all => 'win32') if $^O eq 'MSWin32'; |
622
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
26 plan(skip_all => '127.0.0.2 local address required') |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
27 unless defined IO::Socket::INET->new( LocalAddr => '127.0.0.2' ); |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
28 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
29 my $t = Test::Nginx->new()->has(qw/http proxy stream/)->plan(1) |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
30 ->write_file_expand('nginx.conf', <<'EOF'); |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
31 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
32 %%TEST_GLOBALS%% |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
33 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
34 daemon off; |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
35 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
36 events { |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
37 } |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
38 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
39 stream { |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
40 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
41 listen 127.0.0.1:8081; |
622
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
42 proxy_bind 127.0.0.2; |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
43 proxy_pass 127.0.0.1:8082; |
622
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
44 } |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
45 } |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
46 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
47 http { |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
48 %%TEST_GLOBALS_HTTP%% |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
49 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
50 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
51 listen 127.0.0.1:8080; |
622
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
52 server_name localhost; |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
53 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
54 location / { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
55 proxy_pass http://127.0.0.1:8081; |
622
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
56 } |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
57 } |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
58 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
59 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
60 listen 127.0.0.1:8082; |
622
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
61 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
62 location / { |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
63 add_header X-IP $remote_addr; |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
64 } |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
65 } |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
66 } |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
67 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
68 EOF |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
69 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
70 $t->write_file('index.html', ''); |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
71 $t->run(); |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
72 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
73 ############################################################################### |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
74 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
75 like(http_get('/'), qr/X-IP: 127.0.0.2/, 'bind'); |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
76 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
77 ############################################################################### |