Mercurial > hg > nginx-tests
annotate h3_max_headers.t @ 1990:85d88cd5091c
Tests: SSI include stub tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 04 Jul 2024 17:42:55 +0300 |
parents | 2d58bb10ff5d |
children |
rev | line source |
---|---|
1979
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
2 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
3 # (C) Maxim Dounin |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
4 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
5 # Tests for max_headers directive, HTTP/3. |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
6 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
7 ############################################################################### |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
8 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
9 use warnings; |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
10 use strict; |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
11 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
12 use Test::More; |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
13 use Socket qw/ CRLF /; |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
14 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
16 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
17 use lib 'lib'; |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
18 use Test::Nginx; |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
19 use Test::Nginx::HTTP3; |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
20 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
21 ############################################################################### |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
22 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
23 select STDERR; $| = 1; |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
24 select STDOUT; $| = 1; |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
25 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
26 my $t = Test::Nginx->new()->has(qw/http http_v3 rewrite cryptx/); |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
27 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
28 $t->write_file_expand('nginx.conf', <<'EOF'); |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
29 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
30 %%TEST_GLOBALS%% |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
31 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
32 daemon off; |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
33 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
34 events { |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
35 } |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
36 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
37 http { |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
38 %%TEST_GLOBALS_HTTP%% |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
39 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
40 ssl_certificate localhost.crt; |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
41 ssl_certificate_key localhost.key; |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
42 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
43 server { |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
44 listen 127.0.0.1:%%PORT_8980_UDP%% quic; |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
45 server_name localhost; |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
46 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
47 max_headers 5; |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
48 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
49 location / { |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
50 return 204; |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
51 } |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
52 } |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
53 } |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
54 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
55 EOF |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
56 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
57 $t->write_file('openssl.conf', <<EOF); |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
58 [ req ] |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
59 default_bits = 2048 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
60 encrypt_key = no |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
61 distinguished_name = req_distinguished_name |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
62 [ req_distinguished_name ] |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
63 EOF |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
64 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
65 my $d = $t->testdir(); |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
66 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
67 foreach my $name ('localhost') { |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
68 system('openssl req -x509 -new ' |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
69 . "-config $d/openssl.conf -subj /CN=$name/ " |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
70 . "-out $d/$name.crt -keyout $d/$name.key " |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
71 . ">>$d/openssl.out 2>&1") == 0 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
72 or die "Can't create certificate for $name: $!\n"; |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
73 } |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
74 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
75 $t->try_run('no max_headers')->plan(3); |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
76 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
77 ############################################################################### |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
78 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
79 like(get('/'), qr/ 204/, 'two headers'); |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
80 like(get('/', ('Foo: bar') x 3), qr/ 204/, 'five headers'); |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
81 like(get('/', ('Foo: bar') x 4), qr/ 400/, 'six headers rejected'); |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
82 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
83 ############################################################################### |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
84 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
85 sub get { |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
86 my ($url, @headers) = @_; |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
87 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
88 my $s = Test::Nginx::HTTP3->new(); |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
89 my $sid = $s->new_stream({ |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
90 headers => [ |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
91 { name => ':method', value => 'GET' }, |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
92 { name => ':scheme', value => 'http' }, |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
93 { name => ':path', value => $url }, |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
94 { name => ':authority', value => 'localhost' }, |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
95 { name => 'foo', value => 'bar' }, |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
96 { name => 'foo', value => 'bar' }, |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
97 map { |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
98 my ($n, $v) = split /:/; |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
99 { name => lc $n, value => $v }; |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
100 } @headers |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
101 ] |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
102 }); |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
103 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
104 my $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
105 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
106 my ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
107 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
108 return join("\n", map { "$_: " . $frame->{headers}->{$_}; } |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
109 keys %{$frame->{headers}}); |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
110 } |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
111 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
112 ############################################################################### |