annotate stream_ssl_realip.t @ 1236:93f749c1d5c5

Tests: fixed parallel tests execution with UDP. Previously, when checking ports availability, a UDP socket was always created first, then a TCP socket was created. On success, one of UDP and TCP sockets was closed (depending on the "udp" option) and the second one was used to busy this port in other scripts. This lead to the following problem: in an attempt to reopen a UDP socket used in a given testing script it could be stolen by another script as part of checking ports availability. To solve this problem, UDP and TCP ports were split into two non-overlapping ranges: TCP ports are only used in the range 8000-8499, and UDP ports - in the range 8500-8999. In addition, the order of creating sockets in UDP tests has been reversed: now a TCP socket used as a lock precedes a UDP socket.
author Andrey Zelenkov <zelenkov@nginx.com>
date Thu, 26 Oct 2017 18:00:21 +0300
parents 0af58b78df35
children 766bcbb632ee
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1029
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1 #!/usr/bin/perl
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
2
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
3 # (C) Sergey Kandaurov
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
4 # (C) Nginx, Inc.
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
5
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
6 # Tests for stream realip module, server side proxy protocol with ssl.
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
7
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
8 ###############################################################################
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
9
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
10 use warnings;
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
11 use strict;
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
12
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
13 use Test::More;
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
14
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
15 use Socket qw/ $CRLF /;
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
16
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
17 BEGIN { use FindBin; chdir($FindBin::Bin); }
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
18
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
19 use lib 'lib';
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
20 use Test::Nginx;
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
21 use Test::Nginx::Stream qw/ stream /;
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
22
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
23 ###############################################################################
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
24
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
25 select STDERR; $| = 1;
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
26 select STDOUT; $| = 1;
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
27
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
28 eval { require IO::Socket::SSL; };
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
29 plan(skip_all => 'IO::Socket::SSL not installed') if $@;
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
30 eval { IO::Socket::SSL::SSL_VERIFY_NONE(); };
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
31 plan(skip_all => 'IO::Socket::SSL too old') if $@;
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
32
1170
cf14cfe9ec8c Tests: dropped obsolete ipv6 prerequisite.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1168
diff changeset
33 my $t = Test::Nginx->new()->has(qw/stream stream_return stream_realip/)
1029
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
34 ->has(qw/stream_ssl/)->has_daemon('openssl')
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
35 ->write_file_expand('nginx.conf', <<'EOF');
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
36
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
37 %%TEST_GLOBALS%%
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
38
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
39 daemon off;
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
40
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
41 events {
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
42 }
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
43
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
44 stream {
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
45 ssl_certificate_key localhost.key;
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
46 ssl_certificate localhost.crt;
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
47
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
48 server {
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
49 listen 127.0.0.1:8083 proxy_protocol ssl;
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
50 return $proxy_protocol_addr:$proxy_protocol_port;
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
51 }
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
52
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
53 server {
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
54 listen 127.0.0.1:8086 proxy_protocol ssl;
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
55 listen [::1]:%%PORT_8086%% proxy_protocol ssl;
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
56 return "$remote_addr:$remote_port:
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
57 $realip_remote_addr:$realip_remote_port";
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
58
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
59 set_real_ip_from ::1;
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
60 set_real_ip_from 127.0.0.2;
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
61 }
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
62
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
63 server {
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
64 listen 127.0.0.1:8087;
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
65 proxy_pass [::1]:%%PORT_8086%%;
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
66 }
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
67
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
68 server {
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
69 listen 127.0.0.1:8088 proxy_protocol ssl;
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
70 listen [::1]:%%PORT_8088%% proxy_protocol ssl;
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
71 return "$remote_addr:$remote_port:
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
72 $realip_remote_addr:$realip_remote_port";
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
73
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
74 set_real_ip_from 127.0.0.1;
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
75 set_real_ip_from ::2;
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
76 }
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
77
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
78 server {
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
79 listen 127.0.0.1:8089;
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
80 proxy_pass [::1]:%%PORT_8088%%;
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
81 }
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
82 }
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
83
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
84 EOF
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
85
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
86 $t->write_file('openssl.conf', <<EOF);
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
87 [ req ]
1116
8ef51dbb5d69 Tests: reduced OpenSSL default key length to 1024.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1029
diff changeset
88 default_bits = 1024
1029
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
89 encrypt_key = no
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
90 distinguished_name = req_distinguished_name
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
91 [ req_distinguished_name ]
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
92 EOF
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
93
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
94 my $d = $t->testdir();
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
95
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
96 foreach my $name ('localhost') {
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
97 system('openssl req -x509 -new '
1220
0af58b78df35 Tests: removed single quotes from system() calls.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1190
diff changeset
98 . "-config $d/openssl.conf -subj /CN=$name/ "
0af58b78df35 Tests: removed single quotes from system() calls.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1190
diff changeset
99 . "-out $d/$name.crt -keyout $d/$name.key "
1029
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
100 . ">>$d/openssl.out 2>&1") == 0
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
101 or die "Can't create certificate for $name: $!\n";
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
102 }
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
103
1190
fcd65708672d Tests: let tests pass on travis-ci VMs with disabled IPv6 loopback.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1171
diff changeset
104 $t->try_run('no stream proxy_protocol or inet6 support')->plan(6);
1029
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
105
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
106 ###############################################################################
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
107
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
108 is(pp_get(8083, "PROXY TCP4 192.0.2.1 192.0.2.2 1234 5678${CRLF}"),
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
109 '192.0.2.1:1234', 'server');
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
110
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
111 like(pp_get(8086, "PROXY TCP4 192.0.2.1 192.0.2.2 1234 5678${CRLF}"),
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
112 qr/^(\Q127.0.0.1:\E\d+):\s+\1$/, 'server ipv6 realip - no match');
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
113
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
114 like(pp_get(8087, "PROXY TCP4 192.0.2.1 192.0.2.2 1234 5678${CRLF}"),
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
115 qr/\Q192.0.2.1:1234:\E\s+\Q::1:\E\d+/, 'server ipv6 realip');
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
116
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
117 like(pp_get(8088, "PROXY TCP4 192.0.2.1 192.0.2.2 1234 5678${CRLF}"),
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
118 qr/\Q192.0.2.1:1234:\E\s+\Q127.0.0.1:\E\d+/, 'server ipv4 realip');
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
119
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
120 like(pp_get(8089, "PROXY TCP4 192.0.2.1 192.0.2.2 1234 5678${CRLF}"),
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
121 qr/^(::1:\d+):\s+\1$/, 'server ipv4 realip - no match');
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
122
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
123 like(pp_get(8088, "PROXY UNKNOWN TCP4 192.0.2.1 192.0.2.2 1234 5678${CRLF}"),
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
124 qr/^(\Q127.0.0.1:\E\d+):\s+\1$/, 'server unknown');
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
125
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
126 ###############################################################################
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
127
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
128 sub pp_get {
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
129 my ($port, $proxy) = @_;
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
130
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
131 my $s = stream(PeerPort => port($port));
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
132 $s->write($proxy);
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
133
1168
8821e405b91e Tests: handled SSL negotiation errors.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1116
diff changeset
134 eval {
8821e405b91e Tests: handled SSL negotiation errors.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1116
diff changeset
135 local $SIG{ALRM} = sub { die "timeout\n" };
8821e405b91e Tests: handled SSL negotiation errors.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1116
diff changeset
136 local $SIG{PIPE} = sub { die "sigpipe\n" };
8821e405b91e Tests: handled SSL negotiation errors.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1116
diff changeset
137 alarm(2);
8821e405b91e Tests: handled SSL negotiation errors.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1116
diff changeset
138 IO::Socket::SSL->start_SSL($s->{_socket},
8821e405b91e Tests: handled SSL negotiation errors.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1116
diff changeset
139 SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE(),
8821e405b91e Tests: handled SSL negotiation errors.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1116
diff changeset
140 SSL_error_trap => sub { die $_[1] }
8821e405b91e Tests: handled SSL negotiation errors.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1116
diff changeset
141 );
8821e405b91e Tests: handled SSL negotiation errors.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1116
diff changeset
142 alarm(0);
8821e405b91e Tests: handled SSL negotiation errors.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1116
diff changeset
143 };
8821e405b91e Tests: handled SSL negotiation errors.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1116
diff changeset
144 alarm(0);
8821e405b91e Tests: handled SSL negotiation errors.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1116
diff changeset
145
8821e405b91e Tests: handled SSL negotiation errors.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1116
diff changeset
146 if ($@) {
8821e405b91e Tests: handled SSL negotiation errors.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1116
diff changeset
147 log_in("died: $@");
8821e405b91e Tests: handled SSL negotiation errors.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1116
diff changeset
148 return undef;
8821e405b91e Tests: handled SSL negotiation errors.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1116
diff changeset
149 }
1029
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
150
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
151 return $s->read();
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
152 }
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
153
21602616d8ee Tests: stream realip tests, listen proxy_protocol ssl tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
154 ###############################################################################