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