comparison ssl.t @ 1325:f80176242a7e

Tests: c->read->ready handling in ngx_ssl_recv(), fixed in 1.5.8.
author Sergey Kandaurov <pluknet@nginx.com>
date Thu, 17 May 2018 15:43:08 +0300
parents 918bf90466e0
children cb1346b553aa
comparison
equal deleted inserted replaced
1324:918bf90466e0 1325:f80176242a7e
10 10
11 use warnings; 11 use warnings;
12 use strict; 12 use strict;
13 13
14 use Test::More; 14 use Test::More;
15
16 use Socket qw/ CRLF /;
15 17
16 BEGIN { use FindBin; chdir($FindBin::Bin); } 18 BEGIN { use FindBin; chdir($FindBin::Bin); }
17 19
18 use lib 'lib'; 20 use lib 'lib';
19 use Test::Nginx; 21 use Test::Nginx;
26 eval { require IO::Socket::SSL; }; 28 eval { require IO::Socket::SSL; };
27 plan(skip_all => 'IO::Socket::SSL not installed') if $@; 29 plan(skip_all => 'IO::Socket::SSL not installed') if $@;
28 eval { IO::Socket::SSL::SSL_VERIFY_NONE(); }; 30 eval { IO::Socket::SSL::SSL_VERIFY_NONE(); };
29 plan(skip_all => 'IO::Socket::SSL too old') if $@; 31 plan(skip_all => 'IO::Socket::SSL too old') if $@;
30 32
31 my $t = Test::Nginx->new()->has(qw/http http_ssl rewrite/) 33 my $t = Test::Nginx->new()->has(qw/http http_ssl rewrite proxy/)
32 ->has_daemon('openssl')->plan(20); 34 ->has_daemon('openssl')->plan(21);
33 35
34 $t->write_file_expand('nginx.conf', <<'EOF'); 36 $t->write_file_expand('nginx.conf', <<'EOF');
35 37
36 %%TEST_GLOBALS%% 38 %%TEST_GLOBALS%%
37 39
75 location /issuer { 77 location /issuer {
76 return 200 "body $ssl_client_i_dn"; 78 return 200 "body $ssl_client_i_dn";
77 } 79 }
78 location /subject { 80 location /subject {
79 return 200 "body $ssl_client_s_dn"; 81 return 200 "body $ssl_client_s_dn";
82 }
83
84 location /body {
85 add_header X-Body $request_body always;
86 proxy_pass http://127.0.0.1:8080/;
80 } 87 }
81 } 88 }
82 89
83 server { 90 server {
84 listen 127.0.0.1:8081; 91 listen 127.0.0.1:8081;
237 like(get('/client_verify', 8085), qr/^body NONE$/m, 'client verify'); 244 like(get('/client_verify', 8085), qr/^body NONE$/m, 'client verify');
238 like(get('/protocol', 8085), qr/^body (TLS|SSL)v(\d|\.)+$/m, 'protocol'); 245 like(get('/protocol', 8085), qr/^body (TLS|SSL)v(\d|\.)+$/m, 'protocol');
239 like(cert('/issuer', 8085), qr!^body CN=issuer$!m, 'issuer'); 246 like(cert('/issuer', 8085), qr!^body CN=issuer$!m, 'issuer');
240 like(cert('/subject', 8085), qr!^body CN=subject$!m, 'subject'); 247 like(cert('/subject', 8085), qr!^body CN=subject$!m, 'subject');
241 248
249 # c->read->ready handling bug in ngx_ssl_recv(), triggered with chunked body
250
251 like(get_body('/body', '0123456789', 20, 5), qr/X-Body: (0123456789){100}/,
252 'request body chunked');
253
242 ############################################################################### 254 ###############################################################################
243 255
244 sub get { 256 sub get {
245 my ($uri, $port) = @_; 257 my ($uri, $port) = @_;
246 my $s = get_ssl_socket($ctx, port($port)) or return; 258 my $s = get_ssl_socket($ctx, port($port)) or return;
247 my $r = http_get($uri, socket => $s); 259 my $r = http_get($uri, socket => $s);
260 $s->close();
261 return $r;
262 }
263
264 sub get_body {
265 my ($uri, $body, $len, $n) = @_;
266 my $s = get_ssl_socket($ctx, port(8085)) or return;
267 http("GET /body HTTP/1.1" . CRLF
268 . "Host: localhost" . CRLF
269 . "Connection: close" . CRLF
270 . "Transfer-Encoding: chunked" . CRLF . CRLF,
271 socket => $s, start => 1);
272 http("c8" . CRLF . $body x $len . CRLF, socket => $s, start => 1)
273 for 1 .. $n;
274 my $r = http("0" . CRLF . CRLF, socket => $s);
248 $s->close(); 275 $s->close();
249 return $r; 276 return $r;
250 } 277 }
251 278
252 sub cert { 279 sub cert {