Skip to content

Commit aa94d38

Browse files
committed
Merge branch '797-url-encoded-proxy-auth'
Signed-off-by: Ben Hale <[email protected]>
2 parents 8efbd16 + 2c4b273 commit aa94d38

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

lib/java_buildpack/util/cache/download_cache.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,11 @@ def proxy(uri)
314314
URI.parse(ENV['http_proxy'] || ENV['HTTP_PROXY'] || '')
315315
end
316316

317-
@logger.debug { "Proxy: #{proxy_uri.host}, #{proxy_uri.port}, #{proxy_uri.user}, #{proxy_uri.password}" }
318-
Net::HTTP::Proxy(proxy_uri.host, proxy_uri.port, proxy_uri.user, proxy_uri.password)
317+
proxy_user = proxy_uri.user ? URI.decode_www_form_component(proxy_uri.user) : nil
318+
proxy_pass = proxy_uri.password ? URI.decode_www_form_component(proxy_uri.password) : nil
319+
320+
@logger.debug { "Proxy: #{proxy_uri.host}, #{proxy_uri.port}, #{proxy_user}, #{proxy_pass}" }
321+
Net::HTTP::Proxy(proxy_uri.host, proxy_uri.port, proxy_user, proxy_pass)
319322
end
320323

321324
def redirect?(response)

spec/java_buildpack/util/cache/download_cache_spec.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,22 @@
223223

224224
end
225225

226+
context do
227+
228+
let(:environment) { { 'HTTP_PROXY' => 'http://user%21:pass%40@proxy:9000', 'http_proxy' => nil } }
229+
230+
it 'decodes user/pass from HTTP_PROXY if encoded' do
231+
stub_request(:get, uri)
232+
.to_return(status: 200, body: 'foo-cached', headers: { Etag: 'foo-etag',
233+
'Last-Modified' => 'foo-last-modified' })
234+
235+
allow(Net::HTTP).to receive(:Proxy).with('proxy', 9000, /user!/, /pass@/).and_call_original
236+
237+
download_cache.get(uri) {}
238+
end
239+
240+
end
241+
226242
context do
227243

228244
let(:environment) { { 'https_proxy' => 'http://proxy:9000', 'HTTPS_PROXY' => nil } }
@@ -257,6 +273,22 @@
257273

258274
end
259275

276+
context do
277+
278+
let(:environment) { { 'HTTPS_PROXY' => 'http://user%21:pass%40@proxy:9000', 'https_proxy' => nil } }
279+
280+
it 'decodes user/pass from HTTPS_PROXY if encoded' do
281+
stub_request(:get, uri_secure)
282+
.to_return(status: 200, body: 'foo-cached', headers: { Etag: 'foo-etag',
283+
'Last-Modified' => 'foo-last-modified' })
284+
285+
allow(Net::HTTP).to receive(:Proxy).with('proxy', 9000, /user!/, /pass@/).and_call_original
286+
287+
download_cache.get(uri_secure) {}
288+
end
289+
290+
end
291+
260292
context do
261293
let(:environment) { { 'NO_PROXY' => '127.0.0.1,localhost,foo-uri,.foo-uri', 'HTTPS_PROXY' => 'http://proxy:9000' } }
262294

0 commit comments

Comments
 (0)