Mercurial > hg > nginx-tests
comparison proxy_ssl_keepalive.t @ 693:875900f02f15
Tests: added proxy keepalive tests to ssl backend.
author | Andrey Zelenkov <zelenkov@nginx.com> |
---|---|
date | Mon, 14 Sep 2015 18:20:58 +0300 |
parents | |
children | e9064d691790 |
comparison
equal
deleted
inserted
replaced
692:a16d4a768197 | 693:875900f02f15 |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 # (C) Andrey Zelenkov | |
4 # (C) Nginx, Inc. | |
5 | |
6 # Tests for proxy with keepalive to ssl backend. | |
7 | |
8 ############################################################################### | |
9 | |
10 use warnings; | |
11 use strict; | |
12 | |
13 use Test::More; | |
14 | |
15 BEGIN { use FindBin; chdir($FindBin::Bin); } | |
16 | |
17 use lib 'lib'; | |
18 use Test::Nginx; | |
19 | |
20 ############################################################################### | |
21 | |
22 select STDERR; $| = 1; | |
23 select STDOUT; $| = 1; | |
24 | |
25 eval { require IO::Socket::SSL; }; | |
26 plan(skip_all => 'IO::Socket::SSL not installed') if $@; | |
27 | |
28 my $t = Test::Nginx->new()->has(qw/http http_ssl proxy upstream_keepalive/) | |
29 ->has_daemon('openssl')->plan(3) | |
30 ->write_file_expand('nginx.conf', <<'EOF'); | |
31 | |
32 %%TEST_GLOBALS%% | |
33 | |
34 daemon off; | |
35 | |
36 events { | |
37 } | |
38 | |
39 http { | |
40 %%TEST_GLOBALS_HTTP%% | |
41 | |
42 upstream u { | |
43 server 127.0.0.1:8081; | |
44 keepalive 1; | |
45 } | |
46 | |
47 server { | |
48 listen 127.0.0.1:8080; | |
49 server_name localhost; | |
50 | |
51 proxy_http_version 1.1; | |
52 | |
53 location / { | |
54 proxy_pass https://u/; | |
55 proxy_set_header Connection $args; | |
56 } | |
57 } | |
58 | |
59 server { | |
60 listen 127.0.0.1:8081 ssl; | |
61 server_name localhost; | |
62 | |
63 ssl_certificate_key localhost.key; | |
64 ssl_certificate localhost.crt; | |
65 | |
66 location / { | |
67 add_header X-Connection $connection; | |
68 } | |
69 } | |
70 } | |
71 | |
72 EOF | |
73 | |
74 $t->write_file('openssl.conf', <<EOF); | |
75 [ req ] | |
76 default_bits = 2048 | |
77 encrypt_key = no | |
78 distinguished_name = req_distinguished_name | |
79 [ req_distinguished_name ] | |
80 EOF | |
81 | |
82 my $d = $t->testdir(); | |
83 | |
84 foreach my $name ('localhost') { | |
85 system('openssl req -x509 -new ' | |
86 . "-config '$d/openssl.conf' -subj '/CN=$name/' " | |
87 . "-out '$d/$name.crt' -keyout '$d/$name.key' " | |
88 . ">>$d/openssl.out 2>&1") == 0 | |
89 or die "Can't create certificate for $name: $!\n"; | |
90 } | |
91 | |
92 $t->write_file('index.html', 'SEE-THIS'); | |
93 $t->run(); | |
94 | |
95 ############################################################################### | |
96 | |
97 my ($r, $n); | |
98 | |
99 like($r = http_get('/'), qr/200 OK.*SEE-THIS/ms, 'first'); | |
100 $r =~ m/X-Connection: (\d+)/; $n = $1; | |
101 like(http_get('/'), qr/X-Connection: $n[^\d].*SEE-THIS/ms, 'second'); | |
102 | |
103 http_get('/?close'); | |
104 unlike(http_get('/'), qr/X-Connection: $n[^\d]/, 'close'); | |
105 | |
106 ############################################################################### |