comparison h2.t @ 759:6406eee6366c

Tests: added simple HTTP/2 tests for client GOAWAY.
author Sergey Kandaurov <pluknet@nginx.com>
date Wed, 28 Oct 2015 00:11:44 +0300
parents 70c486d09663
children 4db976a91540
comparison
equal deleted inserted replaced
758:70c486d09663 759:6406eee6366c
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(243); 35 ->has_daemon('openssl')->plan(247);
36 36
37 # Some systems may have also a bug in not treating zero writev iovcnt as EINVAL 37 # Some systems may have also a bug in not treating zero writev iovcnt as EINVAL
38 38
39 $t->todo_alerts(); 39 $t->todo_alerts();
40 40
356 $frames = h2_read(shift @sess, all => [{ type => "GOAWAY" }]); 356 $frames = h2_read(shift @sess, all => [{ type => "GOAWAY" }]);
357 ($frame) = grep { $_->{type} eq "GOAWAY" } @$frames; 357 ($frame) = grep { $_->{type} eq "GOAWAY" } @$frames;
358 ok($frame, 'idle timeout - idle connection GOAWAY'); 358 ok($frame, 'idle timeout - idle connection GOAWAY');
359 is($frame->{code}, 0, 'idle timeout - idle connection code'); 359 is($frame->{code}, 0, 'idle timeout - idle connection code');
360 360
361 # GOAWAY
362
363 h2_goaway(new_session(), 0, 0, 5);
364 h2_goaway(new_session(), 0, 0, 5, 'foobar');
365 h2_goaway(new_session(), 0, 0, 5, 'foobar', split => [ 8, 8, 4 ]);
366
367 $sess = new_session();
368 h2_goaway($sess, 0, 0, 5);
369 h2_goaway($sess, 0, 0, 5);
370
371 $sess = new_session();
372 h2_goaway($sess, 0, 0, 5, 'foobar', len => 0);
373 $frames = h2_read($sess, all => [{ type => "GOAWAY" }]);
374
375 ($frame) = grep { $_->{type} eq "GOAWAY" } @$frames;
376 ok($frame, 'GOAWAY invalid length - GOAWAY frame');
377 is($frame->{code}, 6, 'GOAWAY invalid length - GOAWAY FRAME_SIZE_ERROR');
378
379 # 6.8. GOAWAY
380 # An endpoint MUST treat a GOAWAY frame with a stream identifier other
381 # than 0x0 as a connection error (Section 5.4.1) of type PROTOCOL_ERROR.
382
383 TODO: {
384 local $TODO = 'not yet';
385
386 $sess = new_session();
387 h2_goaway($sess, 1, 0, 5, 'foobar');
388 $frames = h2_read($sess, all => [{ type => "GOAWAY" }]);
389
390 ($frame) = grep { $_->{type} eq "GOAWAY" } @$frames;
391 ok($frame, 'GOAWAY invalid stream - GOAWAY frame');
392 is($frame->{code}, 1, 'GOAWAY invalid stream - GOAWAY PROTOCOL_ERROR');
393
394 }
395
361 # GET 396 # GET
362 397
363 $sess = new_session(); 398 $sess = new_session();
364 my $sid = new_stream($sess); 399 my $sid = new_stream($sess);
365 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); 400 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]);
2447 2482
2448 sub h2_rst { 2483 sub h2_rst {
2449 my ($sess, $stream, $error) = @_; 2484 my ($sess, $stream, $error) = @_;
2450 2485
2451 raw_write($sess->{socket}, pack("x2C2xNN", 4, 0x3, $stream, $error)); 2486 raw_write($sess->{socket}, pack("x2C2xNN", 4, 0x3, $stream, $error));
2487 }
2488
2489 sub h2_goaway {
2490 my ($sess, $stream, $lstream, $err, $debug, %extra) = @_;
2491 $debug = '' unless defined $debug;
2492 my $len = defined $extra{len} ? $extra{len} : 8 + length($debug);
2493 my $buf = pack("x2C2xN3A*", $len, 0x7, $stream, $lstream, $err, $debug);
2494
2495 my @bufs = map {
2496 raw_write($sess->{socket}, substr $buf, 0, $_, "");
2497 select undef, undef, undef, 0.4;
2498 } @{$extra{split}};
2499
2500 raw_write($sess->{socket}, $buf);
2452 } 2501 }
2453 2502
2454 sub h2_priority { 2503 sub h2_priority {
2455 my ($sess, $w, $stream, $dep, %extra) = @_; 2504 my ($sess, $w, $stream, $dep, %extra) = @_;
2456 2505