changeset 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
files h2.t
diffstat 1 files changed, 24 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- 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() ],