Skip to content

Commit d84cd86

Browse files
authored
Service broker client: Set 'X-Api-Info-Location' according to 'temporary_enable_v2' (#4058)
* Service broker client: Set 'X-Api-Info-Location' according to 'temporary_enable_v2' * use /v2/info if true, and root context / for false * Add tests for X-Api-Info-Location header
1 parent 0bf2173 commit d84cd86

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

lib/services/service_brokers/v2/http_client.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ def initialize(attrs, logger=nil)
1717
@auth_password = attrs.fetch(:auth_password)
1818
@verify_mode = verify_certs? ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE
1919
@broker_client_timeout = VCAP::CloudController::Config.config.get(:broker_client_timeout_seconds)
20-
@header_api_info_location = "#{VCAP::CloudController::Config.config.get(:external_domain)}/v2/info"
20+
api_info_path = VCAP::CloudController::Config.config.get(:temporary_enable_v2) ? '/v2/info' : '/'
21+
@header_api_info_location = "#{VCAP::CloudController::Config.config.get(:external_domain)}#{api_info_path}"
2122
@logger = logger || Steno.logger('cc.service_broker.v2.http_client')
2223
end
2324

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

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ module VCAP::Services::ServiceBrokers::V2
6666
to have_been_made
6767
end
6868

69-
it 'sets the X-Api-Info-Location header to the /v2/info endpoint at the external address' do
69+
it 'sets the X-Api-Info-Location header to the correct endpoint at the external address' do
7070
make_request
7171
expect(a_request(http_method, full_url).
7272
with(basic_auth:).
7373
with(query: hash_including({})).
74-
with(headers: { 'X-Api-Info-Location' => "#{TestConfig.config[:external_domain]}/v2/info" })).
74+
with(headers: { 'X-Api-Info-Location' => "#{TestConfig.config[:external_domain]}#{TestConfig.config[:temporary_enable_v2] ? '/v2/info' : '/'}" })).
7575
to have_been_made
7676
end
7777

@@ -86,7 +86,8 @@ module VCAP::Services::ServiceBrokers::V2
8686
expect(fake_logger).to have_received(:debug).with(match(/X-VCAP-Request-ID"=>"[[:alnum:]-]+/))
8787
expect(fake_logger).to have_received(:debug).with(match(/X-Broker-API-Request-Identity"=>"[[:alnum:]-]+/))
8888
expect(fake_logger).to have_received(:debug).with(match(/X-Broker-Api-Version"=>"2\.15/))
89-
expect(fake_logger).to have_received(:debug).with(match(%r{X-Api-Info-Location"=>"api2\.vcap\.me/v2/info}))
89+
api_info_path = TestConfig.config[:temporary_enable_v2] ? '/v2/info' : '/'
90+
expect(fake_logger).to have_received(:debug).with(match(/X-Api-Info-Location"=>"api2\.vcap\.me#{api_info_path}/))
9091
end
9192

9293
context 'when an https URL is used' do
@@ -148,6 +149,40 @@ module VCAP::Services::ServiceBrokers::V2
148149
end
149150
end
150151

152+
context 'X-Api-Info-Location' do
153+
context 'when temporary_enable_v2 is true' do
154+
before do
155+
TestConfig.config[:temporary_enable_v2] = true
156+
end
157+
158+
it 'sets the info location to /v2/info' do
159+
make_request
160+
161+
expect(a_request(http_method, full_url).
162+
with(basic_auth:).
163+
with(query: hash_including({})).
164+
with(headers: { 'X-Api-Info-Location' => 'api2.vcap.me/v2/info' })).
165+
to have_been_made
166+
end
167+
end
168+
169+
context 'when temporary_enable_v2 is false' do
170+
before do
171+
TestConfig.config[:temporary_enable_v2] = false
172+
end
173+
174+
it 'sets the info location to /' do
175+
make_request
176+
177+
expect(a_request(http_method, full_url).
178+
with(basic_auth:).
179+
with(query: hash_including({})).
180+
with(headers: { 'X-Api-Info-Location' => 'api2.vcap.me/' })).
181+
to have_been_made
182+
end
183+
end
184+
end
185+
151186
context 'X-Broker-Api-Originating-Identity' do
152187
context 'when user guid is set in the SecurityContext' do
153188
before do

0 commit comments

Comments
 (0)