Mercurial > hg > nginx-tests
comparison h2_error_page.t @ 1855:b3bbde3f806d
Tests: HTTP/2 tests with error_page and return.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Thu, 11 May 2023 15:29:41 +0400 |
parents | |
children | 236d038dc04a |
comparison
equal
deleted
inserted
replaced
1854:0152ce2de27f | 1855:b3bbde3f806d |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 # (C) Sergey Kandaurov | |
4 # (C) Nginx, Inc. | |
5 | |
6 # Tests for HTTP/2 protocol with error_page directive. | |
7 | |
8 ############################################################################### | |
9 | |
10 use warnings; | |
11 use strict; | |
12 | |
13 use Test::More; | |
14 | |
15 BEGIN { use FindBin; chdir($FindBin::Bin); } | |
16 | |
17 use lib 'lib'; | |
18 use Test::Nginx; | |
19 use Test::Nginx::HTTP2; | |
20 | |
21 ############################################################################### | |
22 | |
23 select STDERR; $| = 1; | |
24 select STDOUT; $| = 1; | |
25 | |
26 my $t = Test::Nginx->new()->has(qw/http http_v2 rewrite/)->plan(2) | |
27 ->write_file_expand('nginx.conf', <<'EOF'); | |
28 | |
29 %%TEST_GLOBALS%% | |
30 | |
31 daemon off; | |
32 | |
33 events { | |
34 } | |
35 | |
36 http { | |
37 %%TEST_GLOBALS_HTTP%% | |
38 | |
39 server { | |
40 listen 127.0.0.1:8080 http2; | |
41 server_name localhost; | |
42 | |
43 lingering_close off; | |
44 | |
45 error_page 400 = /close; | |
46 | |
47 location / { } | |
48 | |
49 location /close { | |
50 return 444; | |
51 } | |
52 } | |
53 } | |
54 | |
55 EOF | |
56 | |
57 $t->run(); | |
58 | |
59 ############################################################################### | |
60 | |
61 # tests for socket leaks with "return 444" in error_page | |
62 | |
63 my ($sid, $frames, $frame); | |
64 | |
65 # make sure there is no socket leak when the request is rejected | |
66 # due to missing mandatory ":scheme" pseudo-header and "return 444;" | |
67 # is used in error_page 400 (ticket #274) | |
68 | |
69 my $s1 = Test::Nginx::HTTP2->new(); | |
70 $sid = $s1->new_stream({ headers => [ | |
71 { name => ':method', value => 'GET' }, | |
72 { name => ':path', value => '/' }, | |
73 { name => ':authority', value => 'localhost' }]}); | |
74 $frames = $s1->read(all => [{ type => 'RST_STREAM' }]); | |
75 | |
76 ($frame) = grep { $_->{type} eq "RST_STREAM" } @$frames; | |
77 is($frame->{sid}, $sid, 'error 400 return 444 - missing header'); | |
78 | |
79 # make sure there is no socket leak when the request is rejected | |
80 # due to invalid method with lower-case letters and "return 444;" | |
81 # is used in error_page 400 (ticket #2455) | |
82 | |
83 my $s2 = Test::Nginx::HTTP2->new(); | |
84 $sid = $s2->new_stream({ method => 'foo' }); | |
85 $frames = $s2->read(all => [{ type => 'RST_STREAM' }]); | |
86 | |
87 ($frame) = grep { $_->{type} eq "RST_STREAM" } @$frames; | |
88 is($frame->{sid}, $sid, 'error 400 return 444 - invalid header'); | |
89 | |
90 # while keeping $s1 and $s2, stop nginx; this should result in | |
91 # "open socket ... left in connection ..." alerts if any of these | |
92 # sockets are still open | |
93 | |
94 $t->stop(); | |
95 | |
96 ############################################################################### |