Mercurial > hg > nginx-tests
comparison h2.t @ 762:f28debc81182
Tests: added HTTP/2 client_max_body_size tests.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Wed, 28 Oct 2015 00:11:45 +0300 |
parents | 01feb5d4d7a4 |
children | 2ba4058848d6 |
comparison
equal
deleted
inserted
replaced
761:01feb5d4d7a4 | 762:f28debc81182 |
---|---|
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(251); | 35 ->has_daemon('openssl')->plan(275); |
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 |
150 proxy_pass http://127.0.0.1:8081/; | 150 proxy_pass http://127.0.0.1:8081/; |
151 proxy_cache NAME; | 151 proxy_cache NAME; |
152 proxy_cache_valid 1m; | 152 proxy_cache_valid 1m; |
153 proxy_buffering off; | 153 proxy_buffering off; |
154 } | 154 } |
155 location /client_max_body_size { | |
156 add_header X-Body $request_body; | |
157 add_header X-Body-File $request_body_file; | |
158 client_body_in_single_buffer on; | |
159 client_body_in_file_only on; | |
160 proxy_pass http://127.0.0.1:8081/; | |
161 client_max_body_size 10; | |
162 } | |
155 location /set-cookie { | 163 location /set-cookie { |
156 add_header Set-Cookie a=b; | 164 add_header Set-Cookie a=b; |
157 add_header Set-Cookie c=d; | 165 add_header Set-Cookie c=d; |
158 return 200; | 166 return 200; |
159 } | 167 } |
1360 { path => '/proxy2/t2.html', body => 'TEST', body_split => [2] }); | 1368 { path => '/proxy2/t2.html', body => 'TEST', body_split => [2] }); |
1361 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | 1369 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); |
1362 | 1370 |
1363 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | 1371 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
1364 is($frame->{headers}->{'x-body'}, 'TEST', 'request body in multiple frames'); | 1372 is($frame->{headers}->{'x-body'}, 'TEST', 'request body in multiple frames'); |
1373 | |
1374 # client_max_body_size | |
1375 | |
1376 $sess = new_session(); | |
1377 $sid = new_stream($sess, { path => '/client_max_body_size/t2.html', | |
1378 body => 'TESTTEST12' }); | |
1379 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
1380 | |
1381 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
1382 is($frame->{headers}->{':status'}, 200, 'client_max_body_size - status'); | |
1383 is(read_body_file($frame->{headers}->{'x-body-file'}), 'TESTTEST12', | |
1384 'client_max_body_size - body'); | |
1385 | |
1386 # client_max_body_size - limited | |
1387 | |
1388 $sess = new_session(); | |
1389 $sid = new_stream($sess, { path => '/client_max_body_size/t2.html', | |
1390 body => 'TESTTEST123' }); | |
1391 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
1392 | |
1393 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
1394 is($frame->{headers}->{':status'}, 413, 'client_max_body_size - limited'); | |
1395 | |
1396 # client_max_body_size - many DATA frames | |
1397 | |
1398 $sess = new_session(); | |
1399 $sid = new_stream($sess, { path => '/client_max_body_size/t2.html', | |
1400 body => 'TESTTEST12', body_split => [2] }); | |
1401 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
1402 | |
1403 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
1404 is($frame->{headers}->{':status'}, 200, 'client_max_body_size many - status'); | |
1405 is(read_body_file($frame->{headers}->{'x-body-file'}), 'TESTTEST12', | |
1406 'client_max_body_size many - body'); | |
1407 | |
1408 # client_max_body_size - many DATA frames - limited | |
1409 | |
1410 $sess = new_session(); | |
1411 $sid = new_stream($sess, { path => '/client_max_body_size/t2.html', | |
1412 body => 'TESTTEST123', body_split => [2] }); | |
1413 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
1414 | |
1415 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
1416 is($frame->{headers}->{':status'}, 413, 'client_max_body_size many - limited'); | |
1417 | |
1418 # client_max_body_size - padded DATA | |
1419 | |
1420 $sess = new_session(); | |
1421 $sid = new_stream($sess, { path => '/client_max_body_size/t2.html', | |
1422 body => 'TESTTEST12', body_padding => 42 }); | |
1423 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
1424 | |
1425 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
1426 is($frame->{headers}->{':status'}, 200, 'client_max_body_size pad - status'); | |
1427 is(read_body_file($frame->{headers}->{'x-body-file'}), 'TESTTEST12', | |
1428 'client_max_body_size pad - body'); | |
1429 | |
1430 # client_max_body_size - padded DATA - limited | |
1431 | |
1432 $sess = new_session(); | |
1433 $sid = new_stream($sess, { path => '/client_max_body_size/t2.html', | |
1434 body => 'TESTTEST123', body_padding => 42 }); | |
1435 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
1436 | |
1437 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
1438 is($frame->{headers}->{':status'}, 413, 'client_max_body_size pad - limited'); | |
1439 | |
1440 # client_max_body_size - many padded DATA frames | |
1441 | |
1442 $sess = new_session(); | |
1443 $sid = new_stream($sess, { path => '/client_max_body_size/t2.html', | |
1444 body => 'TESTTEST12', body_padding => 42, body_split => [2] }); | |
1445 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
1446 | |
1447 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
1448 is($frame->{headers}->{':status'}, 200, | |
1449 'client_max_body_size many pad - status'); | |
1450 is(read_body_file($frame->{headers}->{'x-body-file'}), 'TESTTEST12', | |
1451 'client_max_body_size many pad - body'); | |
1452 | |
1453 # client_max_body_size - many padded DATA frames - limited | |
1454 | |
1455 $sess = new_session(); | |
1456 $sid = new_stream($sess, { path => '/client_max_body_size/t2.html', | |
1457 body => 'TESTTEST123', body_padding => 42, body_split => [2] }); | |
1458 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
1459 | |
1460 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
1461 is($frame->{headers}->{':status'}, 413, | |
1462 'client_max_body_size many pad - limited'); | |
1463 | |
1464 # request body without content-length | |
1465 | |
1466 $sess = new_session(); | |
1467 $sid = new_stream($sess, { body => 'TESTTEST12', headers => [ | |
1468 { name => ':method', value => 'GET', mode => 2 }, | |
1469 { name => ':scheme', value => 'http', mode => 2 }, | |
1470 { name => ':path', value => '/client_max_body_size', mode => 2 }, | |
1471 { name => ':authority', value => 'localhost', mode => 2 }]}); | |
1472 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
1473 | |
1474 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
1475 is($frame->{headers}->{':status'}, 200, | |
1476 'request body without content-length - status'); | |
1477 is(read_body_file($frame->{headers}->{'x-body-file'}), 'TESTTEST12', | |
1478 'request body without content-length - body'); | |
1479 | |
1480 # request body without content-length - limited | |
1481 | |
1482 $sess = new_session(); | |
1483 $sid = new_stream($sess, { body => 'TESTTEST123', headers => [ | |
1484 { name => ':method', value => 'GET', mode => 2 }, | |
1485 { name => ':scheme', value => 'http', mode => 2 }, | |
1486 { name => ':path', value => '/client_max_body_size', mode => 2 }, | |
1487 { name => ':authority', value => 'localhost', mode => 2 }]}); | |
1488 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
1489 | |
1490 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
1491 is($frame->{headers}->{':status'}, 413, | |
1492 'request body without content-length - limited'); | |
1493 | |
1494 # request body without content-length - many DATA frames | |
1495 | |
1496 $sess = new_session(); | |
1497 $sid = new_stream($sess, { body => 'TESTTEST12', body_split => [2], | |
1498 headers => [ | |
1499 { name => ':method', value => 'GET', mode => 2 }, | |
1500 { name => ':scheme', value => 'http', mode => 2 }, | |
1501 { name => ':path', value => '/client_max_body_size', mode => 2 }, | |
1502 { name => ':authority', value => 'localhost', mode => 2 }]}); | |
1503 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
1504 | |
1505 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
1506 is($frame->{headers}->{':status'}, 200, | |
1507 'request body without content-length many - status'); | |
1508 is(read_body_file($frame->{headers}->{'x-body-file'}), 'TESTTEST12', | |
1509 'request body without content-length many - body'); | |
1510 | |
1511 # request body without content-length - many DATA frames - limited | |
1512 | |
1513 $sess = new_session(); | |
1514 $sid = new_stream($sess, { body => 'TESTTEST123', body_split => [2], | |
1515 headers => [ | |
1516 { name => ':method', value => 'GET', mode => 2 }, | |
1517 { name => ':scheme', value => 'http', mode => 2 }, | |
1518 { name => ':path', value => '/client_max_body_size', mode => 2 }, | |
1519 { name => ':authority', value => 'localhost', mode => 2 }]}); | |
1520 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
1521 | |
1522 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
1523 is($frame->{headers}->{':status'}, 413, | |
1524 'request body without content-length many - limited'); | |
1525 | |
1526 # request body without content-length - padding | |
1527 | |
1528 $sess = new_session(); | |
1529 $sid = new_stream($sess, { body => 'TESTTEST12', body_padding => 42, | |
1530 headers => [ | |
1531 { name => ':method', value => 'GET', mode => 2 }, | |
1532 { name => ':scheme', value => 'http', mode => 2 }, | |
1533 { name => ':path', value => '/client_max_body_size', mode => 2 }, | |
1534 { name => ':authority', value => 'localhost', mode => 2 }]}); | |
1535 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
1536 | |
1537 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
1538 is($frame->{headers}->{':status'}, 200, | |
1539 'request body without content-length pad - status'); | |
1540 is(read_body_file($frame->{headers}->{'x-body-file'}), 'TESTTEST12', | |
1541 'request body without content-length pad - body'); | |
1542 | |
1543 # request body without content-length - padding - limited | |
1544 | |
1545 $sess = new_session(); | |
1546 $sid = new_stream($sess, { body => 'TESTTEST123', body_padding => 42, | |
1547 headers => [ | |
1548 { name => ':method', value => 'GET', mode => 2 }, | |
1549 { name => ':scheme', value => 'http', mode => 2 }, | |
1550 { name => ':path', value => '/client_max_body_size', mode => 2 }, | |
1551 { name => ':authority', value => 'localhost', mode => 2 }]}); | |
1552 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
1553 | |
1554 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
1555 is($frame->{headers}->{':status'}, 413, | |
1556 'request body without content-length pad - limited'); | |
1557 | |
1558 # request body without content-length - padding with many DATA frames | |
1559 | |
1560 $sess = new_session(); | |
1561 $sid = new_stream($sess, { body => 'TESTTEST', body_padding => 42, | |
1562 body_split => [2], headers => [ | |
1563 { name => ':method', value => 'GET', mode => 2 }, | |
1564 { name => ':scheme', value => 'http', mode => 2 }, | |
1565 { name => ':path', value => '/client_max_body_size', mode => 2 }, | |
1566 { name => ':authority', value => 'localhost', mode => 2 }]}); | |
1567 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
1568 | |
1569 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
1570 is($frame->{headers}->{':status'}, 200, | |
1571 'request body without content-length many pad - status'); | |
1572 is(read_body_file($frame->{headers}->{'x-body-file'}), 'TESTTEST', | |
1573 'request body without content-length many pad - body'); | |
1574 | |
1575 # request body without content-length - padding with many DATA frames - limited | |
1576 | |
1577 $sess = new_session(); | |
1578 $sid = new_stream($sess, { body => 'TESTTEST123', body_padding => 42, | |
1579 body_split => [2], headers => [ | |
1580 { name => ':method', value => 'GET', mode => 2 }, | |
1581 { name => ':scheme', value => 'http', mode => 2 }, | |
1582 { name => ':path', value => '/client_max_body_size', mode => 2 }, | |
1583 { name => ':authority', value => 'localhost', mode => 2 }]}); | |
1584 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
1585 | |
1586 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
1587 is($frame->{headers}->{':status'}, 413, | |
1588 'request body without content-length many pad - limited'); | |
1365 | 1589 |
1366 # initial window size, client side | 1590 # initial window size, client side |
1367 | 1591 |
1368 # 6.9.2. Initial Flow-Control Window Size | 1592 # 6.9.2. Initial Flow-Control Window Size |
1369 # When an HTTP/2 connection is first established, new streams are | 1593 # When an HTTP/2 connection is first established, new streams are |
3457 return $ret; | 3681 return $ret; |
3458 } | 3682 } |
3459 | 3683 |
3460 ############################################################################### | 3684 ############################################################################### |
3461 | 3685 |
3686 sub read_body_file { | |
3687 my ($path) = @_; | |
3688 open FILE, $path or return "$!"; | |
3689 local $/; | |
3690 my $content = <FILE>; | |
3691 close FILE; | |
3692 return $content; | |
3693 } | |
3694 | |
3462 sub gunzip_like { | 3695 sub gunzip_like { |
3463 my ($in, $re, $name) = @_; | 3696 my ($in, $re, $name) = @_; |
3464 | 3697 |
3465 SKIP: { | 3698 SKIP: { |
3466 eval { require IO::Uncompress::Gunzip; }; | 3699 eval { require IO::Uncompress::Gunzip; }; |