|
164 | 164 | end |
165 | 165 | end |
166 | 166 |
|
| 167 | + context "when clear_authorization_header option" do |
| 168 | + context "is false" do |
| 169 | + it "redirects with the original authorization headers" do |
| 170 | + conn = connection(:clear_authorization_header => false) do |stub| |
| 171 | + stub.get('/redirect') { |
| 172 | + [301, {'Location' => '/found'}, ''] |
| 173 | + } |
| 174 | + stub.get('/found') { |env| |
| 175 | + [200, {'Content-Type' => 'text/plain'}, env[:request_headers]['Authorization']] |
| 176 | + } |
| 177 | + end |
| 178 | + response = conn.get('/redirect') { |req| |
| 179 | + req.headers['Authorization'] = 'success' |
| 180 | + } |
| 181 | + |
| 182 | + expect(response.body).to eq 'success' |
| 183 | + end |
| 184 | + end |
| 185 | + |
| 186 | + context "is true" do |
| 187 | + context "redirect to same host" do |
| 188 | + it "redirects with the original authorization headers" do |
| 189 | + conn = connection do |stub| |
| 190 | + stub.get('http://localhost/redirect') do |
| 191 | + [301, {'Location' => '/found'}, ''] |
| 192 | + end |
| 193 | + stub.get('http://localhost/found') do |env| |
| 194 | + [200, {}, env.request_headers["Authorization"]] |
| 195 | + end |
| 196 | + end |
| 197 | + response = conn.get('http://localhost/redirect') do |req| |
| 198 | + req.headers['Authorization'] = 'success' |
| 199 | + end |
| 200 | + |
| 201 | + expect(response.body).to eq 'success' |
| 202 | + end |
| 203 | + end |
| 204 | + |
| 205 | + context "redirect to same host with explicitly port" do |
| 206 | + it "redirects with the original authorization headers" do |
| 207 | + conn = connection do |stub| |
| 208 | + stub.get('http://localhost/redirect') do |
| 209 | + [301, {'Location' => 'http://localhost:80/found'}, ''] |
| 210 | + end |
| 211 | + stub.get('http://localhost/found') do |env| |
| 212 | + [200, {}, env.request_headers["Authorization"]] |
| 213 | + end |
| 214 | + end |
| 215 | + response = conn.get('http://localhost/redirect') { |req| |
| 216 | + req.headers['Authorization'] = 'success' |
| 217 | + } |
| 218 | + |
| 219 | + expect(response.body).to eq 'success' |
| 220 | + end |
| 221 | + end |
| 222 | + |
| 223 | + context "redirect to different scheme" do |
| 224 | + it "redirects without original authorization headers" do |
| 225 | + conn = connection do |stub| |
| 226 | + stub.get('http://localhost/redirect') do |
| 227 | + [301, {'Location' => 'https://localhost2/found'}, ''] |
| 228 | + end |
| 229 | + stub.get('https://localhost2/found') do |env| |
| 230 | + [200, {}, env.request_headers["Authorization"]] |
| 231 | + end |
| 232 | + end |
| 233 | + response = conn.get('http://localhost/redirect') { |req| |
| 234 | + req.headers['Authorization'] = 'failed' |
| 235 | + } |
| 236 | + |
| 237 | + expect(response.body).to eq nil |
| 238 | + end |
| 239 | + end |
| 240 | + |
| 241 | + context "redirect to different host" do |
| 242 | + it "redirects without original authorization headers" do |
| 243 | + conn = connection do |stub| |
| 244 | + stub.get('http://localhost/redirect') do |
| 245 | + [301, {'Location' => 'http://localhost2/found'}, ''] |
| 246 | + end |
| 247 | + stub.get('https://localhost2/found') do |env| |
| 248 | + [200, {}, env.request_headers["Authorization"]] |
| 249 | + end |
| 250 | + end |
| 251 | + response = conn.get('http://localhost/redirect') { |req| |
| 252 | + req.headers['Authorization'] = 'failed' |
| 253 | + } |
| 254 | + |
| 255 | + expect(response.body).to eq nil |
| 256 | + end |
| 257 | + end |
| 258 | + |
| 259 | + context "redirect to different port" do |
| 260 | + it "redirects without original authorization headers" do |
| 261 | + conn = connection do |stub| |
| 262 | + stub.get('http://localhost:9090/redirect') do |
| 263 | + [301, {'Location' => 'http://localhost:9091/found'}, ''] |
| 264 | + end |
| 265 | + stub.get('http://localhost:9091/found') do |env| |
| 266 | + [200, {}, env.request_headers["Authorization"]] |
| 267 | + end |
| 268 | + end |
| 269 | + response = conn.get('http://localhost:9090/redirect') { |req| |
| 270 | + req.headers['Authorization'] = 'failed' |
| 271 | + } |
| 272 | + |
| 273 | + expect(response.body).to eq nil |
| 274 | + end |
| 275 | + end |
| 276 | + end |
| 277 | + end |
| 278 | + |
167 | 279 | [301, 302].each do |code| |
168 | 280 | context "for an HTTP #{code} response" do |
169 | 281 | it_behaves_like 'a successful redirection', code |
|
0 commit comments