Mercurial > hg > nginx-tests
annotate h3_limit_conn.t @ 1999:15f538440a77 default tip
Tests: adjusted proxy_cache_use_stale.t cache validity.
At least the "s-w-r - updating stale" test sometimes fails on slow
hosts due to "stale-while-revalidate=4" being not enough, so the request
returns with the EXPIRED cache status instead of STALE.
Fix is to use larger "stale-while-revalidate=" times where it is not
significant.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Fri, 09 Aug 2024 18:37:25 +0300 |
parents | 8b74936ff2ac |
children |
rev | line source |
---|---|
1890
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for HTTP/3 protocol with limit_conn. |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 use Test::Nginx::HTTP3; |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 ############################################################################### |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 select STDERR; $| = 1; |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 select STDOUT; $| = 1; |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 |
1896
8b74936ff2ac
Tests: added has_feature() test for CryptX.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1890
diff
changeset
|
26 my $t = Test::Nginx->new()->has(qw/http http_v3 limit_conn proxy cryptx/) |
1890
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 ->has_daemon('openssl')->plan(2); |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 $t->write_file_expand('nginx.conf', <<'EOF'); |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 %%TEST_GLOBALS%% |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 daemon off; |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 events { |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 } |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 http { |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 %%TEST_GLOBALS_HTTP%% |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 ssl_certificate_key localhost.key; |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 ssl_certificate localhost.crt; |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 limit_conn_zone $binary_remote_addr zone=conn:1m; |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 server { |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 listen 127.0.0.1:%%PORT_8980_UDP%% quic; |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 listen 127.0.0.1:8080; |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 server_name localhost; |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 location / { |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 limit_conn conn 1; |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 proxy_pass http://127.0.0.1:8080/stub; |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 } |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 location /stub { |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 limit_rate 200; |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 } |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 } |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 } |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 EOF |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 $t->write_file('openssl.conf', <<EOF); |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 [ req ] |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 default_bits = 2048 |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 encrypt_key = no |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 distinguished_name = req_distinguished_name |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 [ req_distinguished_name ] |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 EOF |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 my $d = $t->testdir(); |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 foreach my $name ('localhost') { |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 system('openssl req -x509 -new ' |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 . "-config $d/openssl.conf -subj /CN=$name/ " |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 . "-out $d/$name.crt -keyout $d/$name.key " |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 . ">>$d/openssl.out 2>&1") == 0 |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 or die "Can't create certificate for $name: $!\n"; |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 } |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 $t->write_file('stub', 'x' x 200); |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 $t->run(); |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 ############################################################################### |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 my $s = Test::Nginx::HTTP3->new(); |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 my $sid = $s->new_stream(); |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 my $sid2 = $s->new_stream(); |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
90 my $frames = $s->read(all => [ |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
91 { sid => $sid, fin => 1 }, |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
92 { sid => $sid2, fin => 1 }]); |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
93 |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
94 my ($frame) = grep { $_->{type} eq "HEADERS" && $_->{sid} == $sid } @$frames; |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
95 is($frame->{headers}->{':status'}, 200, 'limit_conn first stream'); |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
96 |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
97 ($frame) = grep { $_->{type} eq "HEADERS" && $_->{sid} == $sid2 } @$frames; |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
98 is($frame->{headers}->{':status'}, 503, 'limit_conn rejected'); |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
99 |
e99a7790ec61
Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
100 ############################################################################### |