Mercurial > hg > nginx-tests
annotate ssl_proxy_upgrade.t @ 1897:38f1fd9ca3e6
Tests: unbreak reading new stderr data after eof.
Tests don't expect to stop reading redirected stderr when end of file is
reached, but rather to read new data being appended, similar to "tail -f".
The behaviour is found changed in Ubuntu 23.04's Perl 5.36, which applies
the upstream patch [1] expected for inclusion in the upcoming Perl 5.38.
The fix is to clear the filehandle's error state to continue reading.
[1] https://github.com/Perl/perl5/commit/80c1f1e45e8e
Updated mail_error_log.t and stream_error_log.t for consistency.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Mon, 29 May 2023 17:27:11 +0400 |
parents | cdcd75657e52 |
children | 6d3a8f4eb9b2 |
rev | line source |
---|---|
585
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Maxim Dounin |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Sergey Kandaurov |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 # (C) Nginx, Inc. |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 # Tests for http proxy upgrade support with http ssl module. |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 # In contrast to proxy_websocket.t, this test doesn't try to use binary |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 # WebSocket protocol, but uses simple plain text protocol instead. |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 ############################################################################### |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use warnings; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 use strict; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 use Test::More; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use IO::Poll; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 use IO::Select; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 use Socket qw/ CRLF /; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 BEGIN { use FindBin; chdir($FindBin::Bin); } |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 use lib 'lib'; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 use Test::Nginx; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 ############################################################################### |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 select STDERR; $| = 1; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 select STDOUT; $| = 1; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 |
1858
cdcd75657e52
Tests: added has_feature() tests for IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1488
diff
changeset
|
32 my $t = Test::Nginx->new()->has(qw/http proxy http_ssl socket_ssl/) |
cdcd75657e52
Tests: added has_feature() tests for IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1488
diff
changeset
|
33 ->has_daemon('openssl') |
585
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 ->write_file_expand('nginx.conf', <<'EOF')->plan(30); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 %%TEST_GLOBALS%% |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 daemon off; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 events { |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 } |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 http { |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 %%TEST_GLOBALS_HTTP%% |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 log_format test "$bytes_sent $body_bytes_sent"; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 access_log %%TESTDIR%%/cc.log test; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
50 listen 127.0.0.1:8080 ssl; |
585
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 server_name localhost; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 ssl_certificate_key localhost.key; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 ssl_certificate localhost.crt; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 location / { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
57 proxy_pass http://127.0.0.1:8081; |
585
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 proxy_http_version 1.1; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 proxy_set_header Upgrade $http_upgrade; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 proxy_set_header Connection "Upgrade"; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 proxy_read_timeout 2s; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 send_timeout 2s; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 } |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 } |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 } |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 EOF |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 $t->write_file('openssl.conf', <<EOF); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 [ req ] |
1488
dbce8fb5f5f8
Tests: align with OpenSSL security level 2.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1240
diff
changeset
|
71 default_bits = 2048 |
585
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 encrypt_key = no |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 distinguished_name = req_distinguished_name |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 [ req_distinguished_name ] |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 EOF |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 my $d = $t->testdir(); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 foreach my $name ('localhost') { |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 system('openssl req -x509 -new ' |
1220
0af58b78df35
Tests: removed single quotes from system() calls.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1156
diff
changeset
|
81 . "-config $d/openssl.conf -subj /CN=$name/ " |
0af58b78df35
Tests: removed single quotes from system() calls.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1156
diff
changeset
|
82 . "-out $d/$name.crt -keyout $d/$name.key " |
585
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 . ">>$d/openssl.out 2>&1") == 0 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 or die "Can't create certificate for $name: $!\n"; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 } |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 $t->run_daemon(\&upgrade_fake_daemon); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 $t->run(); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
90 $t->waitforsocket('127.0.0.1:' . port(8081)) |
585
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
91 or die "Can't start test backend"; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
92 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
93 ############################################################################### |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
94 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
95 # establish connection |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
96 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
97 my @r; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
98 my $s = upgrade_connect(); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
99 ok($s, "handshake"); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
100 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
101 SKIP: { |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
102 skip "handshake failed", 22 unless $s; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
103 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
104 # send a frame |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
105 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
106 upgrade_write($s, 'foo'); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
107 is(upgrade_read($s), 'bar', "upgrade response"); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
108 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
109 # send some big frame |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
110 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
111 upgrade_write($s, 'foo' x 16384); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
112 like(upgrade_read($s), qr/^(bar){16384}$/, "upgrade big response"); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
113 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
114 # send multiple frames |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
115 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
116 for my $i (1 .. 10) { |
1240
f7eb2875ed45
Tests: avoid interleaved output in Upgrade handling tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1220
diff
changeset
|
117 upgrade_write($s, ('foo' x 16384) . $i, continue => 1); |
f7eb2875ed45
Tests: avoid interleaved output in Upgrade handling tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1220
diff
changeset
|
118 upgrade_write($s, 'bazz' . $i, continue => $i != 10); |
585
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
119 } |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
120 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
121 for my $i (1 .. 10) { |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
122 like(upgrade_read($s), qr/^(bar){16384}\d+$/, "upgrade $i"); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
123 is(upgrade_read($s), 'bazz' . $i, "upgrade small $i"); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
124 } |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
125 } |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
126 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
127 push @r, $s ? ${*$s}->{_upgrade_private}->{r} : 'failed'; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
128 undef $s; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
129 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
130 # establish connection with some pipelined data |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
131 # and make sure they are correctly passed upstream |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
132 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
133 $s = upgrade_connect(message => "foo"); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
134 ok($s, "handshake pipelined"); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
135 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
136 SKIP: { |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
137 skip "handshake failed", 2 unless $s; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
138 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
139 is(upgrade_read($s), "bar", "response pipelined"); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
140 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
141 upgrade_write($s, "foo"); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
142 is(upgrade_read($s), "bar", "next to pipelined"); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
143 } |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
144 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
145 push @r, $s ? ${*$s}->{_upgrade_private}->{r} : 'failed'; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
146 undef $s; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
147 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
148 # connection should not be upgraded unless upgrade was actually |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
149 # requested and allowed by configuration |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
150 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
151 $s = upgrade_connect(noheader => 1); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
152 ok(!$s, "handshake noupgrade"); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
153 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
154 # bytes sent on upgraded connection, fixed in c2f309fb7ad2 (1.7.11) |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
155 # verify with 1) data actually read by client, 2) expected data from backend |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
156 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
157 $t->stop(); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
158 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
159 open my $f, '<', "$d/cc.log" or die "Can't open cc.log: $!"; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
160 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
161 is($f->getline(), shift (@r) . " 540793\n", 'log - bytes'); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
162 is($f->getline(), shift (@r) . " 22\n", 'log - bytes pipelined'); |
665
3a8dc14b98ba
Tests: fixed Upgrade handling tests without client abort detection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
602
diff
changeset
|
163 like($f->getline(), qr/\d+ 0\n/, 'log - bytes noupgrade'); |
585
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
164 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
165 ############################################################################### |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
166 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
167 sub upgrade_connect { |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
168 my (%opts) = @_; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
169 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
170 my $s = IO::Socket::SSL->new( |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
171 Proto => 'tcp', |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
172 PeerAddr => '127.0.0.1:' . port(8080), |
585
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
173 SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE(), |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
174 ) |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
175 or die "Can't connect to nginx: $!\n"; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
176 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
177 # send request, $h->to_string |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
178 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
179 my $buf = "GET / HTTP/1.1" . CRLF |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
180 . "Host: localhost" . CRLF |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
181 . ($opts{noheader} ? '' : "Upgrade: foo" . CRLF) |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
182 . "Connection: Upgrade" . CRLF . CRLF; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
183 |
1240
f7eb2875ed45
Tests: avoid interleaved output in Upgrade handling tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1220
diff
changeset
|
184 $buf .= $opts{message} . CRLF . 'FIN' if defined $opts{message}; |
585
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
185 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
186 local $SIG{PIPE} = 'IGNORE'; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
187 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
188 log_out($buf); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
189 $s->syswrite($buf); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
190 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
191 # read response |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
192 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
193 my $got = ''; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
194 $buf = ''; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
195 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
196 while (1) { |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
197 $buf = upgrade_getline($s); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
198 last unless defined $buf and length $buf; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
199 log_in($buf); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
200 $got .= $buf; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
201 last if $got =~ /\x0d?\x0a\x0d?\x0a$/; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
202 } |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
203 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
204 # parse server response |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
205 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
206 return if $got !~ m!HTTP/1.1 101!; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
207 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
208 # make sure next line is "handshaked" |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
209 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
210 $buf = upgrade_read($s); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
211 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
212 return if !defined $buf or $buf ne 'handshaked'; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
213 return $s; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
214 } |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
215 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
216 sub upgrade_getline { |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
217 my ($s) = @_; |
925
6bb1f2ccd386
Tests: removed unused variables.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
665
diff
changeset
|
218 my ($h, $buf); |
585
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
219 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
220 ${*$s}->{_upgrade_private} ||= { b => '', r => 0 }; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
221 $h = ${*$s}->{_upgrade_private}; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
222 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
223 if ($h->{b} =~ /^(.*?\x0a)(.*)/ms) { |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
224 $h->{b} = $2; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
225 return $1; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
226 } |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
227 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
228 $s->blocking(0); |
1155
d37983612b04
Tests: adjusted read timeout in proxy upgrade tests for slow hosts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1116
diff
changeset
|
229 while (IO::Select->new($s)->can_read(3)) { |
602
1177e4dd249a
Tests: read in full-size SSL records in ssl_proxy_upgrade.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
591
diff
changeset
|
230 my $n = $s->sysread($buf, 16384); |
1156
d12c45f14102
Tests: handled EOF in ssl_proxy_upgrade.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1155
diff
changeset
|
231 if (!defined $n) { |
591
0b059d5e6887
Tests: retry on SSL_WANT_READ in ssl_proxy_upgrade.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
232 next if $s->errstr() == IO::Socket::SSL->SSL_WANT_READ; |
0b059d5e6887
Tests: retry on SSL_WANT_READ in ssl_proxy_upgrade.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
233 last; |
1156
d12c45f14102
Tests: handled EOF in ssl_proxy_upgrade.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1155
diff
changeset
|
234 |
d12c45f14102
Tests: handled EOF in ssl_proxy_upgrade.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1155
diff
changeset
|
235 } elsif (!$n) { |
d12c45f14102
Tests: handled EOF in ssl_proxy_upgrade.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1155
diff
changeset
|
236 last; |
591
0b059d5e6887
Tests: retry on SSL_WANT_READ in ssl_proxy_upgrade.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
237 } |
585
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
238 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
239 $h->{b} .= $buf; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
240 $h->{r} += $n; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
241 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
242 if ($h->{b} =~ /^(.*?\x0a)(.*)/ms) { |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
243 $h->{b} = $2; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
244 return $1; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
245 } |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
246 }; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
247 } |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
248 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
249 sub upgrade_write { |
1240
f7eb2875ed45
Tests: avoid interleaved output in Upgrade handling tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1220
diff
changeset
|
250 my ($s, $message, %extra) = @_; |
585
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
251 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
252 $message = $message . CRLF; |
1240
f7eb2875ed45
Tests: avoid interleaved output in Upgrade handling tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1220
diff
changeset
|
253 $message = $message . 'FIN' unless $extra{continue}; |
585
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
254 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
255 local $SIG{PIPE} = 'IGNORE'; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
256 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
257 $s->blocking(0); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
258 while (IO::Select->new($s)->can_write(1.5)) { |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
259 my $n = $s->syswrite($message); |
588
53b7c3c33a79
Tests: retry on SSL_WANT_WRITE in ssl_proxy_upgrade.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
585
diff
changeset
|
260 unless ($n) { |
53b7c3c33a79
Tests: retry on SSL_WANT_WRITE in ssl_proxy_upgrade.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
585
diff
changeset
|
261 next if $s->errstr() == IO::Socket::SSL->SSL_WANT_WRITE; |
53b7c3c33a79
Tests: retry on SSL_WANT_WRITE in ssl_proxy_upgrade.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
585
diff
changeset
|
262 last; |
53b7c3c33a79
Tests: retry on SSL_WANT_WRITE in ssl_proxy_upgrade.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
585
diff
changeset
|
263 } |
585
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
264 $message = substr($message, $n); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
265 last unless length $message; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
266 } |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
267 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
268 if (length $message) { |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
269 $s->close(); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
270 } |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
271 } |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
272 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
273 sub upgrade_read { |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
274 my ($s) = @_; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
275 my $m = upgrade_getline($s); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
276 $m =~ s/\x0d?\x0a// if defined $m; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
277 log_in($m); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
278 return $m; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
279 } |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
280 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
281 ############################################################################### |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
282 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
283 sub upgrade_fake_daemon { |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
284 my $server = IO::Socket::INET->new( |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
285 Proto => 'tcp', |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
286 LocalAddr => '127.0.0.1:' . port(8081), |
585
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
287 Listen => 5, |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
288 Reuse => 1 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
289 ) |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
290 or die "Can't create listening socket: $!\n"; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
291 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
292 while (my $client = $server->accept()) { |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
293 upgrade_handle_client($client); |
589
a9569f57da98
Tests: whitespaces fix.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
588
diff
changeset
|
294 } |
585
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
295 } |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
296 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
297 sub upgrade_handle_client { |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
298 my ($client) = @_; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
299 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
300 $client->autoflush(1); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
301 $client->blocking(0); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
302 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
303 my $poll = IO::Poll->new; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
304 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
305 my $handshake = 1; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
306 my $unfinished = ''; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
307 my $buffer = ''; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
308 my $n; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
309 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
310 log2c("(new connection $client)"); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
311 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
312 while (1) { |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
313 $poll->mask($client => ($buffer ? POLLIN|POLLOUT : POLLIN)); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
314 my $p = $poll->poll(0.5); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
315 log2c("(poll $p)"); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
316 |
925
6bb1f2ccd386
Tests: removed unused variables.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
665
diff
changeset
|
317 foreach ($poll->handles(POLLIN)) { |
585
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
318 $n = $client->sysread(my $chunk, 65536); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
319 return unless $n; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
320 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
321 log2i($chunk); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
322 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
323 if ($handshake) { |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
324 $buffer .= $chunk; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
325 next unless $buffer =~ /\x0d?\x0a\x0d?\x0a$/; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
326 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
327 log2c("(handshake done)"); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
328 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
329 $handshake = 0; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
330 $buffer = 'HTTP/1.1 101 Switching' . CRLF |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
331 . 'Upgrade: foo' . CRLF |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
332 . 'Connection: Upgrade' . CRLF . CRLF |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
333 . 'handshaked' . CRLF; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
334 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
335 log2o($buffer); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
336 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
337 next; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
338 } |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
339 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
340 $unfinished .= $chunk; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
341 |
1240
f7eb2875ed45
Tests: avoid interleaved output in Upgrade handling tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1220
diff
changeset
|
342 if ($unfinished =~ m/\x0d?\x0aFIN\z/) { |
f7eb2875ed45
Tests: avoid interleaved output in Upgrade handling tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1220
diff
changeset
|
343 $unfinished =~ s/FIN\z//; |
585
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
344 $unfinished =~ s/foo/bar/g; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
345 log2o($unfinished); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
346 $buffer .= $unfinished; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
347 $unfinished = ''; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
348 } |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
349 } |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
350 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
351 foreach my $writer ($poll->handles(POLLOUT)) { |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
352 next unless length $buffer; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
353 $n = $writer->syswrite($buffer); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
354 substr $buffer, 0, $n, ''; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
355 } |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
356 } |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
357 } |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
358 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
359 sub log2i { Test::Nginx::log_core('|| <<', @_); } |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
360 sub log2o { Test::Nginx::log_core('|| >>', @_); } |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
361 sub log2c { Test::Nginx::log_core('||', @_); } |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
362 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
363 ############################################################################### |