Mercurial > hg > nginx-tests
annotate stream_proxy_protocol_ssl.t @ 1568:4cc012205ac5
Tests: added js tests for raw headers API.
author | Dmitry Volyntsev <xeioex@nginx.com> |
---|---|
date | Wed, 06 May 2020 12:52:17 +0000 |
parents | dbce8fb5f5f8 |
children | f3ba4c74de31 |
rev | line source |
---|---|
615
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for stream proxy module with haproxy protocol to ssl backend. |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 use Socket qw/ CR LF CRLF /; |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 BEGIN { use FindBin; chdir($FindBin::Bin); } |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 use lib 'lib'; |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 use Test::Nginx qw/ :DEFAULT http_end /; |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 ############################################################################### |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 select STDERR; $| = 1; |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 select STDOUT; $| = 1; |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 eval { require IO::Socket::SSL; }; |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 plan(skip_all => 'IO::Socket::SSL not installed') if $@; |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 |
1020
196d33c2bb45
Tests: removed TODO and try_run() checks for legacy versions.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
974
diff
changeset
|
30 my $t = Test::Nginx->new()->has(qw/stream stream_ssl/)->has_daemon('openssl') |
196d33c2bb45
Tests: removed TODO and try_run() checks for legacy versions.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
974
diff
changeset
|
31 ->plan(2); |
615
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 $t->write_file_expand('nginx.conf', <<'EOF'); |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 %%TEST_GLOBALS%% |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 daemon off; |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 events { |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 } |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 stream { |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 proxy_ssl on; |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 proxy_protocol on; |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
47 listen 127.0.0.1:8080; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
48 proxy_pass 127.0.0.1:8081; |
615
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 } |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
52 listen 127.0.0.1:8082; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
53 proxy_pass 127.0.0.1:8083; |
615
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 proxy_protocol off; |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 } |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 } |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 EOF |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 $t->write_file('openssl.conf', <<EOF); |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 [ req ] |
1488
dbce8fb5f5f8
Tests: align with OpenSSL security level 2.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1220
diff
changeset
|
62 default_bits = 2048 |
615
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 encrypt_key = no |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 distinguished_name = req_distinguished_name |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 [ req_distinguished_name ] |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 EOF |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 my $d = $t->testdir(); |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 foreach my $name ('localhost') { |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 system('openssl req -x509 -new ' |
1220
0af58b78df35
Tests: removed single quotes from system() calls.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1116
diff
changeset
|
72 . "-config $d/openssl.conf -subj /CN=$name/ " |
0af58b78df35
Tests: removed single quotes from system() calls.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1116
diff
changeset
|
73 . "-out $d/$name.crt -keyout $d/$name.key " |
615
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 . ">>$d/openssl.out 2>&1") == 0 |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 or die "Can't create certificate for $name: $!\n"; |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 } |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
78 $t->run_daemon(\&stream_daemon_ssl, port(8081), path => $d, pp => 1); |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
79 $t->run_daemon(\&stream_daemon_ssl, port(8083), path => $d, pp => 0); |
1020
196d33c2bb45
Tests: removed TODO and try_run() checks for legacy versions.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
974
diff
changeset
|
80 $t->run(); |
615
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
82 $t->waitforsocket('127.0.0.1:' . port(8081)); |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
83 $t->waitforsocket('127.0.0.1:' . port(8083)); |
615
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 ############################################################################### |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
87 my $dp = port(8080); |
952
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
808
diff
changeset
|
88 |
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
808
diff
changeset
|
89 my %r = pp_get('test', '127.0.0.1:' . $dp); |
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
808
diff
changeset
|
90 is($r{'data'}, "PROXY TCP4 127.0.0.1 127.0.0.1 $r{'sp'} $dp" . CRLF . 'test', |
615
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
91 'protocol on'); |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
92 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
93 %r = pp_get('test', '127.0.0.1:' . port(8082)); |
615
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
94 is($r{'data'}, 'test', 'protocol off'); |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
95 |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
96 ############################################################################### |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
97 |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
98 sub pp_get { |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
99 my ($data, $peer) = @_; |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
100 |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
101 my $s = http($data, socket => getconn($peer), start => 1); |
633 | 102 my $sockport = $s->sockport(); |
615
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
103 $data = http_end($s); |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
104 return ('data' => $data, 'sp' => $sockport); |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
105 } |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
106 |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
107 sub getconn { |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
108 my $peer = shift; |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
109 my $s = IO::Socket::INET->new( |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
110 Proto => 'tcp', |
952
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
808
diff
changeset
|
111 PeerAddr => $peer |
615
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
112 ) |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
113 or die "Can't connect to nginx: $!\n"; |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
114 |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
115 return $s; |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
116 } |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
117 |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
118 ############################################################################### |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
119 |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
120 sub stream_daemon_ssl { |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
121 my ($port, %extra) = @_; |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
122 my $d = $extra{path}; |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
123 my $pp = $extra{pp}; |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
124 my $server = IO::Socket::INET->new( |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
125 Proto => 'tcp', |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
126 LocalHost => "127.0.0.1:$port", |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
127 Listen => 5, |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
128 Reuse => 1 |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
129 ) |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
130 or die "Can't create listening socket: $!\n"; |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
131 |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
132 local $SIG{PIPE} = 'IGNORE'; |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
133 |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
134 while (my $client = $server->accept()) { |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
135 my ($buffer, $data) = ('', ''); |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
136 $client->autoflush(1); |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
137 |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
138 log2c("(new connection $client on $port)"); |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
139 |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
140 # read no more than haproxy header of variable length |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
141 |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
142 while ($pp) { |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
143 my $prev = $buffer; |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
144 $client->sysread($buffer, 1) or last; |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
145 $data .= $buffer; |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
146 last if $prev eq CR && $buffer eq LF; |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
147 } |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
148 |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
149 log2i("$client $data"); |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
150 |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
151 # would fail on waitforsocket |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
152 |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
153 eval { |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
154 IO::Socket::SSL->start_SSL($client, |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
155 SSL_server => 1, |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
156 SSL_cert_file => "$d/localhost.crt", |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
157 SSL_key_file => "$d/localhost.key", |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
158 SSL_error_trap => sub { die $_[1] } |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
159 ); |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
160 }; |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
161 next if $@; |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
162 |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
163 $client->sysread($buffer, 65536) or next; |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
164 |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
165 log2i("$client $buffer"); |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
166 |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
167 $data .= $buffer; |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
168 |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
169 log2o("$client $data"); |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
170 |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
171 $client->syswrite($data); |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
172 |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
173 close $client; |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
174 } |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
175 } |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
176 |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
177 sub log2i { Test::Nginx::log_core('|| <<', @_); } |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
178 sub log2o { Test::Nginx::log_core('|| >>', @_); } |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
179 sub log2c { Test::Nginx::log_core('||', @_); } |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
180 |
f27fb891503c
Tests: stream proxy protocol tests to ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
181 ############################################################################### |