Mercurial > hg > nginx-tests
comparison h3_proxy.t @ 1880:03cebb996b5b
Tests: added HTTP/3 test with upstream check broken connection.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Thu, 12 Jan 2023 20:53:51 +0400 |
parents | |
children | 8b74936ff2ac |
comparison
equal
deleted
inserted
replaced
1879:12d950e1165c | 1880:03cebb996b5b |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 # (C) Sergey Kandaurov | |
4 # (C) Nginx, Inc. | |
5 | |
6 # Tests for HTTP/3 with proxy module. | |
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::HTTP3; | |
20 | |
21 ############################################################################### | |
22 | |
23 select STDERR; $| = 1; | |
24 select STDOUT; $| = 1; | |
25 | |
26 eval { require Crypt::Misc; die if $Crypt::Misc::VERSION < 0.067; }; | |
27 plan(skip_all => 'CryptX version >= 0.067 required') if $@; | |
28 | |
29 my $t = Test::Nginx->new()->has(qw/http http_v3 proxy/) | |
30 ->has_daemon('openssl')->plan(3) | |
31 ->write_file_expand('nginx.conf', <<'EOF'); | |
32 | |
33 %%TEST_GLOBALS%% | |
34 | |
35 daemon off; | |
36 | |
37 events { | |
38 } | |
39 | |
40 http { | |
41 %%TEST_GLOBALS_HTTP%% | |
42 | |
43 ssl_certificate_key localhost.key; | |
44 ssl_certificate localhost.crt; | |
45 | |
46 log_format test $uri:$status:$request_completion; | |
47 | |
48 server { | |
49 listen 127.0.0.1:%%PORT_8980_UDP%% quic; | |
50 listen 127.0.0.1:8081; | |
51 server_name localhost; | |
52 | |
53 access_log %%TESTDIR%%/test.log test; | |
54 | |
55 location / { | |
56 proxy_pass http://127.0.0.1:8081/stub; | |
57 } | |
58 | |
59 location /stub { | |
60 limit_rate 100; | |
61 } | |
62 } | |
63 } | |
64 | |
65 EOF | |
66 | |
67 $t->write_file('openssl.conf', <<EOF); | |
68 [ req ] | |
69 default_bits = 2048 | |
70 encrypt_key = no | |
71 distinguished_name = req_distinguished_name | |
72 [ req_distinguished_name ] | |
73 EOF | |
74 | |
75 my $d = $t->testdir(); | |
76 | |
77 foreach my $name ('localhost') { | |
78 system('openssl req -x509 -new ' | |
79 . "-config $d/openssl.conf -subj /CN=$name/ " | |
80 . "-out $d/$name.crt -keyout $d/$name.key " | |
81 . ">>$d/openssl.out 2>&1") == 0 | |
82 or die "Can't create certificate for $name: $!\n"; | |
83 } | |
84 | |
85 $t->write_file('stub', 'SEE-THIS' x 10); | |
86 $t->run(); | |
87 | |
88 ############################################################################### | |
89 | |
90 my ($s, $sid, $frames, $frame); | |
91 | |
92 # upstream check broken connection | |
93 # ensure that STOP_SENDING results in write error, checked in a posted event | |
94 | |
95 $s = Test::Nginx::HTTP3->new(); | |
96 $sid = $s->new_stream(); | |
97 | |
98 select undef, undef, undef, 0.1; | |
99 $s->stop_sending($sid, 0x010c); | |
100 $frames = $s->read(all => [{ type => 'RESET_STREAM' }]); | |
101 | |
102 ($frame) = grep { $_->{type} eq "RESET_STREAM" } @$frames; | |
103 ok($frame, 'RESET_STREAM received'); | |
104 | |
105 $t->stop(); | |
106 | |
107 my $log = $t->read_file('test.log'); | |
108 like($log, qr|^/:499|, 'client reset connection'); | |
109 unlike($log, qr|^/stub:200:OK|, 'backend request incomplete'); | |
110 | |
111 ############################################################################### |