annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
26 eval { require Crypt::Misc; die if $Crypt::Misc::VERSION < 0.067; };
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
27 plan(skip_all => 'CryptX version >= 0.067 required') if $@;
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 my $t = Test::Nginx->new()->has(qw/http http_v3 limit_conn proxy/)
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
30 ->has_daemon('openssl')->plan(2);
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
31
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
32 $t->write_file_expand('nginx.conf', <<'EOF');
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
33
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
34 %%TEST_GLOBALS%%
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
35
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
36 daemon off;
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 events {
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
39 }
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 http {
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
42 %%TEST_GLOBALS_HTTP%%
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 ssl_certificate_key localhost.key;
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
45 ssl_certificate localhost.crt;
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
46
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
47 limit_conn_zone $binary_remote_addr zone=conn:1m;
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
48
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
49 server {
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
50 listen 127.0.0.1:%%PORT_8980_UDP%% quic;
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
51 listen 127.0.0.1:8080;
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
52 server_name localhost;
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
53
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
54 location / {
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
55 limit_conn conn 1;
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
56 proxy_pass http://127.0.0.1:8080/stub;
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
57 }
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 location /stub {
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
60 limit_rate 200;
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 }
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
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
65 EOF
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
66
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
67 $t->write_file('openssl.conf', <<EOF);
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
68 [ req ]
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
69 default_bits = 2048
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
70 encrypt_key = no
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
71 distinguished_name = req_distinguished_name
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
72 [ req_distinguished_name ]
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
73 EOF
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
74
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
75 my $d = $t->testdir();
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
76
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
77 foreach my $name ('localhost') {
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
78 system('openssl req -x509 -new '
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
79 . "-config $d/openssl.conf -subj /CN=$name/ "
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
80 . "-out $d/$name.crt -keyout $d/$name.key "
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
81 . ">>$d/openssl.out 2>&1") == 0
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
82 or die "Can't create certificate for $name: $!\n";
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
83 }
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 $t->write_file('stub', 'x' x 200);
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
86 $t->run();
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
87
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
88 ###############################################################################
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
89
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
90 my $s = Test::Nginx::HTTP3->new();
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
91 my $sid = $s->new_stream();
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
92 my $sid2 = $s->new_stream();
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
93 my $frames = $s->read(all => [
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
94 { sid => $sid, fin => 1 },
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
95 { sid => $sid2, fin => 1 }]);
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 my ($frame) = grep { $_->{type} eq "HEADERS" && $_->{sid} == $sid } @$frames;
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
98 is($frame->{headers}->{':status'}, 200, 'limit_conn first stream');
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 ($frame) = grep { $_->{type} eq "HEADERS" && $_->{sid} == $sid2 } @$frames;
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
101 is($frame->{headers}->{':status'}, 503, 'limit_conn rejected');
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
102
e99a7790ec61 Tests: HTTP/3 limit_conn tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
103 ###############################################################################