Skip to content

Commit abefeea

Browse files
committed
Merge branch 'cgfrost-master'
[resolves cloudfoundry#116][resolves cloudfoundry#114]
2 parents 7b1cbc5 + ac1f06d commit abefeea

File tree

7 files changed

+100
-52
lines changed

7 files changed

+100
-52
lines changed

java-buildpack.iml

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -266,37 +266,37 @@
266266
<excludeFolder url="file://$MODULE_DIR$/coverage" />
267267
<excludeFolder url="file://$MODULE_DIR$/doc" />
268268
</content>
269-
<orderEntry type="jdk" jdkName="rbenv: 1.9.3-p550" jdkType="RUBY_SDK" />
269+
<orderEntry type="jdk" jdkName="ruby-1.9.3-p551" jdkType="RUBY_SDK" />
270270
<orderEntry type="sourceFolder" forTests="false" />
271-
<orderEntry type="library" scope="PROVIDED" name="addressable (v2.3.6, rbenv: 1.9.3-p550) [gem]" level="application" />
272-
<orderEntry type="library" scope="PROVIDED" name="ast (v2.0.0, rbenv: 1.9.3-p550) [gem]" level="application" />
273-
<orderEntry type="library" scope="PROVIDED" name="astrolabe (v1.3.0, rbenv: 1.9.3-p550) [gem]" level="application" />
274-
<orderEntry type="library" scope="PROVIDED" name="bundler (v1.7.4, rbenv: 1.9.3-p550) [gem]" level="application" />
275-
<orderEntry type="library" scope="PROVIDED" name="codeclimate-test-reporter (v0.4.1, rbenv: 1.9.3-p550) [gem]" level="application" />
276-
<orderEntry type="library" scope="PROVIDED" name="crack (v0.4.2, rbenv: 1.9.3-p550) [gem]" level="application" />
277-
<orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.2.5, rbenv: 1.9.3-p550) [gem]" level="application" />
278-
<orderEntry type="library" scope="PROVIDED" name="docile (v1.1.5, rbenv: 1.9.3-p550) [gem]" level="application" />
279-
<orderEntry type="library" scope="PROVIDED" name="multi_json (v1.10.1, rbenv: 1.9.3-p550) [gem]" level="application" />
280-
<orderEntry type="library" scope="PROVIDED" name="parser (v2.2.0.pre.6, rbenv: 1.9.3-p550) [gem]" level="application" />
281-
<orderEntry type="library" scope="PROVIDED" name="powerpack (v0.0.9, rbenv: 1.9.3-p550) [gem]" level="application" />
282-
<orderEntry type="library" scope="PROVIDED" name="rainbow (v2.0.0, rbenv: 1.9.3-p550) [gem]" level="application" />
283-
<orderEntry type="library" scope="PROVIDED" name="rake (v10.3.2, rbenv: 1.9.3-p550) [gem]" level="application" />
284-
<orderEntry type="library" scope="PROVIDED" name="redcarpet (v3.2.0, rbenv: 1.9.3-p550) [gem]" level="application" />
285-
<orderEntry type="library" scope="PROVIDED" name="rspec (v3.1.0, rbenv: 1.9.3-p550) [gem]" level="application" />
286-
<orderEntry type="library" scope="PROVIDED" name="rspec-core (v3.1.7, rbenv: 1.9.3-p550) [gem]" level="application" />
287-
<orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.1.2, rbenv: 1.9.3-p550) [gem]" level="application" />
288-
<orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.1.3, rbenv: 1.9.3-p550) [gem]" level="application" />
289-
<orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.1.2, rbenv: 1.9.3-p550) [gem]" level="application" />
290-
<orderEntry type="library" scope="PROVIDED" name="rubocop (v0.26.1, rbenv: 1.9.3-p550) [gem]" level="application" />
291-
<orderEntry type="library" scope="PROVIDED" name="ruby-progressbar (v1.6.0, rbenv: 1.9.3-p550) [gem]" level="application" />
292-
<orderEntry type="library" scope="PROVIDED" name="rubyzip (v1.1.6, rbenv: 1.9.3-p550) [gem]" level="application" />
293-
<orderEntry type="library" scope="PROVIDED" name="safe_yaml (v1.0.4, rbenv: 1.9.3-p550) [gem]" level="application" />
294-
<orderEntry type="library" scope="PROVIDED" name="simplecov (v0.9.1, rbenv: 1.9.3-p550) [gem]" level="application" />
295-
<orderEntry type="library" scope="PROVIDED" name="simplecov-html (v0.8.0, rbenv: 1.9.3-p550) [gem]" level="application" />
296-
<orderEntry type="library" scope="PROVIDED" name="slop (v3.6.0, rbenv: 1.9.3-p550) [gem]" level="application" />
297-
<orderEntry type="library" scope="PROVIDED" name="tee (v1.0.0, rbenv: 1.9.3-p550) [gem]" level="application" />
298-
<orderEntry type="library" scope="PROVIDED" name="webmock (v1.20.0, rbenv: 1.9.3-p550) [gem]" level="application" />
299-
<orderEntry type="library" scope="PROVIDED" name="yard (v0.8.7.6, rbenv: 1.9.3-p550) [gem]" level="application" />
271+
<orderEntry type="library" scope="PROVIDED" name="addressable (v2.3.6, ruby-1.9.3-p551) [gem]" level="application" />
272+
<orderEntry type="library" scope="PROVIDED" name="ast (v2.0.0, ruby-1.9.3-p551) [gem]" level="application" />
273+
<orderEntry type="library" scope="PROVIDED" name="astrolabe (v1.3.0, ruby-1.9.3-p551) [gem]" level="application" />
274+
<orderEntry type="library" scope="PROVIDED" name="bundler (v1.7.6, ruby-1.9.3-p551) [gem]" level="application" />
275+
<orderEntry type="library" scope="PROVIDED" name="codeclimate-test-reporter (v0.4.1, ruby-1.9.3-p551) [gem]" level="application" />
276+
<orderEntry type="library" scope="PROVIDED" name="crack (v0.4.2, ruby-1.9.3-p551) [gem]" level="application" />
277+
<orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.2.5, ruby-1.9.3-p551) [gem]" level="application" />
278+
<orderEntry type="library" scope="PROVIDED" name="docile (v1.1.5, ruby-1.9.3-p551) [gem]" level="application" />
279+
<orderEntry type="library" scope="PROVIDED" name="multi_json (v1.10.1, ruby-1.9.3-p551) [gem]" level="application" />
280+
<orderEntry type="library" scope="PROVIDED" name="parser (v2.2.0.pre.6, ruby-1.9.3-p551) [gem]" level="application" />
281+
<orderEntry type="library" scope="PROVIDED" name="powerpack (v0.0.9, ruby-1.9.3-p551) [gem]" level="application" />
282+
<orderEntry type="library" scope="PROVIDED" name="rainbow (v2.0.0, ruby-1.9.3-p551) [gem]" level="application" />
283+
<orderEntry type="library" scope="PROVIDED" name="rake (v10.3.2, ruby-1.9.3-p551) [gem]" level="application" />
284+
<orderEntry type="library" scope="PROVIDED" name="redcarpet (v3.2.0, ruby-1.9.3-p551) [gem]" level="application" />
285+
<orderEntry type="library" scope="PROVIDED" name="rspec (v3.1.0, ruby-1.9.3-p551) [gem]" level="application" />
286+
<orderEntry type="library" scope="PROVIDED" name="rspec-core (v3.1.7, ruby-1.9.3-p551) [gem]" level="application" />
287+
<orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.1.2, ruby-1.9.3-p551) [gem]" level="application" />
288+
<orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.1.3, ruby-1.9.3-p551) [gem]" level="application" />
289+
<orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.1.2, ruby-1.9.3-p551) [gem]" level="application" />
290+
<orderEntry type="library" scope="PROVIDED" name="rubocop (v0.26.1, ruby-1.9.3-p551) [gem]" level="application" />
291+
<orderEntry type="library" scope="PROVIDED" name="ruby-progressbar (v1.6.0, ruby-1.9.3-p551) [gem]" level="application" />
292+
<orderEntry type="library" scope="PROVIDED" name="rubyzip (v1.1.6, ruby-1.9.3-p551) [gem]" level="application" />
293+
<orderEntry type="library" scope="PROVIDED" name="safe_yaml (v1.0.4, ruby-1.9.3-p551) [gem]" level="application" />
294+
<orderEntry type="library" scope="PROVIDED" name="simplecov (v0.9.1, ruby-1.9.3-p551) [gem]" level="application" />
295+
<orderEntry type="library" scope="PROVIDED" name="simplecov-html (v0.8.0, ruby-1.9.3-p551) [gem]" level="application" />
296+
<orderEntry type="library" scope="PROVIDED" name="slop (v3.6.0, ruby-1.9.3-p551) [gem]" level="application" />
297+
<orderEntry type="library" scope="PROVIDED" name="tee (v1.0.0, ruby-1.9.3-p551) [gem]" level="application" />
298+
<orderEntry type="library" scope="PROVIDED" name="webmock (v1.20.0, ruby-1.9.3-p551) [gem]" level="application" />
299+
<orderEntry type="library" scope="PROVIDED" name="yard (v0.8.7.6, ruby-1.9.3-p551) [gem]" level="application" />
300300
</component>
301301
<component name="RModuleSettingsStorage">
302302
<LOAD_PATH number="4" string0="$MODULE_DIR$/lib" string1="$MODULE_DIR$/spec" string2="$MODULE_DIR$/bin" string3="$MODULE_DIR$/spec/bin" />

lib/java_buildpack/component/base_component.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
require 'java_buildpack/util/format_duration'
2121
require 'java_buildpack/util/shell'
2222
require 'java_buildpack/util/space_case'
23+
require 'java_buildpack/util/sanitizer'
2324

2425
module JavaBuildpack
2526
module Component
@@ -84,7 +85,7 @@ def release
8485
# @return [Void]
8586
def download(version, uri, name = @component_name)
8687
download_start_time = Time.now
87-
print "-----> Downloading #{name} #{version} from #{uri} "
88+
print "-----> Downloading #{name} #{version} from #{uri.sanitize_uri} "
8889

8990
JavaBuildpack::Util::Cache::ApplicationCache.new.get(uri) do |file, downloaded|
9091
puts downloaded ? "(#{(Time.now - download_start_time).duration})" : '(found in cache)'

lib/java_buildpack/util/cache/cached_file.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class CachedFile
3333
# @param [String] uri a uri which uniquely identifies the file in the cache
3434
# @param [Boolean] mutable whether the cached file should be mutable
3535
def initialize(cache_root, uri, mutable)
36-
key = URI.escape(uri, ':/')
36+
key = URI.escape(uri.sanitize_uri, ':/')
3737
@cached = cache_root + "#{key}.cached"
3838
@etag = cache_root + "#{key}.etag"
3939
@last_modified = cache_root + "#{key}.last_modified"

lib/java_buildpack/util/cache/download_cache.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
require 'java_buildpack/util/cache/cached_file'
2020
require 'java_buildpack/util/cache/inferred_network_failure'
2121
require 'java_buildpack/util/cache/internet_availability'
22+
require 'java_buildpack/util/sanitizer'
2223
require 'monitor'
2324
require 'net/http'
2425
require 'pathname'
@@ -63,7 +64,7 @@ def get(uri, &block)
6364
cached_file, downloaded = from_mutable_cache uri if InternetAvailability.instance.available?
6465
cached_file, downloaded = from_immutable_caches(uri), false unless cached_file
6566

66-
fail "Unable to find cached file for #{uri}" unless cached_file
67+
fail "Unable to find cached file for #{uri.sanitize_uri}" unless cached_file
6768
cached_file.cached(File::RDONLY | File::BINARY, downloaded, &block)
6869
end
6970

@@ -191,7 +192,7 @@ def from_mutable_cache(uri)
191192
cached = update URI(uri), cached_file
192193
[cached_file, cached]
193194
rescue => e
194-
@logger.warn { "Unable to download #{uri} into cache #{@mutable_cache_root}: #{e.message}" }
195+
@logger.warn { "Unable to download #{uri.sanitize_uri} into cache #{@mutable_cache_root}: #{e.message}" }
195196
nil
196197
end
197198

@@ -201,7 +202,7 @@ def from_immutable_caches(uri)
201202

202203
next unless candidate.cached?
203204

204-
@logger.debug { "#{uri} found in cache #{cache_root}" }
205+
@logger.debug { "#{uri.sanitize_uri} found in cache #{cache_root}" }
205206
return candidate
206207
end
207208

lib/java_buildpack/util/sanitizer.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Encoding: utf-8
2+
# Cloud Foundry Java Buildpack
3+
# Copyright (c) 2014 the original author or authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# A mixin that adds the ability to turn a +String+ into sanitized uri
18+
class String
19+
20+
# Takes a uri and strips out any credentials it may contain.
21+
#
22+
# @return [String] the sanitized uri
23+
def sanitize_uri
24+
rich_uri = URI(self)
25+
rich_uri.user = nil
26+
rich_uri.password = nil
27+
rich_uri.to_s
28+
end
29+
30+
end

spec/java_buildpack/util/cache/download_cache_spec.rb

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
expect(Net::HTTP).not_to receive(:Proxy).with('proxy', 9000, nil, nil)
8787

8888
expect { |b| download_cache.get uri_credentials, &b }.to yield_file_with_content(/foo-cached/)
89-
expect_complete_credential_cache mutable_cache_root
89+
expect_complete_cache mutable_cache_root
9090
end
9191

9292
it 'should follow redirects' do
@@ -292,28 +292,12 @@ def cache_file(root, extension)
292292
root + "http%3A%2F%2Ffoo-uri%2F.#{extension}"
293293
end
294294

295-
def credential_cache_file(root, extension)
296-
root + "http%3A%2F%2Ftest-username%3Atest-password@foo-uri%2F.#{extension}"
297-
end
298-
299295
def expect_complete_cache(root)
300296
expect_file_content root, 'cached', 'foo-cached'
301297
expect_file_content root, 'etag', 'foo-etag'
302298
expect_file_content root, 'last_modified', 'foo-last-modified'
303299
end
304300

305-
def expect_complete_credential_cache(root)
306-
expect_credential_file_content root, 'cached', 'foo-cached'
307-
expect_credential_file_content root, 'etag', 'foo-etag'
308-
expect_credential_file_content root, 'last_modified', 'foo-last-modified'
309-
end
310-
311-
def expect_credential_file_content(root, extension, content = '')
312-
file = credential_cache_file root, extension
313-
expect(file).to exist
314-
expect(file.read).to eq(content)
315-
end
316-
317301
def expect_file_content(root, extension, content = '')
318302
file = cache_file root, extension
319303
expect(file).to exist
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Encoding: utf-8
2+
# Cloud Foundry Java Buildpack
3+
# Copyright (c) 2014 the original author or authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
require 'spec_helper'
18+
require 'application_helper'
19+
require 'java_buildpack/util/sanitizer'
20+
21+
describe 'sanitize uri' do
22+
include_context 'application_helper'
23+
24+
it 'should sanatize uri with credentials in' do
25+
expect('https://myuser:mypass@myhost/path/to/file'.sanitize_uri).to eq('https://myhost/path/to/file')
26+
end
27+
28+
it 'should not sanatize uri with no credentials in' do
29+
expect('https://myhost/path/to/file'.sanitize_uri).to eq('https://myhost/path/to/file')
30+
end
31+
32+
end

0 commit comments

Comments
 (0)