Mercurial > hg > nginx-tests
annotate stream_udp_upstream.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 | 144c6ce732e4 |
children | f3ba4c74de31 |
rev | line source |
---|---|
868 | 1 #!/usr/bin/perl |
2 | |
3 # (C) Sergey Kandaurov | |
4 # (C) Nginx, Inc. | |
5 | |
6 # Stream tests for upstream module and balancers with datagrams. | |
7 | |
8 ############################################################################### | |
9 | |
10 use warnings; | |
11 use strict; | |
12 | |
13 use Test::More; | |
14 | |
15 BEGIN { use FindBin; chdir($FindBin::Bin); } | |
16 | |
17 use lib 'lib'; | |
18 use Test::Nginx; | |
19 use Test::Nginx::Stream qw/ dgram /; | |
20 | |
21 ############################################################################### | |
22 | |
23 select STDERR; $| = 1; | |
24 select STDOUT; $| = 1; | |
25 | |
1424
5bee71e1548f
Tests: adjusted stream udp test with failed peer.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1334
diff
changeset
|
26 my $t = Test::Nginx->new()->has(qw/stream udp/)->plan(5) |
868 | 27 ->write_file_expand('nginx.conf', <<'EOF'); |
28 | |
29 %%TEST_GLOBALS%% | |
30 | |
31 daemon off; | |
32 | |
33 events { | |
34 } | |
35 | |
36 stream { | |
37 proxy_responses 1; | |
38 proxy_timeout 1s; | |
39 | |
40 upstream u { | |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1165
diff
changeset
|
41 server 127.0.0.1:%%PORT_8984_UDP%%; |
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1165
diff
changeset
|
42 server 127.0.0.1:%%PORT_8985_UDP%%; |
868 | 43 } |
44 | |
45 upstream u2 { | |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1165
diff
changeset
|
46 server 127.0.0.1:%%PORT_8986_UDP%% down; |
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1165
diff
changeset
|
47 server 127.0.0.1:%%PORT_8986_UDP%%; |
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1165
diff
changeset
|
48 server 127.0.0.1:%%PORT_8984_UDP%%; |
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1165
diff
changeset
|
49 server 127.0.0.1:%%PORT_8985_UDP%%; |
868 | 50 } |
51 | |
52 upstream u3 { | |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1165
diff
changeset
|
53 server 127.0.0.1:%%PORT_8984_UDP%%; |
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1165
diff
changeset
|
54 server 127.0.0.1:%%PORT_8985_UDP%% weight=2; |
868 | 55 } |
56 | |
57 upstream u4 { | |
1334
c4f58dfe8207
Tests: stream udp tests adjusted for upcoming udp streams.
Roman Arutyunyan <arut@nginx.com>
parents:
1251
diff
changeset
|
58 server 127.0.0.1:%%PORT_8986_UDP%% down; |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1165
diff
changeset
|
59 server 127.0.0.1:%%PORT_8984_UDP%% backup; |
868 | 60 } |
61 | |
62 server { | |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1165
diff
changeset
|
63 listen 127.0.0.1:%%PORT_8980_UDP%% udp; |
868 | 64 proxy_pass u; |
65 } | |
66 | |
67 server { | |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1165
diff
changeset
|
68 listen 127.0.0.1:%%PORT_8981_UDP%% udp; |
868 | 69 proxy_pass u2; |
70 } | |
71 | |
72 server { | |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1165
diff
changeset
|
73 listen 127.0.0.1:%%PORT_8982_UDP%% udp; |
868 | 74 proxy_pass u3; |
75 } | |
76 | |
77 server { | |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1165
diff
changeset
|
78 listen 127.0.0.1:%%PORT_8983_UDP%% udp; |
868 | 79 proxy_pass u4; |
80 } | |
81 } | |
82 | |
83 EOF | |
84 | |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1165
diff
changeset
|
85 $t->run_daemon(\&udp_daemon, port(8984), $t); |
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1165
diff
changeset
|
86 $t->run_daemon(\&udp_daemon, port(8985), $t); |
1334
c4f58dfe8207
Tests: stream udp tests adjusted for upcoming udp streams.
Roman Arutyunyan <arut@nginx.com>
parents:
1251
diff
changeset
|
87 $t->run(); |
868 | 88 |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1165
diff
changeset
|
89 $t->waitforfile($t->testdir . '/' . port(8984)); |
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1165
diff
changeset
|
90 $t->waitforfile($t->testdir . '/' . port(8985)); |
868 | 91 |
92 ############################################################################### | |
93 | |
1334
c4f58dfe8207
Tests: stream udp tests adjusted for upcoming udp streams.
Roman Arutyunyan <arut@nginx.com>
parents:
1251
diff
changeset
|
94 my @ports = my ($port4, $port5) = (port(8984), port(8985)); |
952
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
947
diff
changeset
|
95 |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1165
diff
changeset
|
96 is(many(10, port(8980)), "$port4: 5, $port5: 5", 'balanced'); |
1334
c4f58dfe8207
Tests: stream udp tests adjusted for upcoming udp streams.
Roman Arutyunyan <arut@nginx.com>
parents:
1251
diff
changeset
|
97 |
1424
5bee71e1548f
Tests: adjusted stream udp test with failed peer.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1334
diff
changeset
|
98 is(dgram('127.0.0.1:' . port(8981))->io('.', read_timeout => 0.5), '', |
5bee71e1548f
Tests: adjusted stream udp test with failed peer.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1334
diff
changeset
|
99 'no next upstream for dgram'); |
1334
c4f58dfe8207
Tests: stream udp tests adjusted for upcoming udp streams.
Roman Arutyunyan <arut@nginx.com>
parents:
1251
diff
changeset
|
100 |
1424
5bee71e1548f
Tests: adjusted stream udp test with failed peer.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1334
diff
changeset
|
101 is(many(10, port(8981)), "$port4: 5, $port5: 5", 'failures'); |
5bee71e1548f
Tests: adjusted stream udp test with failed peer.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1334
diff
changeset
|
102 |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1165
diff
changeset
|
103 is(many(9, port(8982)), "$port4: 3, $port5: 6", 'weight'); |
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1165
diff
changeset
|
104 is(many(10, port(8983)), "$port4: 10", 'backup'); |
868 | 105 |
106 ############################################################################### | |
107 | |
108 sub many { | |
952
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
947
diff
changeset
|
109 my ($count, $port) = @_; |
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
947
diff
changeset
|
110 my (%ports); |
868 | 111 |
112 for (1 .. $count) { | |
952
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
947
diff
changeset
|
113 if (dgram("127.0.0.1:$port")->io('.') =~ /(\d+)/) { |
868 | 114 $ports{$1} = 0 unless defined $ports{$1}; |
115 $ports{$1}++; | |
116 } | |
117 } | |
118 | |
952
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
947
diff
changeset
|
119 my @keys = map { my $p = $_; grep { $p == $_ } keys %ports } @ports; |
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
947
diff
changeset
|
120 return join ', ', map { $_ . ": " . $ports{$_} } @keys; |
868 | 121 } |
122 | |
123 ############################################################################### | |
124 | |
125 sub udp_daemon { | |
126 my ($port, $t) = @_; | |
127 | |
128 my $server = IO::Socket::INET->new( | |
129 Proto => 'udp', | |
130 LocalAddr => '127.0.0.1:' . $port, | |
131 Reuse => 1, | |
132 ) | |
133 or die "Can't create listening socket: $!\n"; | |
134 | |
135 # signal we are ready | |
136 | |
137 open my $fh, '>', $t->testdir() . '/' . $port; | |
138 close $fh; | |
139 | |
140 while (1) { | |
141 $server->recv(my $buffer, 65536); | |
142 $buffer = $server->sockport(); | |
143 $server->send($buffer); | |
144 } | |
145 } | |
146 | |
147 ############################################################################### |