From db3eb13ac7784bcafa0e74c630e80c77cb75a17c Mon Sep 17 00:00:00 2001 From: Jochen Ehret Date: Thu, 31 Oct 2024 15:12:52 +0100 Subject: [PATCH 1/2] Service broker client: Set 'X-Api-Info-Location' according to 'temporary_enable_v2' * use /v2/info if true, and root context / for false --- lib/services/service_brokers/v2/http_client.rb | 3 ++- .../lib/services/service_brokers/v2/http_client_spec.rb | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/services/service_brokers/v2/http_client.rb b/lib/services/service_brokers/v2/http_client.rb index 93db56b4f82..f1aefbf0fa0 100644 --- a/lib/services/service_brokers/v2/http_client.rb +++ b/lib/services/service_brokers/v2/http_client.rb @@ -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 diff --git a/spec/unit/lib/services/service_brokers/v2/http_client_spec.rb b/spec/unit/lib/services/service_brokers/v2/http_client_spec.rb index 0f034d4c228..94f151e7cc2 100644 --- a/spec/unit/lib/services/service_brokers/v2/http_client_spec.rb +++ b/spec/unit/lib/services/service_brokers/v2/http_client_spec.rb @@ -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 @@ -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 From fad36f2c89b367f97e6a6816862e361a17726a9b Mon Sep 17 00:00:00 2001 From: Jochen Ehret Date: Thu, 31 Oct 2024 16:14:26 +0100 Subject: [PATCH 2/2] Add tests for X-Api-Info-Location header --- .../service_brokers/v2/http_client_spec.rb | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/spec/unit/lib/services/service_brokers/v2/http_client_spec.rb b/spec/unit/lib/services/service_brokers/v2/http_client_spec.rb index 94f151e7cc2..cb1b6bcfd16 100644 --- a/spec/unit/lib/services/service_brokers/v2/http_client_spec.rb +++ b/spec/unit/lib/services/service_brokers/v2/http_client_spec.rb @@ -149,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