annotate ssl_proxy_upgrade.t @ 1021:ebdf239722b9

Tests: relaxed proxy_cache_lock.t nolock tests to fix on Solaris. Assumed that the order of responses being arrived in nolock case may be ignored. An important part of such case is that the only last response should be cached.
author Sergey Kandaurov <pluknet@nginx.com>
date Fri, 02 Sep 2016 12:17:35 +0300
parents 882267679006
children 8ef51dbb5d69
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
32 eval { require IO::Socket::SSL; };
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
33 plan(skip_all => 'IO::Socket::SSL not installed') if $@;
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
34 eval { IO::Socket::SSL::SSL_VERIFY_NONE(); };
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
35 plan(skip_all => 'IO::Socket::SSL too old') if $@;
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
36
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
37 my $t = Test::Nginx->new()->has(qw/http proxy http_ssl/)->has_daemon('openssl')
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
38 ->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
39
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
40 %%TEST_GLOBALS%%
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 daemon off;
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
43
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
44 events {
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
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
47 http {
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
48 %%TEST_GLOBALS_HTTP%%
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
49
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
50 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
51 access_log %%TESTDIR%%/cc.log test;
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 server {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
54 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
55 server_name localhost;
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
56
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
57 ssl_certificate_key localhost.key;
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
58 ssl_certificate localhost.crt;
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
59
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
60 location / {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
61 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
62 proxy_http_version 1.1;
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
63 proxy_set_header Upgrade $http_upgrade;
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
64 proxy_set_header Connection "Upgrade";
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
65 proxy_read_timeout 2s;
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
66 send_timeout 2s;
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
67 }
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 }
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
70
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
71 EOF
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
72
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
73 $t->write_file('openssl.conf', <<EOF);
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
74 [ req ]
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
75 default_bits = 2048
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
76 encrypt_key = no
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
77 distinguished_name = req_distinguished_name
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
78 [ req_distinguished_name ]
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
79 EOF
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
80
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
81 my $d = $t->testdir();
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
82
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
83 foreach my $name ('localhost') {
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
84 system('openssl req -x509 -new '
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
85 . "-config '$d/openssl.conf' -subj '/CN=$name/' "
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
86 . "-out '$d/$name.crt' -keyout '$d/$name.key' "
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
87 . ">>$d/openssl.out 2>&1") == 0
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
88 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
89 }
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
90
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
91 $t->run_daemon(\&upgrade_fake_daemon);
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
92 $t->run();
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
93
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
94 $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
95 or die "Can't start test backend";
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 ###############################################################################
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
98
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
99 # establish connection
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 my @r;
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
102 my $s = upgrade_connect();
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
103 ok($s, "handshake");
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
104
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
105 SKIP: {
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
106 skip "handshake failed", 22 unless $s;
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
107
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
108 # send a frame
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
109
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
110 upgrade_write($s, 'foo');
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
111 is(upgrade_read($s), 'bar', "upgrade response");
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
112
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
113 # send some big frame
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
114
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
115 upgrade_write($s, 'foo' x 16384);
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
116 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
117
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
118 # send multiple frames
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 for my $i (1 .. 10) {
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
121 upgrade_write($s, ('foo' x 16384) . $i);
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
122 upgrade_write($s, 'bazz' . $i);
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
123 }
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 for my $i (1 .. 10) {
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
126 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
127 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
128 }
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
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
131 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
132 undef $s;
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
133
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
134 # establish connection with some pipelined data
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
135 # 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
136
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
137 $s = upgrade_connect(message => "foo");
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
138 ok($s, "handshake pipelined");
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
139
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
140 SKIP: {
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
141 skip "handshake failed", 2 unless $s;
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
142
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
143 is(upgrade_read($s), "bar", "response pipelined");
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 upgrade_write($s, "foo");
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
146 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
147 }
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
148
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
149 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
150 undef $s;
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
151
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
152 # 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
153 # requested and allowed by configuration
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
154
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
155 $s = upgrade_connect(noheader => 1);
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
156 ok(!$s, "handshake noupgrade");
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
157
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
158 # 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
159 # 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
160
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
161 $t->stop();
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
162
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
163 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
164
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
165 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
166 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
167 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
168
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
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
171 sub upgrade_connect {
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
172 my (%opts) = @_;
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
173
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
174 my $s = IO::Socket::SSL->new(
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
175 Proto => 'tcp',
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
176 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
177 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
178 )
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
179 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
180
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
181 # send request, $h->to_string
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
182
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
183 my $buf = "GET / HTTP/1.1" . CRLF
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
184 . "Host: localhost" . CRLF
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
185 . ($opts{noheader} ? '' : "Upgrade: foo" . CRLF)
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
186 . "Connection: Upgrade" . CRLF . CRLF;
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 $buf .= $opts{message} . CRLF if defined $opts{message};
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
189
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
190 local $SIG{PIPE} = 'IGNORE';
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 log_out($buf);
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
193 $s->syswrite($buf);
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
194
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
195 # read response
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 my $got = '';
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
198 $buf = '';
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
199
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
200 while (1) {
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
201 $buf = upgrade_getline($s);
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
202 last unless defined $buf and length $buf;
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
203 log_in($buf);
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
204 $got .= $buf;
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
205 last if $got =~ /\x0d?\x0a\x0d?\x0a$/;
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
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
208 # parse server response
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 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
211
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
212 # make sure next line is "handshaked"
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
213
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
214 $buf = upgrade_read($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 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
217 return $s;
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
218 }
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 sub upgrade_getline {
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
221 my ($s) = @_;
925
6bb1f2ccd386 Tests: removed unused variables.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 665
diff changeset
222 my ($h, $buf);
585
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 ${*$s}->{_upgrade_private} ||= { b => '', r => 0 };
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
225 $h = ${*$s}->{_upgrade_private};
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 if ($h->{b} =~ /^(.*?\x0a)(.*)/ms) {
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
228 $h->{b} = $2;
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
229 return $1;
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
230 }
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
231
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
232 $s->blocking(0);
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
233 while (IO::Select->new($s)->can_read(1.5)) {
602
1177e4dd249a Tests: read in full-size SSL records in ssl_proxy_upgrade.t.
Sergey Kandaurov <pluknet@nginx.com>
parents: 591
diff changeset
234 my $n = $s->sysread($buf, 16384);
591
0b059d5e6887 Tests: retry on SSL_WANT_READ in ssl_proxy_upgrade.t.
Sergey Kandaurov <pluknet@nginx.com>
parents: 589
diff changeset
235 unless ($n) {
0b059d5e6887 Tests: retry on SSL_WANT_READ in ssl_proxy_upgrade.t.
Sergey Kandaurov <pluknet@nginx.com>
parents: 589
diff changeset
236 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
237 last;
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 {
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
251 my ($s, $message) = @_;
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;
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
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
342 if ($unfinished =~ m/\x0d?\x0a\z/) {
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
343 $unfinished =~ s/foo/bar/g;
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
344 log2o($unfinished);
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
345 $buffer .= $unfinished;
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
346 $unfinished = '';
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
347 }
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 foreach my $writer ($poll->handles(POLLOUT)) {
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
351 next unless length $buffer;
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
352 $n = $writer->syswrite($buffer);
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
353 substr $buffer, 0, $n, '';
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
354 }
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 sub log2i { Test::Nginx::log_core('|| <<', @_); }
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
359 sub log2o { Test::Nginx::log_core('|| >>', @_); }
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
360 sub log2c { Test::Nginx::log_core('||', @_); }
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
361
5bb19f7448b5 Tests: Upgrade handling tests with http ssl module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
362 ###############################################################################