comparison h2.t @ 822:92e20c77c916

Tests: added HTTP/2 discarded request body tests with limit_req.
author Sergey Kandaurov <pluknet@nginx.com>
date Tue, 26 Jan 2016 20:20:53 +0300
parents d75000247e1f
children 5c003c3b8e9e
comparison
equal deleted inserted replaced
821:d75000247e1f 822:92e20c77c916
30 eval { IO::Socket::SSL::SSL_VERIFY_NONE(); }; 30 eval { IO::Socket::SSL::SSL_VERIFY_NONE(); };
31 plan(skip_all => 'IO::Socket::SSL too old') if $@; 31 plan(skip_all => 'IO::Socket::SSL too old') if $@;
32 32
33 my $t = Test::Nginx->new()->has(qw/http http_ssl http_v2 proxy cache/) 33 my $t = Test::Nginx->new()->has(qw/http http_ssl http_v2 proxy cache/)
34 ->has(qw/limit_conn rewrite realip shmem/) 34 ->has(qw/limit_conn rewrite realip shmem/)
35 ->has_daemon('openssl')->plan(293); 35 ->has_daemon('openssl')->plan(296);
36 36
37 # Some systems may have also a bug in not treating zero writev iovcnt as EINVAL 37 # Some systems may have also a bug in not treating zero writev iovcnt as EINVAL
38 38
39 $t->todo_alerts(); 39 $t->todo_alerts();
40 40
145 } 145 }
146 location /proxy2/ { 146 location /proxy2/ {
147 add_header X-Body "$request_body"; 147 add_header X-Body "$request_body";
148 proxy_pass http://127.0.0.1:8081/; 148 proxy_pass http://127.0.0.1:8081/;
149 } 149 }
150 location /limit_req {
151 limit_req zone=req burst=2;
152 alias %%TESTDIR%%/t2.html;
153 }
150 location /proxy_limit_req/ { 154 location /proxy_limit_req/ {
151 add_header X-Body $request_body; 155 add_header X-Body $request_body;
152 proxy_pass http://127.0.0.1:8081/; 156 proxy_pass http://127.0.0.1:8081/;
153 limit_req zone=req burst=2; 157 limit_req zone=req burst=2;
154 } 158 }
1446 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; 1450 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
1447 is($frame->{headers}->{'x-body'}, 'TEST2', 'request body - limit req 2'); 1451 is($frame->{headers}->{'x-body'}, 'TEST2', 'request body - limit req 2');
1448 1452
1449 } 1453 }
1450 1454
1455 # partial request body data frame received (to be discarded) within request
1456 # delayed in limit_req, the rest of data frame is received after response
1457
1458 $sess = new_session();
1459
1460 TODO: {
1461 todo_skip 'use-after-free', 1 unless $ENV{TEST_NGINX_UNSAFE};
1462
1463 $sid = new_stream($sess, { path => '/limit_req', body => 'TEST', split => [61],
1464 split_delay => 1.1 });
1465 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]);
1466
1467 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
1468 is($frame->{headers}->{':status'}, '200', 'discard body - limit req - limited');
1469
1470 }
1471
1472 $sid = new_stream($sess, { path => '/' });
1473 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]);
1474
1475 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
1476 is($frame->{headers}->{':status'}, '200', 'discard body - limit req - next');
1477
1478 # ditto, but instead of receiving the rest of data frame, the connection is closed
1479 # 'http request already closed while closing request' alert can be produced
1480
1481 TODO: {
1482 todo_skip 'use-after-free', 1 unless $ENV{TEST_NGINX_UNSAFE};
1483
1484 $sess = new_session();
1485 $sid = new_stream($sess, { split => [61], abort => 1, path => '/limit_req', body => 'TEST' });
1486 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]);
1487
1488 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
1489 is($frame->{headers}->{':status'}, '200', 'discard body - limit req - eof');
1490
1491 undef $sess;
1492
1493 }
1494
1451 # malformed request body length not equal to content-length 1495 # malformed request body length not equal to content-length
1452 1496
1453 $sess = new_session(); 1497 $sess = new_session();
1454 $sid = new_stream($sess, 1498 $sid = new_stream($sess,
1455 { path => '/proxy2/t2.html', body => 'TEST', headers => [ 1499 { path => '/proxy2/t2.html', body => 'TEST', headers => [
3125 3169
3126 $split = ref $uri->{split} && $uri->{split} || []; 3170 $split = ref $uri->{split} && $uri->{split} || [];
3127 for (@$split) { 3171 for (@$split) {
3128 raw_write($ctx->{socket}, substr($buf, 0, $_, "")); 3172 raw_write($ctx->{socket}, substr($buf, 0, $_, ""));
3129 goto done if $uri->{abort}; 3173 goto done if $uri->{abort};
3130 select undef, undef, undef, 0.2; 3174 select undef, undef, undef, ($uri->{split_delay} || 0.2);
3131 } 3175 }
3132 3176
3133 raw_write($ctx->{socket}, $buf); 3177 raw_write($ctx->{socket}, $buf);
3134 done: 3178 done:
3135 return $ctx->{last_stream}; 3179 return $ctx->{last_stream};