annotate h3_absolute_redirect.t @ 1976:4e79bd25642f default tip

Tests: added test for headers without a colon.
author Maxim Dounin <mdounin@mdounin.ru>
date Sat, 11 May 2024 18:56:23 +0300
parents 8b74936ff2ac
children
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
1896
8b74936ff2ac Tests: added has_feature() test for CryptX.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1877
diff changeset
26 my $t = Test::Nginx->new()->has(qw/http http_v3 proxy rewrite cryptx/)
1877
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
27 ->has_daemon('openssl')->plan(23);
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 $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
30
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
31 %%TEST_GLOBALS%%
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
32
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
33 daemon off;
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
34
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
35 events {
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
36 }
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 http {
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
39 %%TEST_GLOBALS_HTTP%%
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 absolute_redirect off;
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
42
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
43 ssl_certificate_key localhost.key;
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
44 ssl_certificate localhost.crt;
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 server {
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
47 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
48 server_name on;
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
49
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
50 absolute_redirect on;
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
51 error_page 400 /return301;
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 location / { }
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
54
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
55 location /auto/ {
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
56 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
57 }
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
58
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
59 location "/auto sp/" {
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
60 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
61 }
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
62
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
63 location /return301 {
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
64 return 301 /redirect;
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
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
67 location /return301/name {
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
68 return 301 /redirect;
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
69 server_name_in_redirect on;
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
70 }
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
71
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
72 location /return301/port {
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
73 return 301 /redirect;
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
74 port_in_redirect off;
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
75 }
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
76
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
77 location /i/ {
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
78 alias %%TESTDIR%%/;
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 }
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
81
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
82 server {
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
83 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
84 server_name off;
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
85
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
86 location / { }
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
87
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
88 location /auto/ {
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
89 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
90 }
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
91
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
92 location "/auto sp/" {
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
93 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
94 }
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
95
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
96 location '/auto "#%<>?\^`{|}/' {
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
97 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
98 }
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
99
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
100 location /return301 {
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
101 return 301 /redirect;
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
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
104 location /i/ {
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
105 alias %%TESTDIR%%/;
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 }
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
108 }
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 EOF
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 $t->write_file('openssl.conf', <<EOF);
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
113 [ req ]
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
114 default_bits = 2048
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
115 encrypt_key = no
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
116 distinguished_name = req_distinguished_name
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
117 [ req_distinguished_name ]
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
118 EOF
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
119
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
120 my $d = $t->testdir();
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
121
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
122 foreach my $name ('localhost') {
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
123 system('openssl req -x509 -new '
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
124 . "-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
125 . "-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
126 . ">>$d/openssl.out 2>&1") == 0
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
127 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
128 }
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
129
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
130 mkdir($t->testdir() . '/dir');
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
131 mkdir($t->testdir() . '/dir sp');
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 $t->run();
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
134
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
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
137 my $p = port(8980);
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 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
140 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
141 'directory alias');
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
142
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
143 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
144 'directory escaped');
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
145 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
146 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
147 'directory escaped args');
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
148
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
149 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
150 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
151 'auto args');
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
152
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
153 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
154 'auto escaped');
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
155 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
156 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
157 'auto escaped args');
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
158
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
159 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
160 'return');
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('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
163 'server_name_in_redirect on');
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
164 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
165 '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
166 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
167 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
168 'invalid host - using local sockaddr');
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
169 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
170 'port_in_redirect off');
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
171
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
172 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
173 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
174
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
175 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
176 'off directory escaped');
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
177 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
178 'off directory escaped args');
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
179
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
180 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
181 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
182 'off auto args');
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
183
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
184 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
185 'auto escaped');
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
186 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
187 'auto escaped args');
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
188
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
189 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
190
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
191 # 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
192 # %00-%1F, %7F-%FF, " ", """, "<", ">", "\", "^", "`", "{", "|", "}"
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
193 # additionally, all characters in ESCAPE_URI: "?", "%", "#"
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
194
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
195 SKIP: {
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
196 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
197
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
198 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
199 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
200 'auto escaped strict');
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
201
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
202 }
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
203
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 sub get {
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
207 my ($host, $uri) = @_;
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 my $s = Test::Nginx::HTTP3->new();
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
210 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
211 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
212
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
213 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
214 return 'Location: ' . $frame->{headers}->{'location'};
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
dc0bda44044c Tests: HTTP/3 tests for absolute_redirect and Location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
217 ###############################################################################