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