changeset 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 ab13e2744d05
children b4014b3e8495
files grpc.t
diffstat 1 files changed, 40 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/grpc.t
+++ b/grpc.t
@@ -24,7 +24,7 @@ select STDERR; $| = 1;
 select STDOUT; $| = 1;
 
 my $t = Test::Nginx->new()->has(qw/http rewrite http_v2 grpc/)
-	->has(qw/upstream_keepalive/)->plan(109);
+	->has(qw/upstream_keepalive/)->plan(111);
 
 $t->write_file_expand('nginx.conf', <<'EOF');
 
@@ -277,6 +277,25 @@ is($frame->{flags}, 5, 'grpc error - HEA
 ($frame) = grep { $_->{type} eq "DATA" } @$frames;
 ok(!$frame, 'grpc error - no DATA frame');
 
+# malformed response body length not equal to content-length
+
+TODO: {
+local $TODO = 'not yet' unless $t->has_version('1.19.1');
+
+$f->{http_start}('/SayHello');
+$f->{data}('Hello');
+$frames = $f->{http_err2}(cl => 42);
+($frame) = grep { $_->{type} eq "RST_STREAM" } @$frames;
+ok($frame, 'response body less than content-length');
+
+$f->{http_start}('/SayHello');
+$f->{data}('Hello');
+$frames = $f->{http_err2}(cl => 8);
+($frame) = grep { $_->{type} eq "RST_STREAM" } @$frames;
+ok($frame, 'response body more than content-length');
+
+}
+
 # continuation from backend, expect parts assembled
 
 $f->{http_start}('/SayHello');
@@ -641,6 +660,26 @@ sub grpc {
 
 		return $s->read(all => [{ fin => 1 }]);
 	};
+	$f->{http_err2} = sub {
+		my %extra = @_;
+		$c->new_stream({ body_more => 1, headers => [
+			{ name => ':status', value => '200', mode => 0 },
+			{ name => 'content-type', value => 'application/grpc',
+				mode => 1, huff => 1 },
+			{ name => 'content-length', value => $extra{cl},
+				mode => 1, huff => 1 },
+		]}, $sid);
+		$c->h2_body('Hello world',
+			{ body_more => 1, body_split => [5] });
+		$c->new_stream({ headers => [
+			{ name => 'grpc-status', value => '0',
+				mode => 2, huff => 1 },
+			{ name => 'grpc-message', value => '',
+				mode => 2, huff => 1 },
+		]}, $sid);
+
+		return $s->read(all => [{ type => 'RST_STREAM' }]);
+	};
 	$f->{continuation} = sub {
 		$c->new_stream({ continuation => 1, body_more => 1, headers => [
 			{ name => ':status', value => '200', mode => 0 },