Mercurial > hg > nginx-tests
annotate proxy_bind_transparent_capability.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 | 97c8280de681 |
children |
rev | line source |
---|---|
915
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
1262
b35037b3a9d0
Tests: added "proxy_bind transparent" test with Linux capabilities.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1261
diff
changeset
|
6 # Tests for http proxy_bind transparent with Linux CAP_NET_RAW capability. |
b35037b3a9d0
Tests: added "proxy_bind transparent" test with Linux capabilities.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1261
diff
changeset
|
7 # Ensure that such configuration isn't broken under a non-priveleged user. |
915
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 |
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 ############################################################################### |
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 |
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use warnings; |
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 use strict; |
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 |
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 use Test::More; |
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 |
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 BEGIN { use FindBin; chdir($FindBin::Bin); } |
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 |
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use lib 'lib'; |
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 use Test::Nginx; |
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 |
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 ############################################################################### |
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 |
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 select STDERR; $| = 1; |
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 select STDOUT; $| = 1; |
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 |
1262
b35037b3a9d0
Tests: added "proxy_bind transparent" test with Linux capabilities.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1261
diff
changeset
|
26 plan(skip_all => 'no linux capability') if $^O ne 'linux'; |
917
6af0421615ea
Tests: require superuser for proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
915
diff
changeset
|
27 plan(skip_all => 'must be root') if $> != 0; |
915
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 plan(skip_all => '127.0.0.2 local address required') |
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 unless defined IO::Socket::INET->new( LocalAddr => '127.0.0.2' ); |
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 |
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 my $t = Test::Nginx->new()->has(qw/http proxy/) |
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 ->write_file_expand('nginx.conf', <<'EOF'); |
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 |
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 %%TEST_GLOBALS%% |
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 |
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 daemon off; |
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 |
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 events { |
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 } |
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 |
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 http { |
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 %%TEST_GLOBALS_HTTP%% |
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 |
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
45 listen 127.0.0.1:8080; |
915
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 server_name localhost; |
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 |
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 location / { |
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 proxy_bind 127.0.0.2 transparent; |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
50 proxy_pass http://127.0.0.1:8081/; |
915
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 } |
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 } |
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 |
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
55 listen 127.0.0.1:8081; |
915
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 server_name localhost; |
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 |
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 location / { |
1261
5da72eaa893f
Tests: reduced differences to the upcoming proxy_bind test script.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
59 add_header X-IP $remote_addr always; |
915
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 } |
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 } |
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 } |
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 |
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 EOF |
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 |
1251
766bcbb632ee
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
66 $t->run()->plan(1); |
915
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 |
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 ############################################################################### |
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 |
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 like(http_get('/'), qr/X-IP: 127.0.0.2/, 'transparent'); |
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 |
1ffb16747167
Tests: proxy_bind transparent tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 ############################################################################### |