Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Service broker client: Set 'X-Api-Info-Location' according to 'temporary_enable_v2' #4058

Merged
merged 2 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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