Mercurial > hg > nginx-tests
comparison h2_ssl.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. | |
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/) | |
30 ->has_daemon('openssl')->plan(1); | |
31 | |
32 $t->write_file_expand('nginx.conf', <<'EOF'); | |
33 | |
34 %%TEST_GLOBALS%% | |
35 | |
36 daemon off; | |
37 | |
38 events { | |
39 } | |
40 | |
41 http { | |
42 %%TEST_GLOBALS_HTTP%% | |
43 | |
44 server { | |
45 listen 127.0.0.1:8080 http2 ssl; | |
46 server_name localhost; | |
47 | |
48 ssl_certificate_key localhost.key; | |
49 ssl_certificate localhost.crt; | |
50 | |
51 location / { } | |
52 } | |
53 } | |
54 | |
55 EOF | |
56 | |
57 $t->write_file('openssl.conf', <<EOF); | |
58 [ req ] | |
59 default_bits = 2048 | |
60 encrypt_key = no | |
61 distinguished_name = req_distinguished_name | |
62 [ req_distinguished_name ] | |
63 EOF | |
64 | |
65 my $d = $t->testdir(); | |
66 | |
67 foreach my $name ('localhost') { | |
68 system('openssl req -x509 -new ' | |
69 . "-config '$d/openssl.conf' -subj '/CN=$name/' " | |
70 . "-out '$d/$name.crt' -keyout '$d/$name.key' " | |
71 . ">>$d/openssl.out 2>&1") == 0 | |
72 or die "Can't create certificate for $name: $!\n"; | |
73 } | |
74 | |
75 $t->write_file('tbig.html', | |
76 join('', map { sprintf "XX%06dXX", $_ } (1 .. 500000))); | |
77 | |
78 open OLDERR, ">&", \*STDERR; close STDERR; | |
79 $t->run(); | |
80 open STDERR, ">&", \*OLDERR; | |
81 | |
82 ############################################################################### | |
83 | |
84 # client cancels 2nd stream after HEADERS has been created | |
85 # while some unsent data was left in the SSL buffer | |
86 # HEADERS frame may stuck in SSL buffer and won't be sent producing alert | |
87 | |
88 SKIP: { | |
89 my $s = getconn(port(0)); | |
90 skip 'OpenSSL ALPN/NPN support required', 1 unless defined $s; | |
91 | |
92 ok($s, 'ssl connection'); | |
93 | |
94 $t->todo_alerts(); | |
95 | |
96 my $sid = $s->new_stream({ path => '/tbig.html' }); | |
97 | |
98 select undef, undef, undef, 0.2; | |
99 $s->h2_rst($sid, 8); | |
100 | |
101 $sid = $s->new_stream({ path => '/tbig.html' }); | |
102 | |
103 select undef, undef, undef, 0.2; | |
104 $s->h2_rst($sid, 8); | |
105 | |
106 $t->stop(); | |
107 | |
108 } | |
109 | |
110 ############################################################################### | |
111 | |
112 sub getconn { | |
113 my ($port) = @_; | |
114 my $s; | |
115 | |
116 eval { | |
117 IO::Socket::SSL->can_alpn() or die; | |
118 $s = Test::Nginx::HTTP2->new($port, SSL => 1, alpn => 'h2'); | |
119 }; | |
120 | |
121 return $s if defined $s; | |
122 | |
123 eval { | |
124 IO::Socket::SSL->can_npn() or die; | |
125 $s = Test::Nginx::HTTP2->new($port, SSL => 1, npn => 'h2'); | |
126 }; | |
127 | |
128 return $s; | |
129 } | |
130 | |
131 ############################################################################### |