Mercurial > hg > nginx-tests
comparison h2.t @ 677:5d258aa5ebc5
Tests: more HTTP/2 tests for newline in request header.
Request with invalid characters in header field value is malformed.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Fri, 04 Sep 2015 15:39:39 +0300 |
parents | 42de9efd11ee |
children | b60c1a207675 |
comparison
equal
deleted
inserted
replaced
676:dbe5bc4b8b39 | 677:5d258aa5ebc5 |
---|---|
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(163); | 35 ->has_daemon('openssl')->plan(168); |
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 |
1419 | 1419 |
1420 | 1420 |
1421 # some invalid cases below | 1421 # some invalid cases below |
1422 | 1422 |
1423 # ensure that request header field value with newline doesn't get split | 1423 # ensure that request header field value with newline doesn't get split |
1424 # | |
1425 # 10.3. Intermediary Encapsulation Attacks | |
1426 # Any request or response that contains a character not permitted | |
1427 # in a header field value MUST be treated as malformed. | |
1424 | 1428 |
1425 $sess = new_session(); | 1429 $sess = new_session(); |
1426 $sid = new_stream($sess, { headers => [ | 1430 $sid = new_stream($sess, { headers => [ |
1427 { name => ':method', value => 'GET', mode => 0 }, | 1431 { name => ':method', value => 'GET', mode => 0 }, |
1428 { name => ':scheme', value => 'http', mode => 0 }, | 1432 { name => ':scheme', value => 'http', mode => 0 }, |
1429 { name => ':path', value => '/proxy2/', mode => 1 }, | 1433 { name => ':path', value => '/proxy2/', mode => 1 }, |
1430 { name => ':authority', value => 'localhost', mode => 1 }, | 1434 { name => ':authority', value => 'localhost', mode => 1 }, |
1431 { name => 'x-foo', value => "x-bar\r\nreferer:see-this", mode => 2 }]}); | 1435 { name => 'x-foo', value => "x-bar\r\nreferer:see-this", mode => 2 }]}); |
1432 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | 1436 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); |
1433 | 1437 |
1438 # 10.3. Intermediary Encapsulation Attacks | |
1439 # An intermediary therefore cannot translate an HTTP/2 request or response | |
1440 # containing an invalid field name into an HTTP/1.1 message. | |
1441 | |
1434 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | 1442 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
1435 isnt($frame->{headers}->{'x-referer'}, 'see-this', 'newline in request header'); | 1443 isnt($frame->{headers}->{'x-referer'}, 'see-this', 'newline in request header'); |
1444 | |
1445 # 8.1.2.6. Malformed Requests and Responses | |
1446 # For malformed requests, a server MAY send an HTTP response prior to | |
1447 # closing or resetting the stream. | |
1448 | |
1449 is($frame->{headers}->{':status'}, 400, 'newline in request header - status'); | |
1450 | |
1451 # 8.1.2.6. Malformed Requests and Responses | |
1452 # Malformed requests or responses that are detected MUST be treated | |
1453 # as a stream error (Section 5.4.2) of type PROTOCOL_ERROR. | |
1454 | |
1455 TODO: { | |
1456 local $TODO = 'not yet'; | |
1457 | |
1458 ($frame) = grep { $_->{type} eq "RST_STREAM" } @$frames; | |
1459 is($frame->{sid}, $sid, 'newline in request header - RST_STREAM sid'); | |
1460 is($frame->{length}, 4, 'newline in request header - RST_STREAM length'); | |
1461 is($frame->{flags}, 0, 'newline in request header - RST_STREAM flags'); | |
1462 is($frame->{code}, 1, 'newline in request header - RST_STREAM code'); | |
1463 | |
1464 } | |
1436 | 1465 |
1437 # GOAWAY on SYN_STREAM with even StreamID | 1466 # GOAWAY on SYN_STREAM with even StreamID |
1438 | 1467 |
1439 TODO: { | 1468 TODO: { |
1440 local $TODO = 'not yet'; | 1469 local $TODO = 'not yet'; |