|
33 | 33 |
|
34 | 34 | let(:uri) { 'http://foo-uri/' } |
35 | 35 |
|
| 36 | + let(:uri_credentials) { 'http://test-username:test-password@foo-uri/' } |
| 37 | + |
36 | 38 | let(:uri_secure) { 'https://foo-uri/' } |
37 | 39 |
|
38 | 40 | let(:download_cache) { described_class.new(mutable_cache_root, immutable_cache_root) } |
|
73 | 75 | expect_complete_cache mutable_cache_root |
74 | 76 | end |
75 | 77 |
|
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) |
78 | 80 | .to_return(status: 200, body: 'foo-cached', headers: { Etag: 'foo-etag', 'Last-Modified' => 'foo-last-modified' }) |
79 | 81 |
|
80 | 82 | allow(Net::HTTP).to receive(:Proxy).and_call_original |
81 | 83 | expect(Net::HTTP).not_to receive(:Proxy).with('proxy', 9000, nil, nil) |
82 | 84 |
|
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 |
86 | 88 | end |
87 | 89 |
|
88 | 90 | it 'should follow redirects' do |
@@ -252,12 +254,28 @@ def cache_file(root, extension) |
252 | 254 | root + "http:%2F%2Ffoo-uri%2F.#{extension}" |
253 | 255 | end |
254 | 256 |
|
| 257 | + def credential_cache_file(root, extension) |
| 258 | + root + "http:%2F%2Ftest-username:test-password@foo-uri%2F.#{extension}" |
| 259 | + end |
| 260 | + |
255 | 261 | def expect_complete_cache(root) |
256 | 262 | expect_file_content root, 'cached', 'foo-cached' |
257 | 263 | expect_file_content root, 'etag', 'foo-etag' |
258 | 264 | expect_file_content root, 'last_modified', 'foo-last-modified' |
259 | 265 | end |
260 | 266 |
|
| 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 | + |
261 | 279 | def expect_file_content(root, extension, content = '') |
262 | 280 | file = cache_file root, extension |
263 | 281 | expect(file).to exist |
|
0 commit comments