annotate h3_absolute_redirect.t @ 1888:cc13f7b098db

Tests: avoid premature stream reset in h3_limit_req.t. STREAM and RESET_STREAM frames could be batched, which prevents the stream from being processed and changes the status code. The fix is to wait for the stream acknowledgment. Here we just look at the largest acknowledged, this should be enough for simple cases.
author Sergey Kandaurov <pluknet@nginx.com>
date Tue, 04 Apr 2023 00:33:54 +0400
parents dc0bda44044c
children 8b74936ff2ac
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1877
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1 #!/usr/bin/perl
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
2
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
3 # (C) Sergey Kandaurov
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
4 # (C) Nginx, Inc.
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
5
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
6 # Tests for absolute_redirect directive and Location escaping.
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
7
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
8 ###############################################################################
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
9
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
10 use warnings;
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
11 use strict;
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
12
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
13 use Test::More;
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
14
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
15 BEGIN { use FindBin; chdir($FindBin::Bin); }
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
16
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
17 use lib 'lib';
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
18 use Test::Nginx;
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
19 use Test::Nginx::HTTP3;
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
20
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
21 ###############################################################################
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
22
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
23 select STDERR; $| = 1;
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
24 select STDOUT; $| = 1;
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
25
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
26 eval { require Crypt::Misc; die if $Crypt::Misc::VERSION < 0.067; };
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
27 plan(skip_all => 'CryptX version >= 0.067 required') if $@;
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
28
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
29 my $t = Test::Nginx->new()->has(qw/http http_v3 proxy rewrite/)
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
30 ->has_daemon('openssl')->plan(23);
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
31
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
32 $t->write_file_expand('nginx.conf', <<'EOF');
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
33
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
34 %%TEST_GLOBALS%%
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
35
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
36 daemon off;
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
37
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
38 events {
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
39 }
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
40
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
41 http {
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
42 %%TEST_GLOBALS_HTTP%%
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
43
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
44 absolute_redirect off;
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
45
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
46 ssl_certificate_key localhost.key;
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
47 ssl_certificate localhost.crt;
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
48
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
49 server {
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
50 listen 127.0.0.1:%%PORT_8980_UDP%% quic;
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
51 server_name on;
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
52
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
53 absolute_redirect on;
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
54 error_page 400 /return301;
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
55
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
56 location / { }
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
57
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
58 location /auto/ {
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
59 proxy_pass http://127.0.0.1:8080;
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
60 }
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
61
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
62 location "/auto sp/" {
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
63 proxy_pass http://127.0.0.1:8080;
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
64 }
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
65
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
66 location /return301 {
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
67 return 301 /redirect;
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
68 }
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
69
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
70 location /return301/name {
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
71 return 301 /redirect;
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
72 server_name_in_redirect on;
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
73 }
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
74
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
75 location /return301/port {
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
76 return 301 /redirect;
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
77 port_in_redirect off;
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
78 }
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
79
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
80 location /i/ {
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
81 alias %%TESTDIR%%/;
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
82 }
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
83 }
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
84
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
85 server {
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
86 listen 127.0.0.1:%%PORT_8980_UDP%% quic;
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
87 server_name off;
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
88
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
89 location / { }
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
90
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
91 location /auto/ {
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
92 proxy_pass http://127.0.0.1:8080;
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
93 }
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
94
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
95 location "/auto sp/" {
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
96 proxy_pass http://127.0.0.1:8080;
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
97 }
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
98
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
99 location '/auto "#%<>?\^`{|}/' {
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
100 proxy_pass http://127.0.0.1:8080;
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
101 }
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
102
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
103 location /return301 {
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
104 return 301 /redirect;
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
105 }
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
106
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
107 location /i/ {
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
108 alias %%TESTDIR%%/;
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
109 }
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
110 }
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
111 }
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
112
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
113 EOF
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
114
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
115 $t->write_file('openssl.conf', <<EOF);
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
116 [ req ]
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
117 default_bits = 2048
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
118 encrypt_key = no
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
119 distinguished_name = req_distinguished_name
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
120 [ req_distinguished_name ]
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
121 EOF
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
122
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
123 my $d = $t->testdir();
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
124
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
125 foreach my $name ('localhost') {
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
126 system('openssl req -x509 -new '
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
127 . "-config $d/openssl.conf -subj /CN=$name/ "
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
128 . "-out $d/$name.crt -keyout $d/$name.key "
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
129 . ">>$d/openssl.out 2>&1") == 0
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
130 or die "Can't create certificate for $name: $!\n";
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
131 }
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
132
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
133 mkdir($t->testdir() . '/dir');
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
134 mkdir($t->testdir() . '/dir sp');
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
135
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
136 $t->run();
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
137
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
138 ###############################################################################
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
139
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
140 my $p = port(8980);
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
141
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
142 like(get('on', '/dir'), qr!Location: https://on:$p/dir/\x0d?$!m, 'directory');
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
143 like(get('on', '/i/dir'), qr!Location: https://on:$p/i/dir/\x0d?$!m,
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
144 'directory alias');
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
145
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
146 like(get('on', '/dir%20sp'), qr!Location: https://on:$p/dir%20sp/\x0d?$!m,
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
147 'directory escaped');
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
148 like(get('on', '/dir%20sp?a=b'),
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
149 qr!Location: https://on:$p/dir%20sp/\?a=b\x0d?$!m,
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
150 'directory escaped args');
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
151
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
152 like(get('on', '/auto'), qr!Location: https://on:$p/auto/\x0d?$!m, 'auto');
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
153 like(get('on', '/auto?a=b'), qr!Location: https://on:$p/auto/\?a=b\x0d?$!m,
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
154 'auto args');
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
155
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
156 like(get('on', '/auto%20sp'), qr!Location: https://on:$p/auto%20sp/\x0d?$!m,
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
157 'auto escaped');
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
158 like(get('on', '/auto%20sp?a=b'),
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
159 qr!Location: https://on:$p/auto%20sp/\?a=b\x0d?$!m,
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
160 'auto escaped args');
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
161
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
162 like(get('on', '/return301'), qr!Location: https://on:$p/redirect\x0d?$!m,
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
163 'return');
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
164
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
165 like(get('host', '/return301/name'), qr!Location: https://on:$p/redirect\x0d?!m,
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
166 'server_name_in_redirect on');
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
167 like(get('host', '/return301'), qr!Location: https://host:$p/redirect\x0d?$!m,
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
168 'server_name_in_redirect off - using host');
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
169 my $ph = IO::Socket::INET->new("127.0.0.1:$p")->peerhost();
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
170 like(get('.', '/return301'), qr!Location: https://$ph:$p/redirect\x0d?$!m,
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
171 'invalid host - using local sockaddr');
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
172 like(get('host', '/return301/port'), qr!Location: https://host/redirect\x0d?$!m,
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
173 'port_in_redirect off');
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
174
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
175 like(get('off', '/dir'), qr!Location: /dir/\x0d?$!m, 'off directory');
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
176 like(get('off', '/i/dir'), qr!Location: /i/dir/\x0d?$!m, 'off directory alias');
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
177
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
178 like(get('off', '/dir%20sp'), qr!Location: /dir%20sp/\x0d?$!m,
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
179 'off directory escaped');
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
180 like(get('off', '/dir%20sp?a=b'), qr!Location: /dir%20sp/\?a=b\x0d?$!m,
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
181 'off directory escaped args');
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
182
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
183 like(get('off', '/auto'), qr!Location: /auto/\x0d?$!m, 'off auto');
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
184 like(get('off', '/auto?a=b'), qr!Location: /auto/\?a=b\x0d?$!m,
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
185 'off auto args');
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
186
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
187 like(get('off', '/auto%20sp'), qr!Location: /auto%20sp/\x0d?$!m,
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
188 'auto escaped');
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
189 like(get('off', '/auto%20sp?a=b'), qr!Location: /auto%20sp/\?a=b\x0d?$!m,
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
190 'auto escaped args');
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
191
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
192 like(get('off', '/return301'), qr!Location: /redirect\x0d?$!m, 'off return');
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
193
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
194 # per RFC 3986, these characters are not allowed unescaped:
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
195 # %00-%1F, %7F-%FF, " ", """, "<", ">", "\", "^", "`", "{", "|", "}"
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
196 # additionally, all characters in ESCAPE_URI: "?", "%", "#"
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
197
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
198 SKIP: {
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
199 skip 'win32', 1 if $^O eq 'MSWin32';
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
200
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
201 like(get('off', '/auto%20%22%23%25%3C%3E%3F%5C%5E%60%7B%7C%7D'),
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
202 qr!Location: /auto%20%22%23%25%3C%3E%3F%5C%5E%60%7B%7C%7D/\x0d?$!m,
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
203 'auto escaped strict');
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
204
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
205 }
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
206
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
207 ###############################################################################
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
208
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
209 sub get {
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
210 my ($host, $uri) = @_;
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
211
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
212 my $s = Test::Nginx::HTTP3->new();
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
213 my $sid = $s->new_stream({ host => $host, path => $uri });
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
214 my $frames = $s->read(all => [{ sid => $sid, fin => 1 }]);
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
215
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
216 my ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
217 return 'Location: ' . $frame->{headers}->{'location'};
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
218 }
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
219
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
220 ###############################################################################