Mercurial > hg > nginx-tests
comparison proxy_ssl.t @ 1079:cbc8641a204e
Tests: fixed "proxy connect timeout" http tests.
Previously, proxy connection hadn't been established before delay so
proxy_connect_timeout had no chances to break connection. Now used backend
with delay greater than proxy_connect_timeout value.
author | Andrey Zelenkov <zelenkov@nginx.com> |
---|---|
date | Mon, 21 Nov 2016 02:07:21 +0300 |
parents | 882267679006 |
children | cd4395a68fc6 |
comparison
equal
deleted
inserted
replaced
1078:36437be7b3f4 | 1079:cbc8641a204e |
---|---|
18 | 18 |
19 ############################################################################### | 19 ############################################################################### |
20 | 20 |
21 select STDERR; $| = 1; | 21 select STDERR; $| = 1; |
22 select STDOUT; $| = 1; | 22 select STDOUT; $| = 1; |
23 | |
24 eval { require IO::Socket::SSL; }; | |
25 plan(skip_all => 'IO::Socket::SSL not installed') if $@; | |
23 | 26 |
24 my $t = Test::Nginx->new()->has(qw/http proxy http_ssl/)->has_daemon('openssl') | 27 my $t = Test::Nginx->new()->has(qw/http proxy http_ssl/)->has_daemon('openssl') |
25 ->plan(5)->write_file_expand('nginx.conf', <<'EOF'); | 28 ->plan(5)->write_file_expand('nginx.conf', <<'EOF'); |
26 | 29 |
27 %%TEST_GLOBALS%% | 30 %%TEST_GLOBALS%% |
59 proxy_pass https://127.0.0.1:8081/; | 62 proxy_pass https://127.0.0.1:8081/; |
60 proxy_ssl_session_reuse off; | 63 proxy_ssl_session_reuse off; |
61 } | 64 } |
62 | 65 |
63 location /timeout { | 66 location /timeout { |
64 proxy_pass https://127.0.0.1:8081/; | 67 proxy_pass https://127.0.0.1:8082; |
65 proxy_connect_timeout 2s; | 68 proxy_connect_timeout 2s; |
66 } | 69 } |
67 } | 70 } |
68 } | 71 } |
69 | 72 |
87 . "-out '$d/$name.crt' -keyout '$d/$name.key' " | 90 . "-out '$d/$name.crt' -keyout '$d/$name.key' " |
88 . ">>$d/openssl.out 2>&1") == 0 | 91 . ">>$d/openssl.out 2>&1") == 0 |
89 or die "Can't create certificate for $name: $!\n"; | 92 or die "Can't create certificate for $name: $!\n"; |
90 } | 93 } |
91 | 94 |
95 $t->run_daemon(\&http_daemon, port(8082)); | |
92 $t->run(); | 96 $t->run(); |
97 $t->waitforsocket('127.0.0.1:' . port(8082)); | |
93 | 98 |
94 ############################################################################### | 99 ############################################################################### |
95 | 100 |
96 like(http_get('/ssl'), qr/200 OK.*X-Session: \./s, 'ssl'); | 101 like(http_get('/ssl'), qr/200 OK.*X-Session: \./s, 'ssl'); |
97 like(http_get('/ssl'), qr/200 OK.*X-Session: \./s, 'ssl 2'); | 102 like(http_get('/ssl'), qr/200 OK.*X-Session: \./s, 'ssl 2'); |
98 like(http_get('/ssl_reuse'), qr/200 OK.*X-Session: \./s, 'ssl reuse session'); | 103 like(http_get('/ssl_reuse'), qr/200 OK.*X-Session: \./s, 'ssl reuse session'); |
99 like(http_get('/ssl_reuse'), qr/200 OK.*X-Session: r/s, 'ssl reuse session 2'); | 104 like(http_get('/ssl_reuse'), qr/200 OK.*X-Session: r/s, 'ssl reuse session 2'); |
100 | 105 like(http_get('/timeout'), qr/200 OK/, 'proxy connect timeout'); |
101 my $s = http('', start => 1); | |
102 | |
103 sleep 3; | |
104 | |
105 like(http_get('/timeout', socket => $s), qr/200 OK/, 'proxy connect timeout'); | |
106 | 106 |
107 ############################################################################### | 107 ############################################################################### |
108 | |
109 sub http_daemon { | |
110 my ($port) = @_; | |
111 my $server = IO::Socket::INET->new( | |
112 Proto => 'tcp', | |
113 LocalHost => '127.0.0.1:' . $port, | |
114 Listen => 5, | |
115 Reuse => 1 | |
116 ) | |
117 or die "Can't create listening socket: $!\n"; | |
118 | |
119 local $SIG{PIPE} = 'IGNORE'; | |
120 | |
121 while (my $client = $server->accept()) { | |
122 $client->autoflush(1); | |
123 | |
124 my $headers = ''; | |
125 my $uri = ''; | |
126 | |
127 # would fail on waitforsocket | |
128 | |
129 eval { | |
130 IO::Socket::SSL->start_SSL($client, | |
131 SSL_server => 1, | |
132 SSL_cert_file => "$d/localhost.crt", | |
133 SSL_key_file => "$d/localhost.key", | |
134 SSL_error_trap => sub { die $_[1] } | |
135 ); | |
136 }; | |
137 next if $@; | |
138 | |
139 while (<$client>) { | |
140 $headers .= $_; | |
141 last if (/^\x0d?\x0a?$/); | |
142 } | |
143 | |
144 $uri = $1 if $headers =~ /^\S+\s+([^ ]+)\s+HTTP/i; | |
145 next if $uri eq ''; | |
146 | |
147 if ($uri eq '/timeout') { | |
148 sleep 3; | |
149 | |
150 print $client <<EOF; | |
151 HTTP/1.1 200 OK | |
152 Connection: close | |
153 | |
154 EOF | |
155 } | |
156 | |
157 close $client; | |
158 } | |
159 } | |
160 | |
161 ############################################################################### |