Mercurial > hg > nginx-tests
annotate h3_server_name.t @ 1894:cd66d6f50ec1
Tests: converted h3_server_name.t to use "socket_ssl_alpn".
See cdcd75657e52 for further details.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Wed, 24 May 2023 19:10:58 +0400 |
parents | 3619dcc8ba6d |
children | acd68670b064 |
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 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
|
28 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
|
29 |
1894
cd66d6f50ec1
Tests: converted h3_server_name.t to use "socket_ssl_alpn".
Sergey Kandaurov <pluknet@nginx.com>
parents:
1882
diff
changeset
|
30 my $t = Test::Nginx->new() |
cd66d6f50ec1
Tests: converted h3_server_name.t to use "socket_ssl_alpn".
Sergey Kandaurov <pluknet@nginx.com>
parents:
1882
diff
changeset
|
31 ->has(qw/http http_ssl http_v2 http_v3 rewrite socket_ssl_alpn/) |
1882
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 ->has_daemon('openssl')->plan(6); |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 $t->write_file_expand('nginx.conf', <<'EOF'); |
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 %%TEST_GLOBALS%% |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 daemon off; |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 events { |
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 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 http { |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 %%TEST_GLOBALS_HTTP%% |
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 ssl_certificate_key localhost.key; |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 ssl_certificate localhost.crt; |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 server { |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 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
|
51 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
|
52 server_name ~^(?P<name>.+)\.example\.com$; |
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 location / { |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 return 200 $name; |
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 } |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 } |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 EOF |
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 $t->write_file('openssl.conf', <<EOF); |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 [ req ] |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 default_bits = 2048 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 encrypt_key = no |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 distinguished_name = req_distinguished_name |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 [ req_distinguished_name ] |
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 my $d = $t->testdir(); |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 foreach my $name ('localhost') { |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 system('openssl req -x509 -new ' |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 . "-config $d/openssl.conf -subj /CN=$name/ " |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 . "-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
|
76 . ">>$d/openssl.out 2>&1") == 0 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 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
|
78 } |
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 $t->run(); |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 ############################################################################### |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 # 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
|
85 # other protocols are provided for convenience |
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 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
|
88 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
|
89 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
90 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
|
91 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
|
92 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
93 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
|
94 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
|
95 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
96 ############################################################################### |
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 sub get1 { |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
99 my ($host, $sni) = @_; |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
100 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
|
101 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
|
102 GET / HTTP/1.1 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
103 Host: $host |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
104 Connection: close |
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 EOF |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
107 return $1; |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
108 } |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
109 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
110 sub get2 { |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
111 my ($host, $sni) = @_; |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
112 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
|
113 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
|
114 my $sid = $s->new_stream({ host => $host }); |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
115 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
|
116 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
117 my ($frame) = grep { $_->{type} eq "DATA" } @$frames; |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
118 return $frame->{data}; |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
119 } |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
120 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
121 sub get3 { |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
122 my ($host, $sni) = @_; |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
123 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
|
124 my $sid = $s->new_stream({ host => $host }); |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
125 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
|
126 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
127 my ($frame) = grep { $_->{type} eq "DATA" } @$frames; |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
128 return $frame->{data}; |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
129 } |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
130 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
131 sub get_ssl_socket { |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
132 my (%extra) = @_; |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
133 my $s; |
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 eval { |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
136 local $SIG{ALRM} = sub { die "timeout\n" }; |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
137 local $SIG{PIPE} = sub { die "sigpipe\n" }; |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
138 alarm(8); |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
139 $s = IO::Socket::SSL->new( |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
140 Proto => 'tcp', |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
141 PeerAddr => '127.0.0.1', |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
142 PeerPort => port(8080), |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
143 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
|
144 SSL_hostname => $extra{sni}, |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
145 SSL_alpn_protocols => $extra{alpn}, |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
146 SSL_error_trap => sub { die $_[1] } |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
147 ); |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
148 alarm(0); |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
149 }; |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
150 alarm(0); |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
151 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
152 if ($@) { |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
153 log_in("died: $@"); |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
154 return undef; |
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 |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
157 return $s; |
3619dcc8ba6d
Tests: HTTP/3 tests with server_name captures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
158 } |
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 ############################################################################### |