Skip to content
This repository was archived by the owner on Jun 2, 2021. It is now read-only.

Commit 933f78d

Browse files
author
Derik Evangelista
authored
v3(services): broker client to follow redirects (cloudfoundry#1896)
See: cloudfoundry#1893 [#175213685](https://www.pivotaltracker.com/story/show/175213685)
1 parent 5416900 commit 933f78d

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

lib/services/service_brokers/v2/http_client.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ def uri_for(path)
4848

4949
def make_request(method, uri, body=nil, options={})
5050
client = HTTPClient.new(force_basic_auth: true)
51-
client.set_auth(uri, auth_username, auth_password)
51+
client.set_auth(nil, auth_username, auth_password)
5252
client.ssl_config.set_default_paths
5353

5454
client.ssl_config.verify_mode = verify_certs? ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE
5555
client.connect_timeout = broker_client_timeout
5656
client.receive_timeout = broker_client_timeout
5757
client.send_timeout = broker_client_timeout
5858

59-
opts = { body: body, header: {} }
59+
opts = { body: body, header: {}, follow_redirect: true }
6060

6161
client.default_header = default_headers
6262
opts[:header]['Content-Type'] = options[:content_type] if options[:content_type]

spec/unit/lib/services/service_brokers/v2/http_client_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,26 @@ def expect_timeout_to_be(timeout)
311311
end
312312
end
313313

314+
shared_examples 'client that follows redirects' do
315+
let(:another_url) { "http://another-broker.example.com#{path}" }
316+
317+
before do
318+
stub_request(http_method, full_url).
319+
with(basic_auth: basic_auth).
320+
to_return(status: 301, body: {}.to_json, headers: { Location: another_url })
321+
322+
stub_request(http_method, another_url).
323+
with(basic_auth: basic_auth).
324+
to_return(status: 200, body: '')
325+
end
326+
327+
it 'should follow redirects' do
328+
request
329+
330+
expect(a_request(http_method, another_url)).to have_been_made
331+
end
332+
end
333+
314334
describe '#get' do
315335
let(:http_method) { :get }
316336

@@ -368,6 +388,10 @@ def expect_timeout_to_be(timeout)
368388
it_behaves_like 'client that maps status codes to status code messages' do
369389
let(:request) { client.get(path) }
370390
end
391+
392+
it_behaves_like 'client that follows redirects' do
393+
let(:request) { client.get(path) }
394+
end
371395
end
372396

373397
describe '#put' do

0 commit comments

Comments
 (0)