changeset 1169:518d1c865812

Tests: avoid illegal dereference on errors in h2_headers.t.
author Sergey Kandaurov <pluknet@nginx.com>
date Wed, 03 May 2017 13:36:40 +0300
parents 8821e405b91e
children cf14cfe9ec8c
files h2_headers.t
diffstat 1 files changed, 19 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/h2_headers.t
+++ b/h2_headers.t
@@ -26,7 +26,7 @@ use Test::Nginx::HTTP2;
 select STDERR; $| = 1;
 select STDOUT; $| = 1;
 
-my $t = Test::Nginx->new()->has(qw/http http_v2 proxy rewrite/)->plan(92)
+my $t = Test::Nginx->new()->has(qw/http http_v2 proxy rewrite/)->plan(93)
 	->write_file_expand('nginx.conf', <<'EOF');
 
 %%TEST_GLOBALS%%
@@ -606,13 +606,14 @@ is($frame->{headers}->{'x-uc-c'}, 'd',
 
 $frames = $s->read(all => [{ sid => $sid, fin => 0x4 }]);
 my @data = grep { $_->{type} =~ "HEADERS|CONTINUATION" } @$frames;
-is(@{$data[-1]->{headers}{'x-longheader'}}, 3,
+my $data = $data[-1];
+is(@{$data->{headers}{'x-longheader'}}, 3,
 	'response CONTINUATION - headers');
-is($data[-1]->{headers}{'x-longheader'}[0], 'x' x 2**13,
+is($data->{headers}{'x-longheader'}[0], 'x' x 2**13,
 	'response CONTINUATION - header 1');
-is($data[-1]->{headers}{'x-longheader'}[1], 'x' x 2**13,
+is($data->{headers}{'x-longheader'}[1], 'x' x 2**13,
 	'response CONTINUATION - header 2');
-is($data[-1]->{headers}{'x-longheader'}[2], 'x' x 2**13,
+is($data->{headers}{'x-longheader'}[2], 'x' x 2**13,
 	'response CONTINUATION - header 3');
 @data = sort { $a <=> $b } map { $_->{length} } @data;
 cmp_ok($data[-1], '<=', 2**14, 'response CONTINUATION - max frame size');
@@ -624,13 +625,14 @@ cmp_ok($data[-1], '<=', 2**14, 'response
 
 $frames = $s->read(all => [{ sid => $sid, fin => 0x4 }]);
 @data = grep { $_->{type} =~ "HEADERS|CONTINUATION" } @$frames;
-is(@{$data[-1]->{headers}{'x-longheader'}}, 3,
+$data = $data[-1];
+is(@{$data->{headers}{'x-longheader'}}, 3,
 	'no body CONTINUATION - headers');
-is($data[-1]->{headers}{'x-longheader'}[0], 'x' x 2**13,
+is($data->{headers}{'x-longheader'}[0], 'x' x 2**13,
 	'no body CONTINUATION - header 1');
-is($data[-1]->{headers}{'x-longheader'}[1], 'x' x 2**13,
+is($data->{headers}{'x-longheader'}[1], 'x' x 2**13,
 	'no body CONTINUATION - header 2');
-is($data[-1]->{headers}{'x-longheader'}[2], 'x' x 2**13,
+is($data->{headers}{'x-longheader'}[2], 'x' x 2**13,
 	'no body CONTINUATION - header 3');
 @data = sort { $a <=> $b } map { $_->{length} } @data;
 cmp_ok($data[-1], '<=', 2**14, 'no body CONTINUATION - max frame size');
@@ -674,12 +676,19 @@ is(length join('', @{$frame->{headers}->
 $frames = $s->read(all => [{ sid => $sid, fin => 0x4 }]);
 
 @data = grep { $_->{type} =~ "HEADERS|CONTINUATION" } @$frames;
+ok(@data, 'response header split');
+
+SKIP: {
+skip 'response header split failed', 2 unless @data;
+
 my ($lengths) = sort { $b <=> $a } map { $_->{length} } @data;
 cmp_ok($lengths, '<=', 16384, 'response header split - max size');
 
-is(length join('', @{@$frames[-1]->{headers}->{'x-longheader'}}), 98304,
+is(length join('', @{$data[-1]->{headers}->{'x-longheader'}}), 98304,
 	'response header split - headers');
 
+}
+
 # max_field_size - header field name
 
 $s = Test::Nginx::HTTP2->new(port(8084));