changeset 886:af2cd0ba6ca7

Tests: fixed HTTP/2 test for empty request body proxied with https. The test was broken with splitting h2.t due to missing ssl_certificate. Break the test out into a separate file as it depends on openssl binary.
author Sergey Kandaurov <pluknet@nginx.com>
date Fri, 25 Mar 2016 22:19:54 +0300
parents a1e76cca714c
children 5debefd670bc
files h2_proxy_ssl.t h2_request_body.t
diffstat 2 files changed, 100 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
new file mode 100644
--- /dev/null
+++ b/h2_proxy_ssl.t
@@ -0,0 +1,99 @@
+#!/usr/bin/perl
+
+# (C) Sergey Kandaurov
+# (C) Nginx, Inc.
+
+# Tests for HTTP/2 protocol with proxy to ssl backend.
+
+###############################################################################
+
+use warnings;
+use strict;
+
+use Test::More;
+
+BEGIN { use FindBin; chdir($FindBin::Bin); }
+
+use lib 'lib';
+use Test::Nginx;
+use Test::Nginx::HTTP2 qw/ :DEFAULT :frame /;
+
+###############################################################################
+
+select STDERR; $| = 1;
+select STDOUT; $| = 1;
+
+my $t = Test::Nginx->new()->has(qw/http http_ssl http_v2 proxy/)
+	->has_daemon('openssl')->plan(1);
+
+$t->todo_alerts();
+
+$t->write_file_expand('nginx.conf', <<'EOF');
+
+%%TEST_GLOBALS%%
+
+daemon off;
+
+events {
+}
+
+http {
+    %%TEST_GLOBALS_HTTP%%
+
+    server {
+        listen       127.0.0.1:8080 http2;
+        listen       127.0.0.1:8081 ssl;
+        server_name  localhost;
+
+        ssl_certificate_key localhost.key;
+        ssl_certificate localhost.crt;
+
+        location / { }
+        location /proxy_ssl/ {
+            proxy_pass https://127.0.0.1:8081/;
+        }
+    }
+}
+
+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";
+}
+
+$t->write_file('index.html', '');
+$t->run();
+
+###############################################################################
+
+# request body with an empty DATA frame proxied to ssl backend
+# "zero size buf in output" alerts seen
+
+TODO: {
+local $TODO = 'not yet';
+
+my $sess = new_session();
+my $sid = new_stream($sess, { path => '/proxy_ssl/', body_more => 1 });
+h2_body($sess, '');
+my $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]);
+
+my ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
+is($frame->{headers}->{':status'}, 200, 'empty request body');
+
+}
+
+###############################################################################
--- a/h2_request_body.t
+++ b/h2_request_body.t
@@ -23,9 +23,7 @@ use Test::Nginx::HTTP2 qw/ :DEFAULT :fra
 select STDERR; $| = 1;
 select STDOUT; $| = 1;
 
-my $t = Test::Nginx->new()->has(qw/http http_ssl http_v2 proxy/)->plan(35);
-
-# Some systems may have also a bug in not treating zero writev iovcnt as EINVAL
+my $t = Test::Nginx->new()->has(qw/http http_v2 proxy/)->plan(34);
 
 $t->todo_alerts();
 
@@ -44,7 +42,6 @@ http {
     server {
         listen       127.0.0.1:8080 http2;
         listen       127.0.0.1:8081;
-        listen       127.0.0.1:8082 ssl;
         server_name  localhost;
 
         location / { }
@@ -54,9 +51,6 @@ http {
             client_body_in_file_only on;
             proxy_pass http://127.0.0.1:8081/;
         }
-        location /proxy_ssl/ {
-            proxy_pass https://127.0.0.1:8082/;
-        }
         location /client_max_body_size {
             add_header X-Body $request_body;
             add_header X-Body-File $request_body_file;
@@ -153,21 +147,6 @@ is(read_body_file($frame->{headers}{'x-b
 
 }
 
-# same as above but proxied to ssl backend
-
-TODO: {
-local $TODO = 'not yet';
-
-$sess = new_session();
-$sid = new_stream($sess, { path => '/proxy_ssl/', body_more => 1 });
-h2_body($sess, '');
-$frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]);
-
-($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
-is($frame->{headers}->{':status'}, 200, 'request body - empty - proxy ssl');
-
-}
-
 # malformed request body length not equal to content-length
 
 $sess = new_session();