Skip to content

Commit

Permalink
Service broker client: Set 'X-Api-Info-Location' according to 'tempor…
Browse files Browse the repository at this point in the history
…ary_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
  • Loading branch information
jochenehret authored Nov 4, 2024
1 parent 0bf2173 commit d84cd86
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/services/service_brokers/v2/http_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ def initialize(attrs, logger=nil)
@auth_password = attrs.fetch(:auth_password)
@verify_mode = verify_certs? ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE
@broker_client_timeout = VCAP::CloudController::Config.config.get(:broker_client_timeout_seconds)
@header_api_info_location = "#{VCAP::CloudController::Config.config.get(:external_domain)}/v2/info"
api_info_path = VCAP::CloudController::Config.config.get(:temporary_enable_v2) ? '/v2/info' : '/'
@header_api_info_location = "#{VCAP::CloudController::Config.config.get(:external_domain)}#{api_info_path}"
@logger = logger || Steno.logger('cc.service_broker.v2.http_client')
end

Expand Down
41 changes: 38 additions & 3 deletions spec/unit/lib/services/service_brokers/v2/http_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ module VCAP::Services::ServiceBrokers::V2
to have_been_made
end

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

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

context 'when an https URL is used' do
Expand Down Expand Up @@ -148,6 +149,40 @@ module VCAP::Services::ServiceBrokers::V2
end
end

context 'X-Api-Info-Location' do
context 'when temporary_enable_v2 is true' do
before do
TestConfig.config[:temporary_enable_v2] = true
end

it 'sets the info location to /v2/info' do
make_request

expect(a_request(http_method, full_url).
with(basic_auth:).
with(query: hash_including({})).
with(headers: { 'X-Api-Info-Location' => 'api2.vcap.me/v2/info' })).
to have_been_made
end
end

context 'when temporary_enable_v2 is false' do
before do
TestConfig.config[:temporary_enable_v2] = false
end

it 'sets the info location to /' do
make_request

expect(a_request(http_method, full_url).
with(basic_auth:).
with(query: hash_including({})).
with(headers: { 'X-Api-Info-Location' => 'api2.vcap.me/' })).
to have_been_made
end
end
end

context 'X-Broker-Api-Originating-Identity' do
context 'when user guid is set in the SecurityContext' do
before do
Expand Down

0 comments on commit d84cd86

Please sign in to comment.