annotate h2_error_page.t @ 1987:a095b971fbcc

Tests: removed TODO and try_run() checks for legacy versions. For h2_http2.t, try_run() is preserved to ensure that deprecation warnings for "listen ... http2" are suppressed, yet plan() is reported before try_run(), so failure to start will be properly reported.
author Maxim Dounin <mdounin@mdounin.ru>
date Tue, 04 Jun 2024 18:38:01 +0300
parents 11463d379570
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 {
1986
11463d379570 Tests: reworked HTTP/2 tests to use "http2 on".
Maxim Dounin <mdounin@mdounin.ru>
parents: 1936
diff changeset
40 listen 127.0.0.1:8080;
1855
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
1986
11463d379570 Tests: reworked HTTP/2 tests to use "http2 on".
Maxim Dounin <mdounin@mdounin.ru>
parents: 1936
diff changeset
43 http2 on;
1855
b3bbde3f806d Tests: HTTP/2 tests with error_page and return.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
44 lingering_close off;
b3bbde3f806d Tests: HTTP/2 tests with error_page and return.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
45
b3bbde3f806d Tests: HTTP/2 tests with error_page and return.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
46 error_page 400 = /close;
b3bbde3f806d Tests: HTTP/2 tests with error_page and return.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
47
b3bbde3f806d Tests: HTTP/2 tests with error_page and return.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
48 location / { }
b3bbde3f806d Tests: HTTP/2 tests with error_page and return.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
49
b3bbde3f806d Tests: HTTP/2 tests with error_page and return.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
50 location /close {
b3bbde3f806d Tests: HTTP/2 tests with error_page and return.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
51 return 444;
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
b3bbde3f806d Tests: HTTP/2 tests with error_page and return.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
56 EOF
b3bbde3f806d Tests: HTTP/2 tests with error_page and return.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
57
b3bbde3f806d Tests: HTTP/2 tests with error_page and return.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
58 $t->run();
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
b3bbde3f806d Tests: HTTP/2 tests with error_page and return.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
62 # 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
63
b3bbde3f806d Tests: HTTP/2 tests with error_page and return.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
64 my ($sid, $frames, $frame);
b3bbde3f806d Tests: HTTP/2 tests with error_page and return.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
65
b3bbde3f806d Tests: HTTP/2 tests with error_page and return.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
66 # 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
67 # 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
68 # 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
69
b3bbde3f806d Tests: HTTP/2 tests with error_page and return.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
70 my $s1 = Test::Nginx::HTTP2->new();
b3bbde3f806d Tests: HTTP/2 tests with error_page and return.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
71 $sid = $s1->new_stream({ headers => [
b3bbde3f806d Tests: HTTP/2 tests with error_page and return.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
72 { name => ':method', value => 'GET' },
b3bbde3f806d Tests: HTTP/2 tests with error_page and return.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
73 { name => ':path', value => '/' },
b3bbde3f806d Tests: HTTP/2 tests with error_page and return.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
74 { name => ':authority', value => 'localhost' }]});
b3bbde3f806d Tests: HTTP/2 tests with error_page and return.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
75 $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
76
b3bbde3f806d Tests: HTTP/2 tests with error_page and return.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
77 ($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
78 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
79
b3bbde3f806d Tests: HTTP/2 tests with error_page and return.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
80 # 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
81 # 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
82 # 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
83
b3bbde3f806d Tests: HTTP/2 tests with error_page and return.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
84 my $s2 = Test::Nginx::HTTP2->new();
b3bbde3f806d Tests: HTTP/2 tests with error_page and return.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
85 $sid = $s2->new_stream({ method => 'foo' });
b3bbde3f806d Tests: HTTP/2 tests with error_page and return.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
86 $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
87
b3bbde3f806d Tests: HTTP/2 tests with error_page and return.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
88 ($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
89 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
90
b3bbde3f806d Tests: HTTP/2 tests with error_page and return.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
91 # 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
92 # "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
93 # sockets are still open
b3bbde3f806d Tests: HTTP/2 tests with error_page and return.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
94
b3bbde3f806d Tests: HTTP/2 tests with error_page and return.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
95 $t->stop();
b3bbde3f806d Tests: HTTP/2 tests with error_page and return.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
96
b3bbde3f806d Tests: HTTP/2 tests with error_page and return.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
97 ###############################################################################