| 1 |
use strict; |
| 2 |
use warnings; |
| 3 |
use Test::More; |
| 4 |
use Protocol::HTTP2::Client; |
| 5 |
use Protocol::HTTP2::Server; |
| 6 |
use Protocol::HTTP2::Constants qw(:errors :settings :limits); |
| 7 |
use lib 't/lib'; |
| 8 |
use PH2Test qw(fake_connect random_string); |
| 9 |
|
| 10 |
subtest 'hpack bomb' => sub { |
| 11 |
|
| 12 |
plan tests => 1; |
| 13 |
my $hc = 2000; |
| 14 |
|
| 15 |
my $server; |
| 16 |
$server = Protocol::HTTP2::Server->new( |
| 17 |
on_error => sub { |
| 18 |
my $error = shift; |
| 19 |
is $error, &ENHANCE_YOUR_CALM, "ENHANCE_YOUR_CALM error"; |
| 20 |
}, |
| 21 |
on_request => sub { |
| 22 |
ok 0, "request should not have been received" |
| 23 |
} |
| 24 |
); |
| 25 |
|
| 26 |
my $client = Protocol::HTTP2::Client->new; |
| 27 |
$client->request( |
| 28 |
':scheme' => 'http', |
| 29 |
':authority' => 'localhost:8000', |
| 30 |
':path' => '/', |
| 31 |
':method' => 'GET', |
| 32 |
headers => [ ('a' => '')x$hc ], |
| 33 |
); |
| 34 |
|
| 35 |
fake_connect( $server, $client ); |
| 36 |
}; |
| 37 |
|
| 38 |
subtest 'change settings' => sub { |
| 39 |
|
| 40 |
plan tests => 3; |
| 41 |
my $hc = 2000; |
| 42 |
|
| 43 |
my $server; |
| 44 |
$server = Protocol::HTTP2::Server->new( |
| 45 |
settings => { |
| 46 |
&SETTINGS_MAX_HEADER_LIST_SIZE => $hc*33 + 200 |
| 47 |
}, |
| 48 |
on_error => sub { |
| 49 |
my $error = shift; |
| 50 |
ok 0, "should be no error"; |
| 51 |
}, |
| 52 |
on_request => sub { |
| 53 |
my ( $stream_id, $headers, $data ) = @_; |
| 54 |
my %h = (@$headers); |
| 55 |
is $#$headers, 2*($hc+4)-1, "2*($hc + 4) headers"; |
| 56 |
is keys %h, 5, "merged in 1 + 4 headers"; |
| 57 |
ok exists $h{b}, "b header"; |
| 58 |
} |
| 59 |
); |
| 60 |
|
| 61 |
my $client = Protocol::HTTP2::Client->new; |
| 62 |
$client->request( |
| 63 |
':scheme' => 'http', |
| 64 |
':authority' => 'localhost:8000', |
| 65 |
':path' => '/', |
| 66 |
':method' => 'GET', |
| 67 |
headers => [ ('b' => '')x$hc ], |
| 68 |
); |
| 69 |
|
| 70 |
fake_connect( $server, $client ); |
| 71 |
}; |
| 72 |
|
| 73 |
|
| 74 |
done_testing; |