Mercurial > hg > nginx-tests
annotate h2_error_page.t @ 1982:fb25cbe9d4ec
Tests: explicit Valgrind support.
Valgrind logging is done to a separate file, as it is not able to
follow stderr redirection within nginx or append to a file without
corrupting it. Further, Valgrind logging seems to interfere with
error suppression in tests, and catches various startup errors and
warnings, so the log is additionally filtered.
Since startup under Valgrind can be really slow, timeout in waitforfile()
was changed to 10 seconds.
Prodded by Robert Mueller.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Fri, 31 May 2024 06:23:00 +0300 |
parents | 716d7500317d |
children | 11463d379570 |
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 |
1900
236d038dc04a
Tests: suppress "listen .. http2;" deprecation warnings.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1855
diff
changeset
|
57 # suppress deprecation warning |
236d038dc04a
Tests: suppress "listen .. http2;" deprecation warnings.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1855
diff
changeset
|
58 |
236d038dc04a
Tests: suppress "listen .. http2;" deprecation warnings.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1855
diff
changeset
|
59 open OLDERR, ">&", \*STDERR; close STDERR; |
1855
b3bbde3f806d
Tests: HTTP/2 tests with error_page and return.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 $t->run(); |
1900
236d038dc04a
Tests: suppress "listen .. http2;" deprecation warnings.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1855
diff
changeset
|
61 open STDERR, ">&", \*OLDERR; |
1855
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 ############################################################################### |
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 # 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
|
66 |
b3bbde3f806d
Tests: HTTP/2 tests with error_page and return.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 my ($sid, $frames, $frame); |
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 # 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
|
70 # 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
|
71 # 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
|
72 |
b3bbde3f806d
Tests: HTTP/2 tests with error_page and return.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 my $s1 = Test::Nginx::HTTP2->new(); |
b3bbde3f806d
Tests: HTTP/2 tests with error_page and return.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 $sid = $s1->new_stream({ headers => [ |
b3bbde3f806d
Tests: HTTP/2 tests with error_page and return.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 { name => ':method', value => 'GET' }, |
b3bbde3f806d
Tests: HTTP/2 tests with error_page and return.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 { name => ':path', value => '/' }, |
b3bbde3f806d
Tests: HTTP/2 tests with error_page and return.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 { name => ':authority', value => 'localhost' }]}); |
b3bbde3f806d
Tests: HTTP/2 tests with error_page and return.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 $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
|
79 |
b3bbde3f806d
Tests: HTTP/2 tests with error_page and return.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 ($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
|
81 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
|
82 |
b3bbde3f806d
Tests: HTTP/2 tests with error_page and return.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 # 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
|
84 # 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
|
85 # 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
|
86 |
b3bbde3f806d
Tests: HTTP/2 tests with error_page and return.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 my $s2 = Test::Nginx::HTTP2->new(); |
b3bbde3f806d
Tests: HTTP/2 tests with error_page and return.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 $sid = $s2->new_stream({ method => 'foo' }); |
b3bbde3f806d
Tests: HTTP/2 tests with error_page and return.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 $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
|
90 |
1936
716d7500317d
Tests: keep HTTP/2 test for "return 444" in error_page as TODO.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1900
diff
changeset
|
91 TODO: { |
716d7500317d
Tests: keep HTTP/2 test for "return 444" in error_page as TODO.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1900
diff
changeset
|
92 local $TODO = 'not yet' unless $t->has_version('1.23.4'); |
716d7500317d
Tests: keep HTTP/2 test for "return 444" in error_page as TODO.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1900
diff
changeset
|
93 |
1855
b3bbde3f806d
Tests: HTTP/2 tests with error_page and return.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
94 ($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
|
95 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
|
96 |
1936
716d7500317d
Tests: keep HTTP/2 test for "return 444" in error_page as TODO.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1900
diff
changeset
|
97 } |
716d7500317d
Tests: keep HTTP/2 test for "return 444" in error_page as TODO.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1900
diff
changeset
|
98 |
1855
b3bbde3f806d
Tests: HTTP/2 tests with error_page and return.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
99 # 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
|
100 # "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
|
101 # sockets are still open |
b3bbde3f806d
Tests: HTTP/2 tests with error_page and return.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
102 |
b3bbde3f806d
Tests: HTTP/2 tests with error_page and return.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
103 $t->stop(); |
1936
716d7500317d
Tests: keep HTTP/2 test for "return 444" in error_page as TODO.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1900
diff
changeset
|
104 $t->todo_alerts() unless $t->has_version('1.23.4'); |
1855
b3bbde3f806d
Tests: HTTP/2 tests with error_page and return.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
105 |
b3bbde3f806d
Tests: HTTP/2 tests with error_page and return.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
106 ############################################################################### |