Mercurial > hg > nginx-tests
comparison http_absolute_redirect.t @ 1691:0d8531f744bc
Tests: added Location header escaping tests (ticket #882).
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Thu, 27 May 2021 13:07:46 +0300 |
parents | 766bcbb632ee |
children | 77a9e393ed46 |
comparison
equal
deleted
inserted
replaced
1690:29f0e926c15f | 1691:0d8531f744bc |
---|---|
1 #!/usr/bin/perl | 1 #!/usr/bin/perl |
2 | 2 |
3 # (C) Sergey Kandaurov | 3 # (C) Sergey Kandaurov |
4 # (C) Nginx, Inc. | 4 # (C) Nginx, Inc. |
5 | 5 |
6 # Tests for absolute_redirect directive. | 6 # Tests for absolute_redirect directive and Location escaping. |
7 | 7 |
8 ############################################################################### | 8 ############################################################################### |
9 | 9 |
10 use warnings; | 10 use warnings; |
11 use strict; | 11 use strict; |
47 | 47 |
48 location /auto/ { | 48 location /auto/ { |
49 proxy_pass http://127.0.0.1:8080; | 49 proxy_pass http://127.0.0.1:8080; |
50 } | 50 } |
51 | 51 |
52 location "/auto sp/" { | |
53 proxy_pass http://127.0.0.1:8080; | |
54 } | |
55 | |
52 location /return301 { | 56 location /return301 { |
53 return 301 /redirect; | 57 return 301 /redirect; |
54 } | 58 } |
55 | 59 |
56 location /i/ { | 60 location /i/ { |
66 | 70 |
67 location /auto/ { | 71 location /auto/ { |
68 proxy_pass http://127.0.0.1:8080; | 72 proxy_pass http://127.0.0.1:8080; |
69 } | 73 } |
70 | 74 |
75 location "/auto sp/" { | |
76 proxy_pass http://127.0.0.1:8080; | |
77 } | |
78 | |
71 location /return301 { | 79 location /return301 { |
72 return 301 /redirect; | 80 return 301 /redirect; |
73 } | 81 } |
74 | 82 |
75 location /i/ { | 83 location /i/ { |
79 } | 87 } |
80 | 88 |
81 EOF | 89 EOF |
82 | 90 |
83 mkdir($t->testdir() . '/dir'); | 91 mkdir($t->testdir() . '/dir'); |
92 mkdir($t->testdir() . '/dir sp'); | |
84 | 93 |
85 $t->run()->plan(10); | 94 $t->run()->plan(18); |
86 | 95 |
87 ############################################################################### | 96 ############################################################################### |
88 | 97 |
89 my $p = port(8080); | 98 my $p = port(8080); |
90 | 99 |
91 like(get('on', '/dir'), qr!Location: http://on:$p/dir/\x0d?$!m, 'directory'); | 100 like(get('on', '/dir'), qr!Location: http://on:$p/dir/\x0d?$!m, 'directory'); |
92 like(get('on', '/i/dir'), qr!Location: http://on:$p/i/dir/\x0d?$!m, | 101 like(get('on', '/i/dir'), qr!Location: http://on:$p/i/dir/\x0d?$!m, |
93 'directory alias'); | 102 'directory alias'); |
103 | |
104 TODO: { | |
105 local $TODO = 'not yet' unless $t->has_version('1.21.0'); | |
106 | |
107 like(get('on', '/dir%20sp'), qr!Location: http://on:$p/dir%20sp/\x0d?$!m, | |
108 'directory escaped'); | |
109 like(get('on', '/dir%20sp?a=b'), | |
110 qr!Location: http://on:$p/dir%20sp/\?a=b\x0d?$!m, | |
111 'directory escaped args'); | |
112 | |
113 } | |
114 | |
94 like(get('on', '/auto'), qr!Location: http://on:$p/auto/\x0d?$!m, 'auto'); | 115 like(get('on', '/auto'), qr!Location: http://on:$p/auto/\x0d?$!m, 'auto'); |
95 like(get('on', '/auto?a=b'), qr!Location: http://on:$p/auto/\?a=b\x0d?$!m, | 116 like(get('on', '/auto?a=b'), qr!Location: http://on:$p/auto/\?a=b\x0d?$!m, |
96 'auto args'); | 117 'auto args'); |
118 | |
119 TODO: { | |
120 local $TODO = 'not yet' unless $t->has_version('1.21.0'); | |
121 | |
122 like(get('on', '/auto%20sp'), qr!Location: http://on:$p/auto%20sp/\x0d?$!m, | |
123 'auto escaped'); | |
124 like(get('on', '/auto%20sp?a=b'), | |
125 qr!Location: http://on:$p/auto%20sp/\?a=b\x0d?$!m, | |
126 'auto escaped args'); | |
127 | |
128 } | |
129 | |
97 like(get('on', '/return301'), qr!Location: http://on:$p/redirect\x0d?$!m, | 130 like(get('on', '/return301'), qr!Location: http://on:$p/redirect\x0d?$!m, |
98 'return'); | 131 'return'); |
99 | 132 |
100 like(get('off', '/dir'), qr!Location: /dir/\x0d?$!m, 'off directory'); | 133 like(get('off', '/dir'), qr!Location: /dir/\x0d?$!m, 'off directory'); |
101 like(get('off', '/i/dir'), qr!Location: /i/dir/\x0d?$!m, 'off directory alias'); | 134 like(get('off', '/i/dir'), qr!Location: /i/dir/\x0d?$!m, 'off directory alias'); |
135 | |
136 TODO: { | |
137 local $TODO = 'not yet' unless $t->has_version('1.21.0'); | |
138 | |
139 like(get('off', '/dir%20sp'), qr!Location: /dir%20sp/\x0d?$!m, | |
140 'off directory escaped'); | |
141 like(get('off', '/dir%20sp?a=b'), qr!Location: /dir%20sp/\?a=b\x0d?$!m, | |
142 'off directory escaped args'); | |
143 | |
144 } | |
145 | |
102 like(get('off', '/auto'), qr!Location: /auto/\x0d?$!m, 'off auto'); | 146 like(get('off', '/auto'), qr!Location: /auto/\x0d?$!m, 'off auto'); |
103 like(get('off', '/auto?a=b'), qr!Location: /auto/\?a=b\x0d?$!m, | 147 like(get('off', '/auto?a=b'), qr!Location: /auto/\?a=b\x0d?$!m, |
104 'off auto args'); | 148 'off auto args'); |
149 | |
150 TODO: { | |
151 local $TODO = 'not yet' unless $t->has_version('1.21.0'); | |
152 | |
153 like(get('off', '/auto%20sp'), qr!Location: /auto%20sp/\x0d?$!m, | |
154 'auto escaped'); | |
155 like(get('off', '/auto%20sp?a=b'), qr!Location: /auto%20sp/\?a=b\x0d?$!m, | |
156 'auto escaped args'); | |
157 | |
158 } | |
159 | |
105 like(get('off', '/return301'), qr!Location: /redirect\x0d?$!m, 'off return'); | 160 like(get('off', '/return301'), qr!Location: /redirect\x0d?$!m, 'off return'); |
106 | 161 |
107 ############################################################################### | 162 ############################################################################### |
108 | 163 |
109 sub get { | 164 sub get { |