Mercurial > hg > nginx-tests
comparison h2_ssl_proxy_cache.t @ 986:99f93be57416
Tests: various HTTP/2 tests with canceled stream.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Wed, 20 Jul 2016 11:07:22 +0300 |
parents | |
children | 3c5d3b384d3f |
comparison
equal
deleted
inserted
replaced
985:de513b115e68 | 986:99f93be57416 |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 # (C) Sergey Kandaurov | |
4 # (C) Nginx, Inc. | |
5 | |
6 # Tests for HTTP/2 protocol with ssl and http proxy cache. | |
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 use Test::Nginx::HTTP2; | |
20 | |
21 ############################################################################### | |
22 | |
23 select STDERR; $| = 1; | |
24 select STDOUT; $| = 1; | |
25 | |
26 eval { require IO::Socket::SSL; }; | |
27 plan(skip_all => 'IO::Socket::SSL not installed') if $@; | |
28 | |
29 my $t = Test::Nginx->new()->has(qw/http http_ssl http_v2 proxy cache shmem/) | |
30 ->has_daemon('openssl'); | |
31 | |
32 $t->todo_alerts(); | |
33 | |
34 $t->write_file_expand('nginx.conf', <<'EOF'); | |
35 | |
36 %%TEST_GLOBALS%% | |
37 | |
38 daemon off; | |
39 | |
40 events { | |
41 } | |
42 | |
43 http { | |
44 %%TEST_GLOBALS_HTTP%% | |
45 | |
46 proxy_cache_path %%TESTDIR%%/cache keys_zone=NAME:1m; | |
47 | |
48 server { | |
49 listen 127.0.0.1:8080 http2 ssl sndbuf=32k; | |
50 server_name localhost; | |
51 | |
52 ssl_certificate_key localhost.key; | |
53 ssl_certificate localhost.crt; | |
54 | |
55 send_timeout 1s; | |
56 | |
57 location / { | |
58 proxy_pass http://127.0.0.1:8081; | |
59 proxy_cache NAME; | |
60 } | |
61 } | |
62 | |
63 server { | |
64 listen 127.0.0.1:8081 sndbuf=64k; | |
65 server_name localhost; | |
66 | |
67 location / { } | |
68 } | |
69 } | |
70 | |
71 EOF | |
72 | |
73 $t->write_file('openssl.conf', <<EOF); | |
74 [ req ] | |
75 default_bits = 2048 | |
76 encrypt_key = no | |
77 distinguished_name = req_distinguished_name | |
78 [ req_distinguished_name ] | |
79 EOF | |
80 | |
81 my $d = $t->testdir(); | |
82 | |
83 foreach my $name ('localhost') { | |
84 system('openssl req -x509 -new ' | |
85 . "-config '$d/openssl.conf' -subj '/CN=$name/' " | |
86 . "-out '$d/$name.crt' -keyout '$d/$name.key' " | |
87 . ">>$d/openssl.out 2>&1") == 0 | |
88 or die "Can't create certificate for $name: $!\n"; | |
89 } | |
90 | |
91 $t->write_file('tbig.html', | |
92 join('', map { sprintf "XX%06dXX", $_ } (1 .. 500000))); | |
93 | |
94 open OLDERR, ">&", \*STDERR; close STDERR; | |
95 $t->run(); | |
96 open STDERR, ">&", \*OLDERR; | |
97 | |
98 plan(skip_all => 'no ALPN/NPN negotiation') unless defined getconn(port(0)); | |
99 $t->plan(1); | |
100 | |
101 ############################################################################### | |
102 | |
103 # client cancels stream with a cacheable request sent to upstream causing alert | |
104 | |
105 my $s = getconn(port(0)); | |
106 ok($s, 'ssl connection'); | |
107 | |
108 my $sid = $s->new_stream(); | |
109 $s->h2_rst($sid, 8); | |
110 | |
111 # large response may stuck in SSL buffer and won't be sent producing alert | |
112 | |
113 my $s2 = getconn(port(0)); | |
114 $sid = $s2->new_stream({ path => '/tbig.html' }); | |
115 $s2->h2_window(2**30, $sid); | |
116 $s2->h2_window(2**30); | |
117 | |
118 select undef, undef, undef, 0.2; | |
119 | |
120 $t->stop(); | |
121 | |
122 ############################################################################### | |
123 | |
124 sub getconn { | |
125 my ($port) = @_; | |
126 my $s; | |
127 | |
128 eval { | |
129 IO::Socket::SSL->can_alpn() or die; | |
130 $s = Test::Nginx::HTTP2->new($port, SSL => 1, alpn => 'h2'); | |
131 }; | |
132 | |
133 return $s if defined $s; | |
134 | |
135 eval { | |
136 IO::Socket::SSL->can_npn() or die; | |
137 $s = Test::Nginx::HTTP2->new($port, SSL => 1, npn => 'h2'); | |
138 }; | |
139 | |
140 return $s; | |
141 } | |
142 | |
143 ############################################################################### |