Mercurial > hg > nginx-tests
annotate ssl_proxy_upgrade.t @ 1990:85d88cd5091c
Tests: SSI include stub tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 04 Jul 2024 17:42:55 +0300 |
parents | 6d3a8f4eb9b2 |
children |
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), |
1970
6d3a8f4eb9b2
Tests: relaxed SSL version used in testing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1858
diff
changeset
|
173 SSL_version => 'SSLv23', |
585
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
174 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
|
175 ) |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
176 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
|
177 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
178 # send request, $h->to_string |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
179 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
180 my $buf = "GET / HTTP/1.1" . CRLF |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
181 . "Host: localhost" . CRLF |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
182 . ($opts{noheader} ? '' : "Upgrade: foo" . CRLF) |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
183 . "Connection: Upgrade" . CRLF . CRLF; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
184 |
1240
f7eb2875ed45
Tests: avoid interleaved output in Upgrade handling tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1220
diff
changeset
|
185 $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
|
186 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
187 local $SIG{PIPE} = 'IGNORE'; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
188 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
189 log_out($buf); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
190 $s->syswrite($buf); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
191 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
192 # read response |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
193 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
194 my $got = ''; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
195 $buf = ''; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
196 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
197 while (1) { |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
198 $buf = upgrade_getline($s); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
199 last unless defined $buf and length $buf; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
200 log_in($buf); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
201 $got .= $buf; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
202 last if $got =~ /\x0d?\x0a\x0d?\x0a$/; |
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 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
205 # parse server response |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
206 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
207 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
|
208 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
209 # make sure next line is "handshaked" |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
210 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
211 $buf = upgrade_read($s); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
212 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
213 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
|
214 return $s; |
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 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
217 sub upgrade_getline { |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
218 my ($s) = @_; |
925
6bb1f2ccd386
Tests: removed unused variables.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
665
diff
changeset
|
219 my ($h, $buf); |
585
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
220 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
221 ${*$s}->{_upgrade_private} ||= { b => '', r => 0 }; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
222 $h = ${*$s}->{_upgrade_private}; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
223 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
224 if ($h->{b} =~ /^(.*?\x0a)(.*)/ms) { |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
225 $h->{b} = $2; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
226 return $1; |
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 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
229 $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
|
230 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
|
231 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
|
232 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
|
233 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
|
234 last; |
1156
d12c45f14102
Tests: handled EOF in ssl_proxy_upgrade.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1155
diff
changeset
|
235 |
d12c45f14102
Tests: handled EOF in ssl_proxy_upgrade.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1155
diff
changeset
|
236 } elsif (!$n) { |
d12c45f14102
Tests: handled EOF in ssl_proxy_upgrade.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1155
diff
changeset
|
237 last; |
591
0b059d5e6887
Tests: retry on SSL_WANT_READ in ssl_proxy_upgrade.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
238 } |
585
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
239 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
240 $h->{b} .= $buf; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
241 $h->{r} += $n; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
242 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
243 if ($h->{b} =~ /^(.*?\x0a)(.*)/ms) { |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
244 $h->{b} = $2; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
245 return $1; |
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 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
250 sub upgrade_write { |
1240
f7eb2875ed45
Tests: avoid interleaved output in Upgrade handling tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1220
diff
changeset
|
251 my ($s, $message, %extra) = @_; |
585
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
252 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
253 $message = $message . CRLF; |
1240
f7eb2875ed45
Tests: avoid interleaved output in Upgrade handling tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1220
diff
changeset
|
254 $message = $message . 'FIN' unless $extra{continue}; |
585
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
255 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
256 local $SIG{PIPE} = 'IGNORE'; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
257 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
258 $s->blocking(0); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
259 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
|
260 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
|
261 unless ($n) { |
53b7c3c33a79
Tests: retry on SSL_WANT_WRITE in ssl_proxy_upgrade.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
585
diff
changeset
|
262 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
|
263 last; |
53b7c3c33a79
Tests: retry on SSL_WANT_WRITE in ssl_proxy_upgrade.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
585
diff
changeset
|
264 } |
585
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
265 $message = substr($message, $n); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
266 last unless length $message; |
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 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
269 if (length $message) { |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
270 $s->close(); |
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 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
274 sub upgrade_read { |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
275 my ($s) = @_; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
276 my $m = upgrade_getline($s); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
277 $m =~ s/\x0d?\x0a// if defined $m; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
278 log_in($m); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
279 return $m; |
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 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
284 sub upgrade_fake_daemon { |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
285 my $server = IO::Socket::INET->new( |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
286 Proto => 'tcp', |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
287 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
|
288 Listen => 5, |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
289 Reuse => 1 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
290 ) |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
291 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
|
292 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
293 while (my $client = $server->accept()) { |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
294 upgrade_handle_client($client); |
589
a9569f57da98
Tests: whitespaces fix.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
588
diff
changeset
|
295 } |
585
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 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
298 sub upgrade_handle_client { |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
299 my ($client) = @_; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
300 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
301 $client->autoflush(1); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
302 $client->blocking(0); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
303 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
304 my $poll = IO::Poll->new; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
305 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
306 my $handshake = 1; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
307 my $unfinished = ''; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
308 my $buffer = ''; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
309 my $n; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
310 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
311 log2c("(new connection $client)"); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
312 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
313 while (1) { |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
314 $poll->mask($client => ($buffer ? POLLIN|POLLOUT : POLLIN)); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
315 my $p = $poll->poll(0.5); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
316 log2c("(poll $p)"); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
317 |
925
6bb1f2ccd386
Tests: removed unused variables.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
665
diff
changeset
|
318 foreach ($poll->handles(POLLIN)) { |
585
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
319 $n = $client->sysread(my $chunk, 65536); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
320 return unless $n; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
321 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
322 log2i($chunk); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
323 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
324 if ($handshake) { |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
325 $buffer .= $chunk; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
326 next unless $buffer =~ /\x0d?\x0a\x0d?\x0a$/; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
327 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
328 log2c("(handshake done)"); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
329 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
330 $handshake = 0; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
331 $buffer = 'HTTP/1.1 101 Switching' . CRLF |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
332 . 'Upgrade: foo' . CRLF |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
333 . 'Connection: Upgrade' . CRLF . CRLF |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
334 . 'handshaked' . CRLF; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
335 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
336 log2o($buffer); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
337 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
338 next; |
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 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
341 $unfinished .= $chunk; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
342 |
1240
f7eb2875ed45
Tests: avoid interleaved output in Upgrade handling tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1220
diff
changeset
|
343 if ($unfinished =~ m/\x0d?\x0aFIN\z/) { |
f7eb2875ed45
Tests: avoid interleaved output in Upgrade handling tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1220
diff
changeset
|
344 $unfinished =~ s/FIN\z//; |
585
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
345 $unfinished =~ s/foo/bar/g; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
346 log2o($unfinished); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
347 $buffer .= $unfinished; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
348 $unfinished = ''; |
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 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
352 foreach my $writer ($poll->handles(POLLOUT)) { |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
353 next unless length $buffer; |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
354 $n = $writer->syswrite($buffer); |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
355 substr $buffer, 0, $n, ''; |
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 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
360 sub log2i { Test::Nginx::log_core('|| <<', @_); } |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
361 sub log2o { Test::Nginx::log_core('|| >>', @_); } |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
362 sub log2c { Test::Nginx::log_core('||', @_); } |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
363 |
5bb19f7448b5
Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
364 ############################################################################### |