annotate h2_error_page.t @ 1912:f61d1b4ac638

Tests: unbreak quic_ciphers.t with AEAD_AES_128_CCM enabled. Although CCM ciphers are disabled in a stock OpenSSL as rarely used, "to reduce ClientHello bloat", AEAD_AES_128_CCM is apparently turned back in certain distributions such as RHEL. Previously, this caused testing connections to fail as the CCM cipher being negotiated isn't supported yet in nginx. Now the test is skipped instead on failure. While here, fixed nearby style.
author Sergey Kandaurov <pluknet@nginx.com>
date Wed, 14 Jun 2023 16:57:01 +0400
parents 236d038dc04a
children 716d7500317d
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 {
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
b3bbde3f806d Tests: HTTP/2 tests with error_page and return.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
91 ($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
92 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
93
b3bbde3f806d Tests: HTTP/2 tests with error_page and return.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
94 # 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
95 # "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
96 # sockets are still open
b3bbde3f806d Tests: HTTP/2 tests with error_page and return.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
97
b3bbde3f806d Tests: HTTP/2 tests with error_page and return.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
98 $t->stop();
b3bbde3f806d Tests: HTTP/2 tests with error_page and return.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
99
b3bbde3f806d Tests: HTTP/2 tests with error_page and return.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
100 ###############################################################################