annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
986
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1 #!/usr/bin/perl
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
2
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
3 # (C) Sergey Kandaurov
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
4 # (C) Nginx, Inc.
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
5
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
6 # Tests for HTTP/2 protocol with ssl.
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
7
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
8 ###############################################################################
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
9
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
10 use warnings;
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
11 use strict;
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
12
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
13 use Test::More;
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
14
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
15 BEGIN { use FindBin; chdir($FindBin::Bin); }
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
16
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
17 use lib 'lib';
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
18 use Test::Nginx;
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
19 use Test::Nginx::HTTP2;
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
20
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
21 ###############################################################################
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
22
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
23 select STDERR; $| = 1;
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
24 select STDOUT; $| = 1;
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
25
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
26 eval { require IO::Socket::SSL; };
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
27 plan(skip_all => 'IO::Socket::SSL not installed') if $@;
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
28
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
29 my $t = Test::Nginx->new()->has(qw/http http_ssl http_v2/)
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
30 ->has_daemon('openssl')->plan(1);
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
31
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
32 $t->write_file_expand('nginx.conf', <<'EOF');
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
33
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
34 %%TEST_GLOBALS%%
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
35
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
36 daemon off;
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
37
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
38 events {
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
39 }
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
40
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
41 http {
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
42 %%TEST_GLOBALS_HTTP%%
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
43
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
44 server {
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
45 listen 127.0.0.1:8080 http2 ssl;
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
46 server_name localhost;
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
47
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
48 ssl_certificate_key localhost.key;
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
49 ssl_certificate localhost.crt;
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
50
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
51 location / { }
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
52 }
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
53 }
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
54
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
55 EOF
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
56
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
57 $t->write_file('openssl.conf', <<EOF);
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
58 [ req ]
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
59 default_bits = 2048
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
60 encrypt_key = no
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
61 distinguished_name = req_distinguished_name
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
62 [ req_distinguished_name ]
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
63 EOF
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
64
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
65 my $d = $t->testdir();
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
66
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
67 foreach my $name ('localhost') {
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
68 system('openssl req -x509 -new '
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
69 . "-config '$d/openssl.conf' -subj '/CN=$name/' "
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
70 . "-out '$d/$name.crt' -keyout '$d/$name.key' "
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
71 . ">>$d/openssl.out 2>&1") == 0
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
72 or die "Can't create certificate for $name: $!\n";
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
73 }
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
74
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
75 $t->write_file('tbig.html',
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
76 join('', map { sprintf "XX%06dXX", $_ } (1 .. 500000)));
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
77
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
78 open OLDERR, ">&", \*STDERR; close STDERR;
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
79 $t->run();
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
80 open STDERR, ">&", \*OLDERR;
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
81
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
82 ###############################################################################
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
83
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
84 # client cancels 2nd stream after HEADERS has been created
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
85 # while some unsent data was left in the SSL buffer
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
86 # HEADERS frame may stuck in SSL buffer and won't be sent producing alert
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
87
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
88 SKIP: {
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
89 my $s = getconn(port(0));
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
90 skip 'OpenSSL ALPN/NPN support required', 1 unless defined $s;
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
91
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
92 ok($s, 'ssl connection');
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
93
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
94 $t->todo_alerts();
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
95
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
96 my $sid = $s->new_stream({ path => '/tbig.html' });
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
97
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
98 select undef, undef, undef, 0.2;
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
99 $s->h2_rst($sid, 8);
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
100
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
101 $sid = $s->new_stream({ path => '/tbig.html' });
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
102
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
103 select undef, undef, undef, 0.2;
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
104 $s->h2_rst($sid, 8);
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
105
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
106 $t->stop();
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
107
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
108 }
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
109
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
110 ###############################################################################
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
111
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
112 sub getconn {
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
113 my ($port) = @_;
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
114 my $s;
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
115
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
116 eval {
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
117 IO::Socket::SSL->can_alpn() or die;
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
118 $s = Test::Nginx::HTTP2->new($port, SSL => 1, alpn => 'h2');
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
119 };
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
120
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
121 return $s if defined $s;
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
122
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
123 eval {
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
124 IO::Socket::SSL->can_npn() or die;
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
125 $s = Test::Nginx::HTTP2->new($port, SSL => 1, npn => 'h2');
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
126 };
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
127
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
128 return $s;
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
129 }
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
130
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
131 ###############################################################################