Mercurial > hg > nginx-tests
annotate proxy_protocol_ipv6.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 | fcd65708672d |
children | f3ba4c74de31 |
rev | line source |
---|---|
811
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for haproxy protocol on IPv6 listening socket. |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 ############################################################################### |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 |
1170
cf14cfe9ec8c
Tests: dropped obsolete ipv6 prerequisite.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
25 my $t = Test::Nginx->new()->has(qw/http realip stream/); |
811
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 $t->write_file_expand('nginx.conf', <<'EOF'); |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 %%TEST_GLOBALS%% |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 daemon off; |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 events { |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 } |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 http { |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 %%TEST_GLOBALS_HTTP%% |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
40 listen [::1]:%%PORT_8080%% proxy_protocol; |
811
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 server_name localhost; |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 add_header X-IP $remote_addr; |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 add_header X-PP $proxy_protocol_addr; |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 real_ip_header proxy_protocol; |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 location / { } |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 location /pp { |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 set_real_ip_from ::1/128; |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 error_page 404 =200 /t; |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 } |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 } |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 } |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 stream { |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
57 listen 127.0.0.1:8080; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
58 proxy_pass [::1]:%%PORT_8080%%; |
811
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 proxy_protocol on; |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 } |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 } |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 EOF |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 $t->write_file('t', 'SEE-THIS'); |
1190
fcd65708672d
Tests: let tests pass on travis-ci VMs with disabled IPv6 loopback.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1171
diff
changeset
|
67 $t->try_run('no inet6 support')->plan(3); |
811
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 ############################################################################### |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 my $r = http_get('/t'); |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 like($r, qr/X-IP: ::1/, 'realip'); |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 like($r, qr/X-PP: 127.0.0.1/, 'proxy protocol'); |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 $r = http_get('/pp'); |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 like($r, qr/X-IP: 127.0.0.1/, 'proxy protocol realip'); |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 ############################################################################### |