Mercurial > hg > nginx-tests
annotate h3_server_name.t @ 1890:e99a7790ec61
Tests: HTTP/3 limit_conn tests.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Tue, 09 May 2023 19:49:41 +0400 |
parents | 3619dcc8ba6d |
children | cd66d6f50ec1 |
rev | line source |
---|---|
1882
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for HTTP/3 protocol, SNI TLS extension and regex in server_name. |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 use Test::Nginx::HTTP2; |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 use Test::Nginx::HTTP3; |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 ############################################################################### |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 select STDERR; $| = 1; |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 select STDOUT; $| = 1; |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 eval { require IO::Socket::SSL; die if $IO::Socket::SSL::VERSION < 1.56; }; |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 plan(skip_all => 'IO::Socket::SSL version >= 1.56 required') if $@; |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 eval { IO::Socket::SSL->can_client_sni() or die; }; |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 plan(skip_all => 'IO::Socket::SSL with OpenSSL SNI support required') if $@; |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 eval { IO::Socket::SSL->can_alpn() or die; }; |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 plan(skip_all => 'IO::Socket::SSL with OpenSSL ALPN support required') if $@; |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 eval { require Crypt::Misc; die if $Crypt::Misc::VERSION < 0.067; }; |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 plan(skip_all => 'CryptX version >= 0.067 required') if $@; |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 my $t = Test::Nginx->new()->has(qw/http http_ssl http_v2 http_v3 rewrite/) |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 ->has_daemon('openssl')->plan(6); |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 $t->write_file_expand('nginx.conf', <<'EOF'); |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 %%TEST_GLOBALS%% |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 daemon off; |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 events { |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 } |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 http { |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 %%TEST_GLOBALS_HTTP%% |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 ssl_certificate_key localhost.key; |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 ssl_certificate localhost.crt; |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 server { |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 listen 127.0.0.1:8080 ssl http2; |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 listen 127.0.0.1:%%PORT_8980_UDP%% quic; |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 server_name ~^(?P<name>.+)\.example\.com$; |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 location / { |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 return 200 $name; |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 } |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 } |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 } |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 EOF |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 $t->write_file('openssl.conf', <<EOF); |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 [ req ] |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 default_bits = 2048 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 encrypt_key = no |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 distinguished_name = req_distinguished_name |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 [ req_distinguished_name ] |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 EOF |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 my $d = $t->testdir(); |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 foreach my $name ('localhost') { |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 system('openssl req -x509 -new ' |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 . "-config $d/openssl.conf -subj /CN=$name/ " |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 . "-out $d/$name.crt -keyout $d/$name.key " |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 . ">>$d/openssl.out 2>&1") == 0 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 or die "Can't create certificate for $name: $!\n"; |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 } |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 $t->run(); |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
90 ############################################################################### |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
91 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
92 # ssl_servername_regex wasn't inherited from QUIC connection, |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
93 # other protocols are provided for convenience |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
94 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
95 is(get1('test.example.com'), 'test', 'http1 - sni match'); |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
96 is(get1('test.example.com', 'localhost'), 'test', 'http1 - sni not found'); |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
97 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
98 is(get2('test.example.com'), 'test', 'http2 - sni match'); |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
99 is(get2('test.example.com', 'localhost'), 'test', 'http2 - sni not found'); |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
100 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
101 is(get3('test.example.com'), 'test', 'http3 - sni match'); |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
102 is(get3('test.example.com', 'localhost'), 'test', 'http3 - sni not found'); |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
103 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
104 ############################################################################### |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
105 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
106 sub get1 { |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
107 my ($host, $sni) = @_; |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
108 my $s = get_ssl_socket(sni => $sni || $host, alpn => ['http/1.1']); |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
109 http(<<EOF, socket => $s) =~ /.*?\x0d\x0a?\x0d\x0a?(.*)/ms; |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
110 GET / HTTP/1.1 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
111 Host: $host |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
112 Connection: close |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
113 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
114 EOF |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
115 return $1; |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
116 } |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
117 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
118 sub get2 { |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
119 my ($host, $sni) = @_; |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
120 my $sock = get_ssl_socket(sni => $sni || $host, alpn => ['h2']); |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
121 my $s = Test::Nginx::HTTP2->new(undef, socket => $sock); |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
122 my $sid = $s->new_stream({ host => $host }); |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
123 my $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
124 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
125 my ($frame) = grep { $_->{type} eq "DATA" } @$frames; |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
126 return $frame->{data}; |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
127 } |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
128 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
129 sub get3 { |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
130 my ($host, $sni) = @_; |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
131 my $s = Test::Nginx::HTTP3->new(8980, sni => $sni || $host); |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
132 my $sid = $s->new_stream({ host => $host }); |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
133 my $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
134 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
135 my ($frame) = grep { $_->{type} eq "DATA" } @$frames; |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
136 return $frame->{data}; |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
137 } |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
138 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
139 sub get_ssl_socket { |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
140 my (%extra) = @_; |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
141 my $s; |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
142 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
143 eval { |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
144 local $SIG{ALRM} = sub { die "timeout\n" }; |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
145 local $SIG{PIPE} = sub { die "sigpipe\n" }; |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
146 alarm(8); |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
147 $s = IO::Socket::SSL->new( |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
148 Proto => 'tcp', |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
149 PeerAddr => '127.0.0.1', |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
150 PeerPort => port(8080), |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
151 SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE(), |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
152 SSL_hostname => $extra{sni}, |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
153 SSL_alpn_protocols => $extra{alpn}, |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
154 SSL_error_trap => sub { die $_[1] } |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
155 ); |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
156 alarm(0); |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
157 }; |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
158 alarm(0); |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
159 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
160 if ($@) { |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
161 log_in("died: $@"); |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
162 return undef; |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
163 } |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
164 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
165 return $s; |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
166 } |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
167 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
168 ############################################################################### |