Skip to content

Commit a95ef91

Browse files
committed
Merge 70503862-repository-credentials to master
[Completes #70503862]
2 parents 074fd9a + a43e0d7 commit a95ef91

2 files changed

Lines changed: 24 additions & 5 deletions

File tree

lib/java_buildpack/util/cache/download_cache.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ def update(uri, cached_file)
240240
proxy(uri).start(uri.host, uri.port, http_options(uri)) do |http|
241241
@logger.debug { "HTTP: #{http.address}, #{http.port}, #{http_options(uri)}" }
242242
request = request uri, cached_file
243+
request.basic_auth uri.user, uri.password
243244

244245
failures = 0
245246
begin

spec/java_buildpack/util/cache/download_cache_spec.rb

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333

3434
let(:uri) { 'http://foo-uri/' }
3535

36+
let(:uri_credentials) { 'http://test-username:test-password@foo-uri/' }
37+
3638
let(:uri_secure) { 'https://foo-uri/' }
3739

3840
let(:download_cache) { described_class.new(mutable_cache_root, immutable_cache_root) }
@@ -73,16 +75,16 @@
7375
expect_complete_cache mutable_cache_root
7476
end
7577

76-
it 'should download if cached file does not exist' do
77-
stub_request(:get, uri)
78+
it 'should download with credentials if cached file does not exist' do
79+
stub_request(:get, uri_credentials)
7880
.to_return(status: 200, body: 'foo-cached', headers: { Etag: 'foo-etag', 'Last-Modified' => 'foo-last-modified' })
7981

8082
allow(Net::HTTP).to receive(:Proxy).and_call_original
8183
expect(Net::HTTP).not_to receive(:Proxy).with('proxy', 9000, nil, nil)
8284

83-
expect { |b| download_cache.get uri, &b }.to yield_with_args(be_a(File), true)
84-
.and yield_file_with_content(/foo-cached/)
85-
expect_complete_cache mutable_cache_root
85+
expect { |b| download_cache.get uri_credentials, &b }.to yield_with_args(be_a(File), true)
86+
.and yield_file_with_content(/foo-cached/)
87+
expect_complete_credential_cache mutable_cache_root
8688
end
8789

8890
it 'should follow redirects' do
@@ -252,12 +254,28 @@ def cache_file(root, extension)
252254
root + "http:%2F%2Ffoo-uri%2F.#{extension}"
253255
end
254256

257+
def credential_cache_file(root, extension)
258+
root + "http:%2F%2Ftest-username:test-password@foo-uri%2F.#{extension}"
259+
end
260+
255261
def expect_complete_cache(root)
256262
expect_file_content root, 'cached', 'foo-cached'
257263
expect_file_content root, 'etag', 'foo-etag'
258264
expect_file_content root, 'last_modified', 'foo-last-modified'
259265
end
260266

267+
def expect_complete_credential_cache(root)
268+
expect_credential_file_content root, 'cached', 'foo-cached'
269+
expect_credential_file_content root, 'etag', 'foo-etag'
270+
expect_credential_file_content root, 'last_modified', 'foo-last-modified'
271+
end
272+
273+
def expect_credential_file_content(root, extension, content = '')
274+
file = credential_cache_file root, extension
275+
expect(file).to exist
276+
expect(file.read).to eq(content)
277+
end
278+
261279
def expect_file_content(root, extension, content = '')
262280
file = cache_file root, extension
263281
expect(file).to exist

0 commit comments

Comments
 (0)