Mercurial > hg > nginx-tests
comparison h2_headers.t @ 1549:6c9e3e20af97
Tests: HTTP/2 tests for error handling in parsing HPACK integers.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Wed, 05 Feb 2020 18:04:55 +0300 |
parents | d8684b300d22 |
children | 5c96745988c4 |
comparison
equal
deleted
inserted
replaced
1548:b02d0fd71638 | 1549:6c9e3e20af97 |
---|---|
21 ############################################################################### | 21 ############################################################################### |
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 http_v2 proxy rewrite/)->plan(97) | 26 my $t = Test::Nginx->new()->has(qw/http http_v2 proxy rewrite/)->plan(103) |
27 ->write_file_expand('nginx.conf', <<'EOF'); | 27 ->write_file_expand('nginx.conf', <<'EOF'); |
28 | 28 |
29 %%TEST_GLOBALS%% | 29 %%TEST_GLOBALS%% |
30 | 30 |
31 daemon off; | 31 daemon off; |
1045 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); | 1045 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); |
1046 | 1046 |
1047 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | 1047 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
1048 is($frame->{headers}->{':status'}, 400, 'invalid path'); | 1048 is($frame->{headers}->{':status'}, 400, 'invalid path'); |
1049 | 1049 |
1050 | |
1051 # ngx_http_v2_parse_int() error handling | |
1052 | |
1053 # NGX_ERROR | |
1054 | |
1055 $s = Test::Nginx::HTTP2->new(); | |
1056 { | |
1057 local $SIG{PIPE} = 'IGNORE'; | |
1058 syswrite($s->{socket}, pack("x2C3NC", 1, 0x1, 5, 1, 0xff)); | |
1059 } | |
1060 $frames = $s->read(all => [{ type => "GOAWAY" }]); | |
1061 | |
1062 ($frame) = grep { $_->{type} eq 'GOAWAY' } @$frames; | |
1063 is($frame->{code}, 0x6, 'invalid index length'); | |
1064 | |
1065 $s = Test::Nginx::HTTP2->new(); | |
1066 { | |
1067 local $SIG{PIPE} = 'IGNORE'; | |
1068 syswrite($s->{socket}, pack("x2C3NC2", 2, 0x1, 5, 1, 0x42, 0xff)); | |
1069 } | |
1070 $frames = $s->read(all => [{ type => "GOAWAY" }]); | |
1071 | |
1072 ($frame) = grep { $_->{type} eq 'GOAWAY' } @$frames; | |
1073 is($frame->{code}, 0x6, 'invalid literal length'); | |
1074 | |
1075 # NGX_DECLINED | |
1076 | |
1077 $s = Test::Nginx::HTTP2->new(); | |
1078 { | |
1079 local $SIG{PIPE} = 'IGNORE'; | |
1080 syswrite($s->{socket}, pack("x2C3NN", 5, 0x1, 5, 1, 0xffffffff)); | |
1081 } | |
1082 $frames = $s->read(all => [{ type => "GOAWAY" }]); | |
1083 | |
1084 ($frame) = grep { $_->{type} eq 'GOAWAY' } @$frames; | |
1085 is($frame->{code}, 0x9, 'too long index'); | |
1086 | |
1087 $s = Test::Nginx::HTTP2->new(); | |
1088 { | |
1089 local $SIG{PIPE} = 'IGNORE'; | |
1090 syswrite($s->{socket}, pack("x2C3NCN", 6, 0x1, 5, 1, 0x42, 0xffffffff)); | |
1091 } | |
1092 $frames = $s->read(all => [{ type => "GOAWAY" }]); | |
1093 | |
1094 ($frame) = grep { $_->{type} eq 'GOAWAY' } @$frames; | |
1095 is($frame->{code}, 0x9, 'too long literal'); | |
1096 | |
1097 # NGX_AGAIN | |
1098 | |
1099 $s = Test::Nginx::HTTP2->new(); | |
1100 $sid = $s->new_stream({ split => [35], split_delay => 1.1, headers => [ | |
1101 { name => ':method', value => 'GET', mode => 3, huff => 0 }, | |
1102 { name => ':scheme', value => 'http', mode => 3, huff => 0 }, | |
1103 { name => ':path', value => '/', mode => 3, huff => 0 }, | |
1104 { name => ':authority', value => 'localhost', mode => 3, huff => 0 }, | |
1105 { name => 'referer', value => 'foo', mode => 3, huff => 0 }]}); | |
1106 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); | |
1107 | |
1108 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
1109 is($frame->{headers}->{'x-referer'}, 'foo', 'header split index'); | |
1110 | |
1111 $s = Test::Nginx::HTTP2->new(); | |
1112 $sid = $s->new_stream({ split => [37], split_delay => 1.1, headers => [ | |
1113 { name => ':method', value => 'GET', mode => 3, huff => 0 }, | |
1114 { name => ':scheme', value => 'http', mode => 3, huff => 0 }, | |
1115 { name => ':path', value => '/', mode => 3, huff => 0 }, | |
1116 { name => ':authority', value => 'localhost', mode => 3, huff => 0 }, | |
1117 { name => 'referer', value => '1234' x 32, mode => 3, huff => 0 }]}); | |
1118 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); | |
1119 | |
1120 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
1121 is($frame->{headers}->{'x-referer'}, '1234' x 32, 'header split field length'); | |
1122 | |
1050 ############################################################################### | 1123 ############################################################################### |
1051 | 1124 |
1052 sub http_daemon { | 1125 sub http_daemon { |
1053 my $server = IO::Socket::INET->new( | 1126 my $server = IO::Socket::INET->new( |
1054 Proto => 'tcp', | 1127 Proto => 'tcp', |