Mercurial > hg > nginx-tests
comparison grpc.t @ 1583:8aede7babd9a
Tests: added grpc tests with wrong response size.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Sat, 11 Jul 2020 01:04:14 +0300 |
parents | fe938b5daf80 |
children | 5b3d33b5556c |
comparison
equal
deleted
inserted
replaced
1582:ab13e2744d05 | 1583:8aede7babd9a |
---|---|
22 | 22 |
23 select STDERR; $| = 1; | 23 select STDERR; $| = 1; |
24 select STDOUT; $| = 1; | 24 select STDOUT; $| = 1; |
25 | 25 |
26 my $t = Test::Nginx->new()->has(qw/http rewrite http_v2 grpc/) | 26 my $t = Test::Nginx->new()->has(qw/http rewrite http_v2 grpc/) |
27 ->has(qw/upstream_keepalive/)->plan(109); | 27 ->has(qw/upstream_keepalive/)->plan(111); |
28 | 28 |
29 $t->write_file_expand('nginx.conf', <<'EOF'); | 29 $t->write_file_expand('nginx.conf', <<'EOF'); |
30 | 30 |
31 %%TEST_GLOBALS%% | 31 %%TEST_GLOBALS%% |
32 | 32 |
274 $frames = $f->{http_err}(); | 274 $frames = $f->{http_err}(); |
275 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | 275 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
276 is($frame->{flags}, 5, 'grpc error - HEADERS flags'); | 276 is($frame->{flags}, 5, 'grpc error - HEADERS flags'); |
277 ($frame) = grep { $_->{type} eq "DATA" } @$frames; | 277 ($frame) = grep { $_->{type} eq "DATA" } @$frames; |
278 ok(!$frame, 'grpc error - no DATA frame'); | 278 ok(!$frame, 'grpc error - no DATA frame'); |
279 | |
280 # malformed response body length not equal to content-length | |
281 | |
282 TODO: { | |
283 local $TODO = 'not yet' unless $t->has_version('1.19.1'); | |
284 | |
285 $f->{http_start}('/SayHello'); | |
286 $f->{data}('Hello'); | |
287 $frames = $f->{http_err2}(cl => 42); | |
288 ($frame) = grep { $_->{type} eq "RST_STREAM" } @$frames; | |
289 ok($frame, 'response body less than content-length'); | |
290 | |
291 $f->{http_start}('/SayHello'); | |
292 $f->{data}('Hello'); | |
293 $frames = $f->{http_err2}(cl => 8); | |
294 ($frame) = grep { $_->{type} eq "RST_STREAM" } @$frames; | |
295 ok($frame, 'response body more than content-length'); | |
296 | |
297 } | |
279 | 298 |
280 # continuation from backend, expect parts assembled | 299 # continuation from backend, expect parts assembled |
281 | 300 |
282 $f->{http_start}('/SayHello'); | 301 $f->{http_start}('/SayHello'); |
283 $f->{data}('Hello'); | 302 $f->{data}('Hello'); |
639 mode => 2, huff => 1 }, | 658 mode => 2, huff => 1 }, |
640 ]}, $sid); | 659 ]}, $sid); |
641 | 660 |
642 return $s->read(all => [{ fin => 1 }]); | 661 return $s->read(all => [{ fin => 1 }]); |
643 }; | 662 }; |
663 $f->{http_err2} = sub { | |
664 my %extra = @_; | |
665 $c->new_stream({ body_more => 1, headers => [ | |
666 { name => ':status', value => '200', mode => 0 }, | |
667 { name => 'content-type', value => 'application/grpc', | |
668 mode => 1, huff => 1 }, | |
669 { name => 'content-length', value => $extra{cl}, | |
670 mode => 1, huff => 1 }, | |
671 ]}, $sid); | |
672 $c->h2_body('Hello world', | |
673 { body_more => 1, body_split => [5] }); | |
674 $c->new_stream({ headers => [ | |
675 { name => 'grpc-status', value => '0', | |
676 mode => 2, huff => 1 }, | |
677 { name => 'grpc-message', value => '', | |
678 mode => 2, huff => 1 }, | |
679 ]}, $sid); | |
680 | |
681 return $s->read(all => [{ type => 'RST_STREAM' }]); | |
682 }; | |
644 $f->{continuation} = sub { | 683 $f->{continuation} = sub { |
645 $c->new_stream({ continuation => 1, body_more => 1, headers => [ | 684 $c->new_stream({ continuation => 1, body_more => 1, headers => [ |
646 { name => ':status', value => '200', mode => 0 }, | 685 { name => ':status', value => '200', mode => 0 }, |
647 ]}, $sid); | 686 ]}, $sid); |
648 $c->h2_continue($sid, { continuation => 1, headers => [ | 687 $c->h2_continue($sid, { continuation => 1, headers => [ |