Mercurial > hg > nginx-tests
annotate h3_trailers.t @ 1990:85d88cd5091c
Tests: SSI include stub tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 04 Jul 2024 17:42:55 +0300 |
parents | 8b74936ff2ac |
children |
rev | line source |
---|---|
1891
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for HTTP/3 trailers. |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 use Test::Nginx::HTTP3; |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 ############################################################################### |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 select STDERR; $| = 1; |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 select STDOUT; $| = 1; |
acbdc4dd7508
Tests: HTTP/3 add_trailer 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:
1891
diff
changeset
|
26 my $t = Test::Nginx->new()->has(qw/http http_v3 cryptx/) |
1891
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 ->has_daemon('openssl')->plan(8); |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 $t->write_file_expand('nginx.conf', <<'EOF'); |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 %%TEST_GLOBALS%% |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 daemon off; |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 events { |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 } |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 http { |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 %%TEST_GLOBALS_HTTP%% |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 ssl_certificate_key localhost.key; |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 ssl_certificate localhost.crt; |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 server { |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 listen 127.0.0.1:%%PORT_8980_UDP%% quic; |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 server_name localhost; |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 location / { |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 add_trailer X-Var $host; |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 } |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 } |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 } |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 EOF |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 $t->write_file('openssl.conf', <<EOF); |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 [ req ] |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 default_bits = 2048 |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 encrypt_key = no |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 distinguished_name = req_distinguished_name |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 [ req_distinguished_name ] |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 EOF |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 my $d = $t->testdir(); |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 foreach my $name ('localhost') { |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 system('openssl req -x509 -new ' |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 . "-config $d/openssl.conf -subj /CN=$name/ " |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 . "-out $d/$name.crt -keyout $d/$name.key " |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 . ">>$d/openssl.out 2>&1") == 0 |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 or die "Can't create certificate for $name: $!\n"; |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 } |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 $t->write_file('index.html', 'SEE-THIS'); |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 $t->write_file('empty', ''); |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 $t->run(); |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 ############################################################################### |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 my ($s, $sid, $frames, $frame); |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 $s = Test::Nginx::HTTP3->new(); |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 $sid = $s->new_stream({ path => '/' }); |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 @$frames = grep { $_->{type} =~ "HEADERS|DATA" } @$frames; |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 is(@$frames, 3, 'frames'); |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 $frame = shift @$frames; |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
90 is($frame->{headers}->{':status'}, 200, 'header'); |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
91 is($frame->{headers}->{'x-var'}, undef, 'header not trailer'); |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
92 |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
93 $frame = shift @$frames; |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
94 is($frame->{data}, 'SEE-THIS', 'data'); |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
95 |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
96 $frame = shift @$frames; |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
97 is($frame->{headers}->{'x-var'}, 'localhost', 'trailer'); |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
98 |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
99 # with zero content-length |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
100 |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
101 $s = Test::Nginx::HTTP3->new(); |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
102 $sid = $s->new_stream({ path => '/empty' }); |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
103 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
104 @$frames = grep { $_->{type} =~ "HEADERS|DATA" } @$frames; |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
105 |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
106 is(@$frames, 2, 'no data - frames'); |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
107 |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
108 $frame = shift @$frames; |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
109 is($frame->{headers}->{':status'}, 200, 'no data - header'); |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
110 |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
111 $frame = shift @$frames; |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
112 is($frame->{headers}->{'x-var'}, 'localhost', 'no data - trailer'); |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
113 |
acbdc4dd7508
Tests: HTTP/3 add_trailer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
114 ############################################################################### |