Mercurial > hg > nginx-tests
changeset 311:ad164c14058a
Tests: basic proxy tests to ssl backend.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Fri, 12 Jul 2013 20:46:32 +0400 |
parents | 25f2ba615000 |
children | b639e76ba923 |
files | proxy_ssl.t |
diffstat | 1 files changed, 93 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/proxy_ssl.t Fri Jul 12 20:46:32 2013 +0400 @@ -0,0 +1,93 @@ +#!/usr/bin/perl + +# (C) Nginx, Inc. + +# Tests for proxy to ssl backend. + +############################################################################### + +use warnings; +use strict; + +use Test::More; + +BEGIN { use FindBin; chdir($FindBin::Bin); } + +use lib 'lib'; +use Test::Nginx; + +############################################################################### + +select STDERR; $| = 1; +select STDOUT; $| = 1; + +my $t = Test::Nginx->new()->has(qw/http proxy http_ssl/)->has_daemon('openssl') + ->plan(4)->write_file_expand('nginx.conf', <<'EOF'); + +%%TEST_GLOBALS%% + +daemon off; + +events { +} + +http { + %%TEST_GLOBALS_HTTP%% + + server { + listen 127.0.0.1:8081 ssl; + + ssl_certificate_key localhost.key; + ssl_certificate localhost.crt; + } + + server { + listen 127.0.0.1:8080; + server_name localhost; + + add_header X-Foo ssl; + + location /ssl_reuse { + proxy_pass https://127.0.0.1:8081/; + proxy_ssl_session_reuse on; + } + + location /ssl { + proxy_pass https://127.0.0.1:8081/; + proxy_ssl_session_reuse off; + } + } +} + +EOF + +$t->write_file('openssl.conf', <<EOF); +[ req ] +default_bits = 2048 +encrypt_key = no +distinguished_name = req_distinguished_name +[ req_distinguished_name ] +EOF + +$t->write_file('index.html', ''); + +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->run(); + +############################################################################### + +like(http_get('/ssl'), qr/200 OK.*X-Foo: ssl/ms, 'ssl'); +like(http_get('/ssl'), qr/200 OK.*X-Foo: ssl/ms, 'ssl 2'); +like(http_get('/ssl_reuse'), qr/200 OK.*X-Foo: ssl/ms, 'ssl reuse session'); +like(http_get('/ssl_reuse'), qr/200 OK.*X-Foo: ssl/ms, 'ssl reuse session 2'); + +###############################################################################