Skip to content

Commit 5f0af3c

Browse files
committed
Tests: expect HTTP 400 on HTTP/2 header validation errors.
1 parent 64a9195 commit 5f0af3c

File tree

1 file changed

+20
-24
lines changed

1 file changed

+20
-24
lines changed

h2_headers.t

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use Test::Nginx::HTTP2;
2323
select STDERR; $| = 1;
2424
select STDOUT; $| = 1;
2525

26-
my $t = Test::Nginx->new()->has(qw/http http_v2 proxy rewrite/)->plan(107)
26+
my $t = Test::Nginx->new()->has(qw/http http_v2 proxy rewrite/)->plan(103)
2727
->write_file_expand('nginx.conf', <<'EOF');
2828
2929
%%TEST_GLOBALS%%
@@ -943,7 +943,7 @@ $sid = $s->new_stream({ headers => [
943943
{ name => ':path', value => '/proxy2/', mode => 1 },
944944
{ name => ':authority', value => 'localhost', mode => 1 },
945945
{ name => 'x-foo', value => "x-bar\r\nreferer:see-this", mode => 2 }]});
946-
$frames = $s->read(all => [{ type => 'RST_STREAM' }]);
946+
$frames = $s->read(all => [{ sid => $sid, fin => 1 }]);
947947

948948
# 10.3. Intermediary Encapsulation Attacks
949949
# An intermediary therefore cannot translate an HTTP/2 request or response
@@ -952,15 +952,12 @@ $frames = $s->read(all => [{ type => 'RST_STREAM' }]);
952952
($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
953953
isnt($frame->{headers}->{'x-referer'}, 'see-this', 'newline in request header');
954954

955-
# 8.1.2.6. Malformed Requests and Responses
956-
# Malformed requests or responses that are detected MUST be treated
957-
# as a stream error (Section 5.4.2) of type PROTOCOL_ERROR.
955+
TODO: {
956+
local $TODO = 'not yet' unless $t->has_version('1.23.4');
957+
958+
is($frame->{headers}->{':status'}, 400, 'newline in request header - bad request');
958959

959-
($frame) = grep { $_->{type} eq "RST_STREAM" } @$frames;
960-
is($frame->{sid}, $sid, 'newline in request header - RST_STREAM sid');
961-
is($frame->{length}, 4, 'newline in request header - RST_STREAM length');
962-
is($frame->{flags}, 0, 'newline in request header - RST_STREAM flags');
963-
is($frame->{code}, 1, 'newline in request header - RST_STREAM code');
960+
}
964961

965962
# invalid header name as seen with underscore should not lead to ignoring rest
966963

@@ -977,7 +974,10 @@ $frames = $s->read(all => [{ type => 'HEADERS' }]);
977974
($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
978975
is($frame->{headers}->{'x-referer'}, 'see-this', 'after invalid header name');
979976

980-
# other invalid header name characters as seen with ':' result in RST_STREAM
977+
# other invalid header name characters as seen with ':'
978+
979+
TODO: {
980+
local $TODO = 'not yet' unless $t->has_version('1.23.4');
981981

982982
$s = Test::Nginx::HTTP2->new();
983983
$sid = $s->new_stream({ headers => [
@@ -987,14 +987,10 @@ $sid = $s->new_stream({ headers => [
987987
{ name => ':authority', value => 'localhost', mode => 1 },
988988
{ name => 'x:foo', value => "x-bar", mode => 2 },
989989
{ name => 'referer', value => "see-this", mode => 1 }]});
990-
$frames = $s->read(all => [{ type => 'RST_STREAM' }]);
991-
992-
($frame) = grep { $_->{type} eq "RST_STREAM" } @$frames;
993-
is($frame->{sid}, $sid, 'colon in header name - RST_STREAM sid');
994-
is($frame->{code}, 1, 'colon in header name - RST_STREAM code');
990+
$frames = $s->read(all => [{ sid => $sid, fin => 1 }]);
995991

996-
TODO: {
997-
local $TODO = 'not yet' unless $t->has_version('1.21.1');
992+
($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
993+
is($frame->{headers}->{':status'}, 400, 'colon in header name');
998994

999995
$s = Test::Nginx::HTTP2->new();
1000996
$sid = $s->new_stream({ headers => [
@@ -1003,10 +999,10 @@ $sid = $s->new_stream({ headers => [
1003999
{ name => ':path', value => '/', mode => 0 },
10041000
{ name => ':authority', value => 'localhost', mode => 1 },
10051001
{ name => 'x foo', value => "bar", mode => 2 }]});
1006-
$frames = $s->read(all => [{ type => 'RST_STREAM' }]);
1002+
$frames = $s->read(all => [{ sid => $sid, fin => 1 }]);
10071003

1008-
($frame) = grep { $_->{type} eq "RST_STREAM" } @$frames;
1009-
ok($frame, 'space in header name - RST_STREAM sid');
1004+
($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
1005+
is($frame->{headers}->{':status'}, 400, 'space in header name');
10101006

10111007
$s = Test::Nginx::HTTP2->new();
10121008
$sid = $s->new_stream({ headers => [
@@ -1015,10 +1011,10 @@ $sid = $s->new_stream({ headers => [
10151011
{ name => ':path', value => '/', mode => 0 },
10161012
{ name => ':authority', value => 'localhost', mode => 1 },
10171013
{ name => "foo\x02", value => "bar", mode => 2 }]});
1018-
$frames = $s->read(all => [{ type => 'RST_STREAM' }]);
1014+
$frames = $s->read(all => [{ sid => $sid, fin => 1 }]);
10191015

1020-
($frame) = grep { $_->{type} eq "RST_STREAM" } @$frames;
1021-
ok($frame, 'control in header name - RST_STREAM sid');
1016+
($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
1017+
is($frame->{headers}->{':status'}, 400, 'control in header name');
10221018

10231019
}
10241020

0 commit comments

Comments
 (0)