# HG changeset patch # User Sergey Kandaurov # Date 1443710634 -10800 # Node ID 61800918f6470c69811b5a058b4f3f670d15dec2 # Parent 3e034902ebe71107854a2baf0294ba28a0fea985 Tests: added HTTP/2 tests with invalid connection preface. diff --git a/h2.t b/h2.t --- a/h2.t +++ b/h2.t @@ -32,7 +32,7 @@ plan(skip_all => 'IO::Socket::SSL too ol my $t = Test::Nginx->new()->has(qw/http http_ssl http_v2 proxy cache/) ->has(qw/limit_conn rewrite realip shmem/) - ->has_daemon('openssl')->plan(212); + ->has_daemon('openssl')->plan(216); # FreeBSD has a bug in not treating zero iovcnt as EINVAL @@ -1907,6 +1907,24 @@ is($frame->{headers}->{':status'}, 200, # some invalid cases below +# invalid connection preface + +$sess = new_session(8080, preface => 'bogus preface'); +$sid = new_stream($sess, { path => '/pp' }); +$frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); + +($frame) = grep { $_->{type} eq "GOAWAY" } @$frames; +ok($frame, 'invalid preface - GOAWAY frame'); +is($frame->{code}, 1, 'invalid preface - error code'); + +$sess = new_session(8080, preface => 'PRI * HTTP/2.0' . CRLF . CRLF . 'bogus'); +$sid = new_stream($sess, { path => '/pp' }); +$frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); + +($frame) = grep { $_->{type} eq "GOAWAY" } @$frames; +ok($frame, 'invalid preface 2 - GOAWAY frame'); +is($frame->{code}, 1, 'invalid preface 2 - error code'); + # invalid PROXY protocol string $sess = new_session(8082, proxy => 'bogus'); @@ -2358,9 +2376,10 @@ sub raw_write { sub new_session { my ($port, %extra) = @_; - my ($s); - - $s = new_socket($port, %extra); + + my $s = new_socket($port, %extra); + my $preface = $extra{preface} + || 'PRI * HTTP/2.0' . CRLF . CRLF . 'SM' . CRLF . CRLF; if ($extra{proxy}) { raw_write($s, $extra{proxy}); @@ -2368,7 +2387,7 @@ sub new_session { # preface - raw_write($s, 'PRI * HTTP/2.0' . CRLF . CRLF . 'SM' . CRLF . CRLF); + raw_write($s, $preface); return { socket => $s, last_stream => -1, dynamic_encode => [ static_table() ],