Mercurial > hg > nginx-tests
changeset 985:de513b115e68
Tests: renamed some HTTP/2 tests to follow naming convention.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Wed, 20 Jul 2016 11:07:20 +0300 |
parents | 892737e9fd31 |
children | 99f93be57416 |
files | h2_cache.t h2_proxy_cache.t h2_ssl.t h2_ssl_variables.t |
diffstat | 4 files changed, 364 insertions(+), 364 deletions(-) [+] |
line wrap: on
line diff
--- a/h2_cache.t Mon Jul 18 17:58:19 2016 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,148 +0,0 @@ -#!/usr/bin/perl - -# (C) Sergey Kandaurov -# (C) Nginx, Inc. - -# Tests for HTTP/2 protocol with cache. - -############################################################################### - -use warnings; -use strict; - -use Test::More; - -BEGIN { use FindBin; chdir($FindBin::Bin); } - -use lib 'lib'; -use Test::Nginx; -use Test::Nginx::HTTP2; - -############################################################################### - -select STDERR; $| = 1; -select STDOUT; $| = 1; - -my $t = Test::Nginx->new()->has(qw/http http_v2 proxy cache/)->plan(11) - ->write_file_expand('nginx.conf', <<'EOF'); - -%%TEST_GLOBALS%% - -daemon off; - -events { -} - -http { - %%TEST_GLOBALS_HTTP%% - - proxy_cache_path %%TESTDIR%%/cache keys_zone=NAME:1m; - - server { - listen 127.0.0.1:8080 http2; - listen 127.0.0.1:8081; - server_name localhost; - - location /cache { - proxy_pass http://127.0.0.1:8081/; - proxy_cache NAME; - proxy_cache_valid 1m; - } - location /proxy_buffering_off { - proxy_pass http://127.0.0.1:8081/; - proxy_cache NAME; - proxy_cache_valid 1m; - proxy_buffering off; - } - } -} - -EOF - -$t->write_file('t.html', 'SEE-THIS'); -$t->run(); - -############################################################################### - -# simple proxy cache test - -my $s = Test::Nginx::HTTP2->new(); -my $sid = $s->new_stream({ path => '/cache/t.html' }); -my $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); - -my ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; -is($frame->{headers}->{':status'}, '200', 'proxy cache'); - -my $etag = $frame->{headers}->{'etag'}; - -($frame) = grep { $_->{type} eq "DATA" } @$frames; -is($frame->{length}, length 'SEE-THIS', 'proxy cache - DATA'); -is($frame->{data}, 'SEE-THIS', 'proxy cache - DATA payload'); - -$t->write_file('t.html', 'NOOP'); - -$sid = $s->new_stream({ headers => [ - { name => ':method', value => 'GET', mode => 0 }, - { name => ':scheme', value => 'http', mode => 0 }, - { name => ':path', value => '/cache/t.html' }, - { name => ':authority', value => 'localhost', mode => 1 }, - { name => 'if-none-match', value => $etag }]}); -$frames = $s->read(all => [{ sid => $sid, fin => 1 }]); - -($frame) = grep { $_->{type} eq "HEADERS" } @$frames; -is($frame->{headers}->{':status'}, 304, 'proxy cache conditional'); - -$t->write_file('t.html', 'SEE-THIS'); - -# request body with cached response - -$sid = $s->new_stream({ path => '/cache/t.html', body_more => 1 }); -$s->h2_body('TEST'); -$frames = $s->read(all => [{ sid => $sid, fin => 1 }]); - -($frame) = grep { $_->{type} eq "HEADERS" } @$frames; -is($frame->{headers}->{':status'}, 200, 'proxy cache - request body'); - -$s->h2_ping('SEE-THIS'); -$frames = $s->read(all => [{ type => 'PING' }]); - -($frame) = grep { $_->{type} eq "PING" && $_->{flags} & 0x1 } @$frames; -ok($frame, 'proxy cache - request body - next'); - -# HEADERS could be received with fin, followed by DATA - -$s = Test::Nginx::HTTP2->new(); -$sid = $s->new_stream({ path => '/cache/t.html?1', method => 'HEAD' }); - -$frames = $s->read(all => [{ sid => $sid, fin => 1 }], wait => 0.2); -push @$frames, $_ for @{$s->read(all => [{ sid => $sid }], wait => 0.2)}; -ok(!grep ({ $_->{type} eq "DATA" } @$frames), 'proxy cache HEAD - no body'); - -# proxy cache - expect no stray empty DATA frame - -TODO: { -local $TODO = 'not yet'; - -$s = Test::Nginx::HTTP2->new(); -$sid = $s->new_stream({ path => '/cache/t.html?2' }); - -$frames = $s->read(all => [{ sid => $sid, fin => 1 }]); -my @data = grep ({ $_->{type} eq "DATA" } @$frames); -is(@data, 1, 'proxy cache write - data frames'); -is(join(' ', map { $_->{data} } @data), 'SEE-THIS', 'proxy cache write - data'); -is(join(' ', map { $_->{flags} } @data), '1', 'proxy cache write - flags'); - -} - -# HEAD on empty cache with proxy_buffering off - -$s = Test::Nginx::HTTP2->new(); -$sid = $s->new_stream( - { path => '/proxy_buffering_off/t.html?1', method => 'HEAD' }); - -$frames = $s->read(all => [{ sid => $sid, fin => 1 }]); -push @$frames, $_ for @{$s->read(all => [{ sid => $sid }], wait => 0.2)}; -ok(!grep ({ $_->{type} eq "DATA" } @$frames), - 'proxy cache HEAD buffering off - no body'); - -###############################################################################
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/h2_proxy_cache.t Wed Jul 20 11:07:20 2016 +0300 @@ -0,0 +1,148 @@ +#!/usr/bin/perl + +# (C) Sergey Kandaurov +# (C) Nginx, Inc. + +# Tests for HTTP/2 protocol with cache. + +############################################################################### + +use warnings; +use strict; + +use Test::More; + +BEGIN { use FindBin; chdir($FindBin::Bin); } + +use lib 'lib'; +use Test::Nginx; +use Test::Nginx::HTTP2; + +############################################################################### + +select STDERR; $| = 1; +select STDOUT; $| = 1; + +my $t = Test::Nginx->new()->has(qw/http http_v2 proxy cache/)->plan(11) + ->write_file_expand('nginx.conf', <<'EOF'); + +%%TEST_GLOBALS%% + +daemon off; + +events { +} + +http { + %%TEST_GLOBALS_HTTP%% + + proxy_cache_path %%TESTDIR%%/cache keys_zone=NAME:1m; + + server { + listen 127.0.0.1:8080 http2; + listen 127.0.0.1:8081; + server_name localhost; + + location /cache { + proxy_pass http://127.0.0.1:8081/; + proxy_cache NAME; + proxy_cache_valid 1m; + } + location /proxy_buffering_off { + proxy_pass http://127.0.0.1:8081/; + proxy_cache NAME; + proxy_cache_valid 1m; + proxy_buffering off; + } + } +} + +EOF + +$t->write_file('t.html', 'SEE-THIS'); +$t->run(); + +############################################################################### + +# simple proxy cache test + +my $s = Test::Nginx::HTTP2->new(); +my $sid = $s->new_stream({ path => '/cache/t.html' }); +my $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); + +my ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; +is($frame->{headers}->{':status'}, '200', 'proxy cache'); + +my $etag = $frame->{headers}->{'etag'}; + +($frame) = grep { $_->{type} eq "DATA" } @$frames; +is($frame->{length}, length 'SEE-THIS', 'proxy cache - DATA'); +is($frame->{data}, 'SEE-THIS', 'proxy cache - DATA payload'); + +$t->write_file('t.html', 'NOOP'); + +$sid = $s->new_stream({ headers => [ + { name => ':method', value => 'GET', mode => 0 }, + { name => ':scheme', value => 'http', mode => 0 }, + { name => ':path', value => '/cache/t.html' }, + { name => ':authority', value => 'localhost', mode => 1 }, + { name => 'if-none-match', value => $etag }]}); +$frames = $s->read(all => [{ sid => $sid, fin => 1 }]); + +($frame) = grep { $_->{type} eq "HEADERS" } @$frames; +is($frame->{headers}->{':status'}, 304, 'proxy cache conditional'); + +$t->write_file('t.html', 'SEE-THIS'); + +# request body with cached response + +$sid = $s->new_stream({ path => '/cache/t.html', body_more => 1 }); +$s->h2_body('TEST'); +$frames = $s->read(all => [{ sid => $sid, fin => 1 }]); + +($frame) = grep { $_->{type} eq "HEADERS" } @$frames; +is($frame->{headers}->{':status'}, 200, 'proxy cache - request body'); + +$s->h2_ping('SEE-THIS'); +$frames = $s->read(all => [{ type => 'PING' }]); + +($frame) = grep { $_->{type} eq "PING" && $_->{flags} & 0x1 } @$frames; +ok($frame, 'proxy cache - request body - next'); + +# HEADERS could be received with fin, followed by DATA + +$s = Test::Nginx::HTTP2->new(); +$sid = $s->new_stream({ path => '/cache/t.html?1', method => 'HEAD' }); + +$frames = $s->read(all => [{ sid => $sid, fin => 1 }], wait => 0.2); +push @$frames, $_ for @{$s->read(all => [{ sid => $sid }], wait => 0.2)}; +ok(!grep ({ $_->{type} eq "DATA" } @$frames), 'proxy cache HEAD - no body'); + +# proxy cache - expect no stray empty DATA frame + +TODO: { +local $TODO = 'not yet'; + +$s = Test::Nginx::HTTP2->new(); +$sid = $s->new_stream({ path => '/cache/t.html?2' }); + +$frames = $s->read(all => [{ sid => $sid, fin => 1 }]); +my @data = grep ({ $_->{type} eq "DATA" } @$frames); +is(@data, 1, 'proxy cache write - data frames'); +is(join(' ', map { $_->{data} } @data), 'SEE-THIS', 'proxy cache write - data'); +is(join(' ', map { $_->{flags} } @data), '1', 'proxy cache write - flags'); + +} + +# HEAD on empty cache with proxy_buffering off + +$s = Test::Nginx::HTTP2->new(); +$sid = $s->new_stream( + { path => '/proxy_buffering_off/t.html?1', method => 'HEAD' }); + +$frames = $s->read(all => [{ sid => $sid, fin => 1 }]); +push @$frames, $_ for @{$s->read(all => [{ sid => $sid }], wait => 0.2)}; +ok(!grep ({ $_->{type} eq "DATA" } @$frames), + 'proxy cache HEAD buffering off - no body'); + +###############################################################################
--- a/h2_ssl.t Mon Jul 18 17:58:19 2016 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,216 +0,0 @@ -#!/usr/bin/perl - -# (C) Sergey Kandaurov -# (C) Nginx, Inc. - -# Tests for HTTP/2 protocol with ssl. - -############################################################################### - -use warnings; -use strict; - -use Test::More; - -BEGIN { use FindBin; chdir($FindBin::Bin); } - -use lib 'lib'; -use Test::Nginx; -use Test::Nginx::HTTP2; - -############################################################################### - -select STDERR; $| = 1; -select STDOUT; $| = 1; - -eval { require IO::Socket::SSL; }; -plan(skip_all => 'IO::Socket::SSL not installed') if $@; -eval { IO::Socket::SSL::SSL_VERIFY_NONE(); }; -plan(skip_all => 'IO::Socket::SSL too old') if $@; - -my $t = Test::Nginx->new()->has(qw/http http_ssl http_v2 rewrite/) - ->has_daemon('openssl')->plan(8); - -$t->write_file_expand('nginx.conf', <<'EOF'); - -%%TEST_GLOBALS%% - -daemon off; - -events { -} - -http { - %%TEST_GLOBALS_HTTP%% - - server { - listen 127.0.0.1:8080 http2 ssl; - server_name localhost; - - ssl_certificate_key localhost.key; - ssl_certificate localhost.crt; - - location /h2 { - return 200 $http2; - } - location /sp { - return 200 $server_protocol; - } - location /scheme { - return 200 $scheme; - } - location /https { - return 200 $https; - } - } -} - -EOF - -$t->write_file('openssl.conf', <<EOF); -[ req ] -default_bits = 2048 -encrypt_key = no -distinguished_name = req_distinguished_name -[ req_distinguished_name ] -EOF - -my $d = $t->testdir(); - -foreach my $name ('localhost') { - system('openssl req -x509 -new ' - . "-config '$d/openssl.conf' -subj '/CN=$name/' " - . "-out '$d/$name.crt' -keyout '$d/$name.key' " - . ">>$d/openssl.out 2>&1") == 0 - or die "Can't create certificate for $name: $!\n"; -} - -open OLDERR, ">&", \*STDERR; close STDERR; -$t->run(); -open STDERR, ">&", \*OLDERR; - -############################################################################### - -my ($s, $sid, $frames, $frame); - -# SSL/TLS connection, NPN - -SKIP: { -eval { IO::Socket::SSL->can_npn() or die; }; -skip 'OpenSSL NPN support required', 1 if $@; - -$s = Test::Nginx::HTTP2->new(port(8080), SSL => 1, npn => 'h2'); -$sid = $s->new_stream({ path => '/h2' }); -$frames = $s->read(all => [{ sid => $sid, fin => 1 }]); - -($frame) = grep { $_->{type} eq "DATA" } @$frames; -is($frame->{data}, 'h2', 'http variable - npn'); - -} - -# SSL/TLS connection, ALPN - -SKIP: { -eval { IO::Socket::SSL->can_alpn() or die; }; -skip 'OpenSSL ALPN support required', 1 if $@; - -$s = Test::Nginx::HTTP2->new(port(8080), SSL => 1, alpn => 'h2'); -$sid = $s->new_stream({ path => '/h2' }); -$frames = $s->read(all => [{ sid => $sid, fin => 1 }]); - -($frame) = grep { $_->{type} eq "DATA" } @$frames; -is($frame->{data}, 'h2', 'http variable - alpn'); - -} - -# $server_protocol - SSL/TLS connection, NPN - -SKIP: { -eval { IO::Socket::SSL->can_npn() or die; }; -skip 'OpenSSL NPN support required', 1 if $@; - -$s = Test::Nginx::HTTP2->new(port(8080), SSL => 1, npn => 'h2'); -$sid = $s->new_stream({ path => '/sp' }); -$frames = $s->read(all => [{ sid => $sid, fin => 1 }]); - -($frame) = grep { $_->{type} eq "DATA" } @$frames; -is($frame->{data}, 'HTTP/2.0', 'server_protocol variable - npn'); - -} - -# $server_protocol - SSL/TLS connection, ALPN - -SKIP: { -eval { IO::Socket::SSL->can_alpn() or die; }; -skip 'OpenSSL ALPN support required', 1 if $@; - -$s = Test::Nginx::HTTP2->new(port(8080), SSL => 1, alpn => 'h2'); -$sid = $s->new_stream({ path => '/sp' }); -$frames = $s->read(all => [{ sid => $sid, fin => 1 }]); - -($frame) = grep { $_->{type} eq "DATA" } @$frames; -is($frame->{data}, 'HTTP/2.0', 'server_protocol variable - alpn'); - -} - -# $scheme - SSL/TLS connection, NPN - -SKIP: { -eval { IO::Socket::SSL->can_npn() or die; }; -skip 'OpenSSL NPN support required', 1 if $@; - -$s = Test::Nginx::HTTP2->new(port(8080), SSL => 1, npn => 'h2'); -$sid = $s->new_stream({ path => '/scheme' }); -$frames = $s->read(all => [{ sid => $sid, fin => 1 }]); - -($frame) = grep { $_->{type} eq "DATA" } @$frames; -is($frame->{data}, 'https', 'scheme variable - npn'); - -} - -# $scheme - SSL/TLS connection, ALPN - -SKIP: { -eval { IO::Socket::SSL->can_alpn() or die; }; -skip 'OpenSSL ALPN support required', 1 if $@; - -$s = Test::Nginx::HTTP2->new(port(8080), SSL => 1, alpn => 'h2'); -$sid = $s->new_stream({ path => '/scheme' }); -$frames = $s->read(all => [{ sid => $sid, fin => 1 }]); - -($frame) = grep { $_->{type} eq "DATA" } @$frames; -is($frame->{data}, 'https', 'scheme variable - alpn'); - -} - -# $https - SSL/TLS connection, NPN - -SKIP: { -eval { IO::Socket::SSL->can_npn() or die; }; -skip 'OpenSSL NPN support required', 1 if $@; - -$s = Test::Nginx::HTTP2->new(port(8080), SSL => 1, npn => 'h2'); -$sid = $s->new_stream({ path => '/https' }); -$frames = $s->read(all => [{ sid => $sid, fin => 1 }]); - -($frame) = grep { $_->{type} eq "DATA" } @$frames; -is($frame->{data}, 'on', 'https variable - npn'); - -} - -# $https - SSL/TLS connection, ALPN - -SKIP: { -eval { IO::Socket::SSL->can_alpn() or die; }; -skip 'OpenSSL ALPN support required', 1 if $@; - -$s = Test::Nginx::HTTP2->new(port(8080), SSL => 1, alpn => 'h2'); -$sid = $s->new_stream({ path => '/https' }); -$frames = $s->read(all => [{ sid => $sid, fin => 1 }]); - -($frame) = grep { $_->{type} eq "DATA" } @$frames; -is($frame->{data}, 'on', 'https variable - alpn'); - -} - -###############################################################################
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/h2_ssl_variables.t Wed Jul 20 11:07:20 2016 +0300 @@ -0,0 +1,216 @@ +#!/usr/bin/perl + +# (C) Sergey Kandaurov +# (C) Nginx, Inc. + +# Tests for HTTP/2 protocol with ssl. + +############################################################################### + +use warnings; +use strict; + +use Test::More; + +BEGIN { use FindBin; chdir($FindBin::Bin); } + +use lib 'lib'; +use Test::Nginx; +use Test::Nginx::HTTP2; + +############################################################################### + +select STDERR; $| = 1; +select STDOUT; $| = 1; + +eval { require IO::Socket::SSL; }; +plan(skip_all => 'IO::Socket::SSL not installed') if $@; +eval { IO::Socket::SSL::SSL_VERIFY_NONE(); }; +plan(skip_all => 'IO::Socket::SSL too old') if $@; + +my $t = Test::Nginx->new()->has(qw/http http_ssl http_v2 rewrite/) + ->has_daemon('openssl')->plan(8); + +$t->write_file_expand('nginx.conf', <<'EOF'); + +%%TEST_GLOBALS%% + +daemon off; + +events { +} + +http { + %%TEST_GLOBALS_HTTP%% + + server { + listen 127.0.0.1:8080 http2 ssl; + server_name localhost; + + ssl_certificate_key localhost.key; + ssl_certificate localhost.crt; + + location /h2 { + return 200 $http2; + } + location /sp { + return 200 $server_protocol; + } + location /scheme { + return 200 $scheme; + } + location /https { + return 200 $https; + } + } +} + +EOF + +$t->write_file('openssl.conf', <<EOF); +[ req ] +default_bits = 2048 +encrypt_key = no +distinguished_name = req_distinguished_name +[ req_distinguished_name ] +EOF + +my $d = $t->testdir(); + +foreach my $name ('localhost') { + system('openssl req -x509 -new ' + . "-config '$d/openssl.conf' -subj '/CN=$name/' " + . "-out '$d/$name.crt' -keyout '$d/$name.key' " + . ">>$d/openssl.out 2>&1") == 0 + or die "Can't create certificate for $name: $!\n"; +} + +open OLDERR, ">&", \*STDERR; close STDERR; +$t->run(); +open STDERR, ">&", \*OLDERR; + +############################################################################### + +my ($s, $sid, $frames, $frame); + +# SSL/TLS connection, NPN + +SKIP: { +eval { IO::Socket::SSL->can_npn() or die; }; +skip 'OpenSSL NPN support required', 1 if $@; + +$s = Test::Nginx::HTTP2->new(port(8080), SSL => 1, npn => 'h2'); +$sid = $s->new_stream({ path => '/h2' }); +$frames = $s->read(all => [{ sid => $sid, fin => 1 }]); + +($frame) = grep { $_->{type} eq "DATA" } @$frames; +is($frame->{data}, 'h2', 'http variable - npn'); + +} + +# SSL/TLS connection, ALPN + +SKIP: { +eval { IO::Socket::SSL->can_alpn() or die; }; +skip 'OpenSSL ALPN support required', 1 if $@; + +$s = Test::Nginx::HTTP2->new(port(8080), SSL => 1, alpn => 'h2'); +$sid = $s->new_stream({ path => '/h2' }); +$frames = $s->read(all => [{ sid => $sid, fin => 1 }]); + +($frame) = grep { $_->{type} eq "DATA" } @$frames; +is($frame->{data}, 'h2', 'http variable - alpn'); + +} + +# $server_protocol - SSL/TLS connection, NPN + +SKIP: { +eval { IO::Socket::SSL->can_npn() or die; }; +skip 'OpenSSL NPN support required', 1 if $@; + +$s = Test::Nginx::HTTP2->new(port(8080), SSL => 1, npn => 'h2'); +$sid = $s->new_stream({ path => '/sp' }); +$frames = $s->read(all => [{ sid => $sid, fin => 1 }]); + +($frame) = grep { $_->{type} eq "DATA" } @$frames; +is($frame->{data}, 'HTTP/2.0', 'server_protocol variable - npn'); + +} + +# $server_protocol - SSL/TLS connection, ALPN + +SKIP: { +eval { IO::Socket::SSL->can_alpn() or die; }; +skip 'OpenSSL ALPN support required', 1 if $@; + +$s = Test::Nginx::HTTP2->new(port(8080), SSL => 1, alpn => 'h2'); +$sid = $s->new_stream({ path => '/sp' }); +$frames = $s->read(all => [{ sid => $sid, fin => 1 }]); + +($frame) = grep { $_->{type} eq "DATA" } @$frames; +is($frame->{data}, 'HTTP/2.0', 'server_protocol variable - alpn'); + +} + +# $scheme - SSL/TLS connection, NPN + +SKIP: { +eval { IO::Socket::SSL->can_npn() or die; }; +skip 'OpenSSL NPN support required', 1 if $@; + +$s = Test::Nginx::HTTP2->new(port(8080), SSL => 1, npn => 'h2'); +$sid = $s->new_stream({ path => '/scheme' }); +$frames = $s->read(all => [{ sid => $sid, fin => 1 }]); + +($frame) = grep { $_->{type} eq "DATA" } @$frames; +is($frame->{data}, 'https', 'scheme variable - npn'); + +} + +# $scheme - SSL/TLS connection, ALPN + +SKIP: { +eval { IO::Socket::SSL->can_alpn() or die; }; +skip 'OpenSSL ALPN support required', 1 if $@; + +$s = Test::Nginx::HTTP2->new(port(8080), SSL => 1, alpn => 'h2'); +$sid = $s->new_stream({ path => '/scheme' }); +$frames = $s->read(all => [{ sid => $sid, fin => 1 }]); + +($frame) = grep { $_->{type} eq "DATA" } @$frames; +is($frame->{data}, 'https', 'scheme variable - alpn'); + +} + +# $https - SSL/TLS connection, NPN + +SKIP: { +eval { IO::Socket::SSL->can_npn() or die; }; +skip 'OpenSSL NPN support required', 1 if $@; + +$s = Test::Nginx::HTTP2->new(port(8080), SSL => 1, npn => 'h2'); +$sid = $s->new_stream({ path => '/https' }); +$frames = $s->read(all => [{ sid => $sid, fin => 1 }]); + +($frame) = grep { $_->{type} eq "DATA" } @$frames; +is($frame->{data}, 'on', 'https variable - npn'); + +} + +# $https - SSL/TLS connection, ALPN + +SKIP: { +eval { IO::Socket::SSL->can_alpn() or die; }; +skip 'OpenSSL ALPN support required', 1 if $@; + +$s = Test::Nginx::HTTP2->new(port(8080), SSL => 1, alpn => 'h2'); +$sid = $s->new_stream({ path => '/https' }); +$frames = $s->read(all => [{ sid => $sid, fin => 1 }]); + +($frame) = grep { $_->{type} eq "DATA" } @$frames; +is($frame->{data}, 'on', 'https variable - alpn'); + +} + +###############################################################################