comparison h2.t @ 728:61800918f647

Tests: added HTTP/2 tests with invalid connection preface.
author Sergey Kandaurov <pluknet@nginx.com>
date Thu, 01 Oct 2015 17:43:54 +0300
parents 3e034902ebe7
children 41caaaff9b95
comparison
equal deleted inserted replaced
727:3e034902ebe7 728:61800918f647
30 eval { IO::Socket::SSL::SSL_VERIFY_NONE(); }; 30 eval { IO::Socket::SSL::SSL_VERIFY_NONE(); };
31 plan(skip_all => 'IO::Socket::SSL too old') if $@; 31 plan(skip_all => 'IO::Socket::SSL too old') if $@;
32 32
33 my $t = Test::Nginx->new()->has(qw/http http_ssl http_v2 proxy cache/) 33 my $t = Test::Nginx->new()->has(qw/http http_ssl http_v2 proxy cache/)
34 ->has(qw/limit_conn rewrite realip shmem/) 34 ->has(qw/limit_conn rewrite realip shmem/)
35 ->has_daemon('openssl')->plan(212); 35 ->has_daemon('openssl')->plan(216);
36 36
37 # FreeBSD has a bug in not treating zero iovcnt as EINVAL 37 # FreeBSD has a bug in not treating zero iovcnt as EINVAL
38 38
39 $t->todo_alerts() unless $^O eq 'freebsd'; 39 $t->todo_alerts() unless $^O eq 'freebsd';
40 40
1905 is($frame->{headers}->{':status'}, 200, 'http2_max_concurrent_streams 3'); 1905 is($frame->{headers}->{':status'}, 200, 'http2_max_concurrent_streams 3');
1906 1906
1907 1907
1908 # some invalid cases below 1908 # some invalid cases below
1909 1909
1910 # invalid connection preface
1911
1912 $sess = new_session(8080, preface => 'bogus preface');
1913 $sid = new_stream($sess, { path => '/pp' });
1914 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]);
1915
1916 ($frame) = grep { $_->{type} eq "GOAWAY" } @$frames;
1917 ok($frame, 'invalid preface - GOAWAY frame');
1918 is($frame->{code}, 1, 'invalid preface - error code');
1919
1920 $sess = new_session(8080, preface => 'PRI * HTTP/2.0' . CRLF . CRLF . 'bogus');
1921 $sid = new_stream($sess, { path => '/pp' });
1922 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]);
1923
1924 ($frame) = grep { $_->{type} eq "GOAWAY" } @$frames;
1925 ok($frame, 'invalid preface 2 - GOAWAY frame');
1926 is($frame->{code}, 1, 'invalid preface 2 - error code');
1927
1910 # invalid PROXY protocol string 1928 # invalid PROXY protocol string
1911 1929
1912 $sess = new_session(8082, proxy => 'bogus'); 1930 $sess = new_session(8082, proxy => 'bogus');
1913 $sid = new_stream($sess, { path => '/pp' }); 1931 $sid = new_stream($sess, { path => '/pp' });
1914 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); 1932 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]);
2356 } 2374 }
2357 } 2375 }
2358 2376
2359 sub new_session { 2377 sub new_session {
2360 my ($port, %extra) = @_; 2378 my ($port, %extra) = @_;
2361 my ($s); 2379
2362 2380 my $s = new_socket($port, %extra);
2363 $s = new_socket($port, %extra); 2381 my $preface = $extra{preface}
2382 || 'PRI * HTTP/2.0' . CRLF . CRLF . 'SM' . CRLF . CRLF;
2364 2383
2365 if ($extra{proxy}) { 2384 if ($extra{proxy}) {
2366 raw_write($s, $extra{proxy}); 2385 raw_write($s, $extra{proxy});
2367 } 2386 }
2368 2387
2369 # preface 2388 # preface
2370 2389
2371 raw_write($s, 'PRI * HTTP/2.0' . CRLF . CRLF . 'SM' . CRLF . CRLF); 2390 raw_write($s, $preface);
2372 2391
2373 return { socket => $s, last_stream => -1, 2392 return { socket => $s, last_stream => -1,
2374 dynamic_encode => [ static_table() ], 2393 dynamic_encode => [ static_table() ],
2375 dynamic_decode => [ static_table() ], 2394 dynamic_decode => [ static_table() ],
2376 static_table_size => scalar @{[static_table()]} }; 2395 static_table_size => scalar @{[static_table()]} };