Mercurial > hg > nginx-tests
annotate proxy_bind.t @ 1825:3629eda94c1b
Tests: handling of EWOULDBLOCK from sysread() with IO::Socket::SSL.
With IO::Socket::SSL, when select() reports that the socket is readable,
reading from it might still fail with EWOULDBLOCK, since no application
data is available in the socket. In particular, this might happen with
TLSv1.3 when a session ticket is received after the handshake. Fix is
to explicitly check for EWOULDBLOCK errors.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Tue, 21 Mar 2023 02:57:39 +0300 |
parents | 766bcbb632ee |
children |
rev | line source |
---|---|
641
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
2 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
3 # (C) Andrey Zelenkov |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
5 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
6 # Tests for http proxy_bind directive. |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
7 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
9 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
11 use strict; |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
12 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
14 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
16 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
19 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
20 ############################################################################### |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
21 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
24 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
25 plan(skip_all => 'win32') if $^O eq 'MSWin32'; |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
26 plan(skip_all => '127.0.0.2 local address required') |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
27 unless defined IO::Socket::INET->new( LocalAddr => '127.0.0.2' ); |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
28 |
953
2bbab9bd73e5
Tests: added proxy_bind test with port.
Sergey Kandaurov <pluknet@nginx.com>
parents:
952
diff
changeset
|
29 my $t = Test::Nginx->new()->has(qw/http proxy/)->plan(5) |
641
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
30 ->write_file_expand('nginx.conf', <<'EOF'); |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
31 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
32 %%TEST_GLOBALS%% |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
33 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
34 daemon off; |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
35 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
36 events { |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
37 } |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
38 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
39 http { |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
40 %%TEST_GLOBALS_HTTP%% |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
41 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
42 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
953
diff
changeset
|
43 listen 127.0.0.1:8080; |
641
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
44 server_name localhost; |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
45 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
46 proxy_bind 127.0.0.2; |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
47 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
48 location / { |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
49 proxy_bind 127.0.0.1; |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
953
diff
changeset
|
50 proxy_pass http://127.0.0.1:8081/; |
641
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
51 } |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
52 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
53 location /inherit { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
953
diff
changeset
|
54 proxy_pass http://127.0.0.1:8081/; |
641
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
55 } |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
56 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
57 location /off { |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
58 proxy_bind off; |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
953
diff
changeset
|
59 proxy_pass http://127.0.0.1:8081/; |
641
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
60 } |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
61 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
62 location /var { |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
63 proxy_bind $arg_b; |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
953
diff
changeset
|
64 proxy_pass http://127.0.0.1:8081/; |
641
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
65 } |
953
2bbab9bd73e5
Tests: added proxy_bind test with port.
Sergey Kandaurov <pluknet@nginx.com>
parents:
952
diff
changeset
|
66 |
2bbab9bd73e5
Tests: added proxy_bind test with port.
Sergey Kandaurov <pluknet@nginx.com>
parents:
952
diff
changeset
|
67 location /port { |
2bbab9bd73e5
Tests: added proxy_bind test with port.
Sergey Kandaurov <pluknet@nginx.com>
parents:
952
diff
changeset
|
68 proxy_bind 127.0.0.2:$remote_port; |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
953
diff
changeset
|
69 proxy_pass http://127.0.0.1:8081/; |
953
2bbab9bd73e5
Tests: added proxy_bind test with port.
Sergey Kandaurov <pluknet@nginx.com>
parents:
952
diff
changeset
|
70 add_header X-Client-Port $remote_port; |
2bbab9bd73e5
Tests: added proxy_bind test with port.
Sergey Kandaurov <pluknet@nginx.com>
parents:
952
diff
changeset
|
71 } |
641
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
72 } |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
73 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
74 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
953
diff
changeset
|
75 listen 127.0.0.1:8081; |
641
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
76 server_name localhost; |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
77 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
78 location / { |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
79 add_header X-IP $remote_addr; |
953
2bbab9bd73e5
Tests: added proxy_bind test with port.
Sergey Kandaurov <pluknet@nginx.com>
parents:
952
diff
changeset
|
80 add_header X-Port $remote_port; |
641
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
81 } |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
82 } |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
83 } |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
84 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
85 EOF |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
86 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
87 $t->write_file('index.html', ''); |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
88 $t->run(); |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
89 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
90 ############################################################################### |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
91 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
92 like(http_get('/'), qr/X-IP: 127.0.0.1/, 'bind'); |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
93 like(http_get('/inherit'), qr/X-IP: 127.0.0.2/, 'bind inherit'); |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
94 like(http_get('/off'), qr/X-IP: 127.0.0.1/, 'bind off'); |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
95 like(http_get('/var?b=127.0.0.2'), qr/X-IP: 127.0.0.2/, 'bind var'); |
953
2bbab9bd73e5
Tests: added proxy_bind test with port.
Sergey Kandaurov <pluknet@nginx.com>
parents:
952
diff
changeset
|
96 like(http_get('/port'), qr/Port: (\d+)(?!\d).*Port: \1/s, 'bind port'); |
2bbab9bd73e5
Tests: added proxy_bind test with port.
Sergey Kandaurov <pluknet@nginx.com>
parents:
952
diff
changeset
|
97 |
641
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
98 ############################################################################### |