comparison h2.t @ 697:46f698a7e59c

Tests: added HTTP/2 test for unknown frame type.
author Sergey Kandaurov <pluknet@nginx.com>
date Tue, 15 Sep 2015 18:40:33 +0300
parents beab9da9b731
children f86c8314d205
comparison
equal deleted inserted replaced
696:beab9da9b731 697:46f698a7e59c
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(193); 35 ->has_daemon('openssl')->plan(194);
36 36
37 $t->write_file_expand('nginx.conf', <<'EOF'); 37 $t->write_file_expand('nginx.conf', <<'EOF');
38 38
39 %%TEST_GLOBALS%% 39 %%TEST_GLOBALS%%
40 40
1710 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); 1710 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]);
1711 1711
1712 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; 1712 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
1713 is($frame->{headers}->{':status'}, 400, 'empty authority'); 1713 is($frame->{headers}->{':status'}, 400, 'empty authority');
1714 1714
1715 # unknown frame type
1716
1717 $sess = new_session();
1718 h2_unknown($sess, 'payload');
1719 h2_ping($sess, 'SEE-THIS');
1720 $frames = h2_read($sess, all => [{ type => 'PING' }]);
1721
1722 ($frame) = grep { $_->{type} eq "PING" } @$frames;
1723 is($frame->{value}, 'SEE-THIS', 'unknown frame type');
1724
1715 # GOAWAY - force closing a connection by server 1725 # GOAWAY - force closing a connection by server
1716 1726
1717 $sid = new_stream($sess, { path => 't1.html' }); 1727 $sid = new_stream($sess, { path => 't1.html' });
1718 h2_read($sess, all => [{ sid => $sid, length => 2**16 - 1 }]); 1728 h2_read($sess, all => [{ sid => $sid, length => 2**16 - 1 }]);
1719 1729
1757 my ($sess, $ack, %extra) = @_; 1767 my ($sess, $ack, %extra) = @_;
1758 1768
1759 my $len = 6 * keys %extra; 1769 my $len = 6 * keys %extra;
1760 my $buf = pack_length($len) . pack "CCx4", 0x4, $ack ? 0x1 : 0x0; 1770 my $buf = pack_length($len) . pack "CCx4", 0x4, $ack ? 0x1 : 0x0;
1761 $buf .= join '', map { pack "nN", $_, $extra{$_} } keys %extra; 1771 $buf .= join '', map { pack "nN", $_, $extra{$_} } keys %extra;
1772 raw_write($sess->{socket}, $buf);
1773 }
1774
1775 sub h2_unknown {
1776 my ($sess, $payload) = @_;
1777
1778 my $buf = pack_length(length($payload)) . pack("Cx5a*", 0xa, $payload);
1762 raw_write($sess->{socket}, $buf); 1779 raw_write($sess->{socket}, $buf);
1763 } 1780 }
1764 1781
1765 sub h2_continue { 1782 sub h2_continue {
1766 my ($ctx, $stream, $uri) = @_; 1783 my ($ctx, $stream, $uri) = @_;