Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redact all sources in verbose mode #4564

Merged
merged 1 commit into from Apr 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 8 additions & 4 deletions bundler/lib/bundler/fetcher/downloader.rb
Expand Up @@ -14,8 +14,10 @@ def initialize(connection, redirect_limit)
def fetch(uri, headers = {}, counter = 0)
raise HTTPError, "Too many redirects" if counter >= redirect_limit

filtered_uri = URICredentialsFilter.credential_filtered_uri(uri)

response = request(uri, headers)
Bundler.ui.debug("HTTP #{response.code} #{response.message} #{uri}")
Bundler.ui.debug("HTTP #{response.code} #{response.message} #{filtered_uri}")

case response
when Net::HTTPSuccess, Net::HTTPNotModified
Expand All @@ -40,7 +42,7 @@ def fetch(uri, headers = {}, counter = 0)
raise BadAuthenticationError, uri.host if uri.userinfo
raise AuthenticationRequiredError, uri.host
when Net::HTTPNotFound
raise FallbackError, "Net::HTTPNotFound: #{URICredentialsFilter.credential_filtered_uri(uri)}"
raise FallbackError, "Net::HTTPNotFound: #{filtered_uri}"
else
raise HTTPError, "#{response.class}#{": #{response.body}" unless response.body.empty?}"
end
Expand All @@ -49,7 +51,9 @@ def fetch(uri, headers = {}, counter = 0)
def request(uri, headers)
validate_uri_scheme!(uri)

Bundler.ui.debug "HTTP GET #{uri}"
filtered_uri = URICredentialsFilter.credential_filtered_uri(uri)

Bundler.ui.debug "HTTP GET #{filtered_uri}"
req = Net::HTTP::Get.new uri.request_uri, headers
if uri.user
user = CGI.unescape(uri.user)
Expand All @@ -69,7 +73,7 @@ def request(uri, headers)
raise NetworkDownError, "Could not reach host #{uri.host}. Check your network " \
"connection and try again."
else
raise HTTPError, "Network error while fetching #{URICredentialsFilter.credential_filtered_uri(uri)}" \
raise HTTPError, "Network error while fetching #{filtered_uri}" \
" (#{e})"
end
end
Expand Down
4 changes: 2 additions & 2 deletions bundler/lib/bundler/source/rubygems.rb
Expand Up @@ -423,11 +423,11 @@ def remote_specs
def fetch_names(fetchers, dependency_names, index, override_dupes)
fetchers.each do |f|
if dependency_names
Bundler.ui.info "Fetching gem metadata from #{f.uri}", Bundler.ui.debug?
Bundler.ui.info "Fetching gem metadata from #{URICredentialsFilter.credential_filtered_uri(f.uri)}", Bundler.ui.debug?
index.use f.specs_with_retry(dependency_names, self), override_dupes
Bundler.ui.info "" unless Bundler.ui.debug? # new line now that the dots are over
else
Bundler.ui.info "Fetching source index from #{f.uri}"
Bundler.ui.info "Fetching source index from #{URICredentialsFilter.credential_filtered_uri(f.uri)}"
index.use f.specs_with_retry(nil, self), override_dupes
end
end
Expand Down
11 changes: 11 additions & 0 deletions bundler/spec/install/gems/compact_index_spec.rb
Expand Up @@ -614,6 +614,17 @@ def require(*args)
expect(the_bundle).to include_gems "rack 1.0.0"
end

it "passes basic authentication details and strips out creds also in verbose mode" do
gemfile <<-G
source "#{basic_auth_source_uri}"
gem "rack"
G

bundle :install, :verbose => true, :artifice => "compact_index_basic_authentication"
expect(out).not_to include("#{user}:#{password}")
expect(the_bundle).to include_gems "rack 1.0.0"
end

it "strips http basic auth creds when warning about ambiguous sources", :bundler => "< 3" do
gemfile <<-G
source "#{basic_auth_source_uri}"
Expand Down
11 changes: 11 additions & 0 deletions bundler/spec/install/gems/dependency_api_spec.rb
Expand Up @@ -586,6 +586,17 @@ def require(*args)
expect(the_bundle).to include_gems "rack 1.0.0"
end

it "passes basic authentication details and strips out creds also in verbose mode" do
gemfile <<-G
source "#{basic_auth_source_uri}"
gem "rack"
G

bundle :install, :verbose => true, :artifice => "endpoint_basic_authentication"
expect(out).not_to include("#{user}:#{password}")
expect(the_bundle).to include_gems "rack 1.0.0"
end

it "strips http basic authentication creds for modern index" do
gemfile <<-G
source "#{basic_auth_source_uri}"
Expand Down