|
10 | 10 | 'HTTP_X_FORWARDED_FOR' => '212.122.121.211',
|
11 | 11 | 'HTTP_X_FORWARDED_HOST' => host,
|
12 | 12 | 'HTTP_X_FORWARDED_PORT' => '443',
|
13 |
| - 'HTTP_X_FORWARDED_PROTO' => scheme, |
| 13 | + 'HTTP_X_FORWARDED_PROTO' => 'https', |
14 | 14 | 'HTTP_USER_AGENT' => 'Faraday',
|
15 | 15 | 'HTTP_OTHER_HEADER' => 'Ignored'
|
16 | 16 | }
|
|
20 | 20 | response_headers: response_headers,
|
21 | 21 | status: 301,
|
22 | 22 | response_body: nil,
|
23 |
| - url: URI.join("#{scheme}://#{host}", *[remote_prefix.presence, remote_path].compact) |
| 23 | + url: URI.join("https://#{host}", *[remote_prefix.presence, remote_path].compact) |
24 | 24 | }
|
25 | 25 | end
|
26 | 26 | let(:host) { 'api.example.com' }
|
27 | 27 | let(:local_prefix) { '/proxy-prefix' }
|
| 28 | + let(:location) { nil } |
28 | 29 | let(:options) do
|
29 | 30 | {
|
30 | 31 | target_prefix: remote_prefix,
|
|
35 | 36 | let(:remote_prefix) { '/remote-prefix' }
|
36 | 37 | let(:remote_path) { 'remote-path' }
|
37 | 38 | let(:response_headers) do
|
38 |
| - {'Location' => '/remote-prefix/see/other/path'} |
| 39 | + {'Location' => location.presence}.compact |
39 | 40 | end
|
40 | 41 | let(:rack_response) { response.rack_response }
|
41 |
| - let(:scheme) { 'https' } |
42 |
| - let(:headers) { rack_response.headers } |
43 | 42 |
|
44 | 43 | describe 'Location header' do
|
45 |
| - subject { headers['Location'] } |
| 44 | + subject { rack_response.location } |
46 | 45 |
|
47 | 46 | context 'when both remote and local have a prefix' do
|
| 47 | + let(:location) { '/remote-prefix/original-redirect' } |
48 | 48 | let(:local_prefix) { '/proxy-prefix' }
|
49 | 49 | let(:remote_prefix) { '/remote-prefix' }
|
50 | 50 |
|
51 |
| - it { is_expected.to eq '/proxy-prefix/see/other/path' } |
| 51 | + it { is_expected.to eq '/proxy-prefix/original-redirect' } |
52 | 52 | end
|
53 | 53 |
|
54 | 54 | context 'when only remote has a prefix' do
|
| 55 | + let(:location) { '/remote-prefix/original-redirect' } |
55 | 56 | let(:local_prefix) { '' }
|
56 | 57 | let(:remote_prefix) { '/remote-prefix' }
|
57 | 58 |
|
58 |
| - it { is_expected.to eq '/see/other/path' } |
| 59 | + it { is_expected.to eq '/original-redirect' } |
59 | 60 | end
|
60 | 61 |
|
61 | 62 | context 'when only local has a prefix' do
|
| 63 | + let(:location) { '/original-redirect' } |
62 | 64 | let(:local_prefix) { '/local-prefix' }
|
63 |
| - let(:response_headers) do |
64 |
| - {'Location' => '/see/other/path'} |
65 |
| - end |
| 65 | + let(:remote_prefix) { '' } |
66 | 66 |
|
67 |
| - it { is_expected.to eq '/proxy-prefix/see/other/path' } |
| 67 | + it { is_expected.to eq '/local-prefix/original-redirect' } |
| 68 | + end |
| 69 | + |
| 70 | + context 'when neither has a prefix' do |
| 71 | + let(:location) { '/original-redirect' } |
| 72 | + let(:local_prefix) { '' } |
| 73 | + let(:remote_prefix) { '' } |
| 74 | + |
| 75 | + it { is_expected.to eq location } |
| 76 | + end |
| 77 | + |
| 78 | + context 'when it points to a different host' do |
| 79 | + let(:location) { 'https://otherhost.com/original-redirect' } |
| 80 | + let(:local_prefix) { '/proxy-prefix' } |
| 81 | + let(:remote_prefix) { '/remote-prefix' } |
| 82 | + |
| 83 | + it { is_expected.to eq location } |
68 | 84 | end
|
69 | 85 | end
|
70 | 86 | end
|
0 commit comments