Mercurial > hg > nginx-tests
comparison stream_proxy_ssl_name_complex.t @ 989:98546e08521f
Tests: stream tests for proxy_ssl_name with complex value.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Thu, 21 Jul 2016 14:01:02 +0300 |
parents | |
children | 8ef51dbb5d69 |
comparison
equal
deleted
inserted
replaced
988:64505109060c | 989:98546e08521f |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 # (C) Sergey Kandaurov | |
4 # (C) Nginx, Inc. | |
5 | |
6 # Stream tests for proxy to ssl backend, use of Server Name Indication | |
7 # (proxy_ssl_name, proxy_ssl_server_name directives) with complex value. | |
8 | |
9 ############################################################################### | |
10 | |
11 use warnings; | |
12 use strict; | |
13 | |
14 use Test::More; | |
15 | |
16 BEGIN { use FindBin; chdir($FindBin::Bin); } | |
17 | |
18 use lib 'lib'; | |
19 use Test::Nginx; | |
20 use Test::Nginx::Stream qw/ stream /; | |
21 | |
22 ############################################################################### | |
23 | |
24 select STDERR; $| = 1; | |
25 select STDOUT; $| = 1; | |
26 | |
27 my $t = Test::Nginx->new()->has(qw/stream stream_ssl stream_return sni/) | |
28 ->has_daemon('openssl'); | |
29 | |
30 $t->write_file_expand('nginx.conf', <<'EOF'); | |
31 | |
32 %%TEST_GLOBALS%% | |
33 | |
34 daemon off; | |
35 | |
36 events { | |
37 } | |
38 | |
39 stream { | |
40 proxy_ssl on; | |
41 proxy_ssl_session_reuse off; | |
42 | |
43 server { | |
44 listen 127.0.0.1:8081; | |
45 listen 127.0.0.1:8082; | |
46 proxy_pass 127.0.0.1:8085; | |
47 | |
48 proxy_ssl_server_name on; | |
49 proxy_ssl_name x${server_port}x; | |
50 } | |
51 | |
52 server { | |
53 ssl_certificate_key localhost.key; | |
54 ssl_certificate localhost.crt; | |
55 | |
56 listen 127.0.0.1:8085 ssl; | |
57 return $ssl_server_name; | |
58 } | |
59 } | |
60 | |
61 EOF | |
62 | |
63 $t->write_file('openssl.conf', <<EOF); | |
64 [ req ] | |
65 default_bits = 2048 | |
66 encrypt_key = no | |
67 distinguished_name = req_distinguished_name | |
68 [ req_distinguished_name ] | |
69 EOF | |
70 | |
71 my $d = $t->testdir(); | |
72 | |
73 foreach my $name ('localhost') { | |
74 system('openssl req -x509 -new ' | |
75 . "-config '$d/openssl.conf' -subj '/CN=$name/' " | |
76 . "-out '$d/$name.crt' -keyout '$d/$name.key' " | |
77 . ">>$d/openssl.out 2>&1") == 0 | |
78 or die "Can't create certificate for $name: $!\n"; | |
79 } | |
80 | |
81 $t->try_run('no stream return')->plan(2); | |
82 | |
83 ############################################################################### | |
84 | |
85 my ($p1, $p2) = (port(8081), port(8082)); | |
86 | |
87 is(stream("127.0.0.1:$p1")->read(), "x${p1}x", 'name 1'); | |
88 is(stream("127.0.0.1:$p2")->read(), "x${p2}x", 'name 2'); | |
89 | |
90 ############################################################################### |