Skip to content

Commit e43cd44

Browse files
committed
fix specs
1 parent e5bc294 commit e43cd44

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

spec/api_valve/forwarder/response_spec.rb

+28-12
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
'HTTP_X_FORWARDED_FOR' => '212.122.121.211',
1111
'HTTP_X_FORWARDED_HOST' => host,
1212
'HTTP_X_FORWARDED_PORT' => '443',
13-
'HTTP_X_FORWARDED_PROTO' => scheme,
13+
'HTTP_X_FORWARDED_PROTO' => 'https',
1414
'HTTP_USER_AGENT' => 'Faraday',
1515
'HTTP_OTHER_HEADER' => 'Ignored'
1616
}
@@ -20,11 +20,12 @@
2020
response_headers: response_headers,
2121
status: 301,
2222
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)
2424
}
2525
end
2626
let(:host) { 'api.example.com' }
2727
let(:local_prefix) { '/proxy-prefix' }
28+
let(:location) { nil }
2829
let(:options) do
2930
{
3031
target_prefix: remote_prefix,
@@ -35,36 +36,51 @@
3536
let(:remote_prefix) { '/remote-prefix' }
3637
let(:remote_path) { 'remote-path' }
3738
let(:response_headers) do
38-
{'Location' => '/remote-prefix/see/other/path'}
39+
{'Location' => location.presence}.compact
3940
end
4041
let(:rack_response) { response.rack_response }
41-
let(:scheme) { 'https' }
42-
let(:headers) { rack_response.headers }
4342

4443
describe 'Location header' do
45-
subject { headers['Location'] }
44+
subject { rack_response.location }
4645

4746
context 'when both remote and local have a prefix' do
47+
let(:location) { '/remote-prefix/original-redirect' }
4848
let(:local_prefix) { '/proxy-prefix' }
4949
let(:remote_prefix) { '/remote-prefix' }
5050

51-
it { is_expected.to eq '/proxy-prefix/see/other/path' }
51+
it { is_expected.to eq '/proxy-prefix/original-redirect' }
5252
end
5353

5454
context 'when only remote has a prefix' do
55+
let(:location) { '/remote-prefix/original-redirect' }
5556
let(:local_prefix) { '' }
5657
let(:remote_prefix) { '/remote-prefix' }
5758

58-
it { is_expected.to eq '/see/other/path' }
59+
it { is_expected.to eq '/original-redirect' }
5960
end
6061

6162
context 'when only local has a prefix' do
63+
let(:location) { '/original-redirect' }
6264
let(:local_prefix) { '/local-prefix' }
63-
let(:response_headers) do
64-
{'Location' => '/see/other/path'}
65-
end
65+
let(:remote_prefix) { '' }
6666

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 }
6884
end
6985
end
7086
end

0 commit comments

Comments
 (0)