Mercurial > hg > nginx-tests
comparison h3_limit_conn.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 | |
children | 8b74936ff2ac |
comparison
equal
deleted
inserted
replaced
1889:8303f3633f65 | 1890:e99a7790ec61 |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 # (C) Sergey Kandaurov | |
4 # (C) Nginx, Inc. | |
5 | |
6 # Tests for HTTP/3 protocol with limit_conn. | |
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 limit_conn proxy/) | |
30 ->has_daemon('openssl')->plan(2); | |
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 ssl_certificate_key localhost.key; | |
45 ssl_certificate localhost.crt; | |
46 | |
47 limit_conn_zone $binary_remote_addr zone=conn:1m; | |
48 | |
49 server { | |
50 listen 127.0.0.1:%%PORT_8980_UDP%% quic; | |
51 listen 127.0.0.1:8080; | |
52 server_name localhost; | |
53 | |
54 location / { | |
55 limit_conn conn 1; | |
56 proxy_pass http://127.0.0.1:8080/stub; | |
57 } | |
58 | |
59 location /stub { | |
60 limit_rate 200; | |
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', 'x' x 200); | |
86 $t->run(); | |
87 | |
88 ############################################################################### | |
89 | |
90 my $s = Test::Nginx::HTTP3->new(); | |
91 my $sid = $s->new_stream(); | |
92 my $sid2 = $s->new_stream(); | |
93 my $frames = $s->read(all => [ | |
94 { sid => $sid, fin => 1 }, | |
95 { sid => $sid2, fin => 1 }]); | |
96 | |
97 my ($frame) = grep { $_->{type} eq "HEADERS" && $_->{sid} == $sid } @$frames; | |
98 is($frame->{headers}->{':status'}, 200, 'limit_conn first stream'); | |
99 | |
100 ($frame) = grep { $_->{type} eq "HEADERS" && $_->{sid} == $sid2 } @$frames; | |
101 is($frame->{headers}->{':status'}, 503, 'limit_conn rejected'); | |
102 | |
103 ############################################################################### |