Skip to content

Commit 1df5e8b

Browse files
authored
Merge pull request #850 from dmikusa-pivotal/main
Add basic auth support when using APPD_CONF_HTTP_URL to fetch configuration from a remote server.
2 parents bc0bb93 + 091e00d commit 1df5e8b

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

lib/java_buildpack/framework/app_dynamics_agent.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,11 @@ def check_if_resource_exists(resource_uri, conf_file)
148148
begin
149149
opts = { use_ssl: true } if resource_uri.scheme == 'https'
150150
response = Net::HTTP.start(resource_uri.host, resource_uri.port, opts) do |http|
151-
http.request_head(resource_uri)
151+
req = Net::HTTP::Head.new(resource_uri)
152+
if resource_uri.user != '' || resource_uri.password != ''
153+
req.basic_auth(resource_uri.user, resource_uri.password)
154+
end
155+
http.request(req)
152156
end
153157
rescue StandardError => e
154158
@logger.error { "Request failure: #{e.message}" }

spec/java_buildpack/framework/app_dynamics_agent_spec.rb

+23
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,29 @@
190190
end
191191
end
192192

193+
context do
194+
let(:environment) { { 'APPD_CONF_HTTP_URL' => 'https://user:[email protected]' } }
195+
196+
it 'sets APPD_CONF_HTTP_URL env var to download config files over HTTPS with Basic Auth',
197+
cache_fixture: 'stub-app-dynamics-agent.zip' do
198+
199+
config_files = %w[logging/log4j2.xml logging/log4j.xml app-agent-config.xml controller-info.xml
200+
service-endpoint.xml transactions.xml custom-interceptors.xml
201+
custom-activity-correlation.xml]
202+
203+
config_files.each do |file|
204+
allow(application_cache).to receive(:get)
205+
.with("https://user:[email protected]/java/#{file}")
206+
allow(Net::HTTP).to receive(:start).with('foo.com', 443, use_ssl: true).and_call_original
207+
stub_request(:head, "https://foo.com/java/#{file}")
208+
.with(headers: { 'Accept' => '*/*', 'Host' => 'foo.com', 'User-Agent' => 'Ruby',
209+
'Authorization' => 'Basic dXNlcjpwYXNz' })
210+
.to_return(status: 200, body: '', headers: {})
211+
end
212+
component.compile
213+
end
214+
end
215+
193216
context do
194217

195218
let(:environment) { { 'APPD_CONF_DIR' => 'BOOT-INF/classes/appdynamics/conf' } }

0 commit comments

Comments
 (0)