Skip to content

Commit d8c5711

Browse files
Merge pull request #4565 from rubygems/improve_authentication_required_message
Improve authentication required error message to include an alternative using `ENV` (cherry picked from commit 23e1855)
1 parent 49d9221 commit d8c5711

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

bundler/lib/bundler/fetcher.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ def initialize(remote_uri)
4747
remote_uri = filter_uri(remote_uri)
4848
super "Authentication is required for #{remote_uri}.\n" \
4949
"Please supply credentials for this source. You can do this by running:\n" \
50-
" bundle config set --global #{remote_uri} username:password"
50+
"`bundle config set --global #{remote_uri} username:password`\n" \
51+
"or by storing the credentials in the `#{Settings.key_for(remote_uri)}` environment variable"
5152
end
5253
end
5354
# This error is raised if HTTP authentication is provided, but incorrect.

bundler/lib/bundler/settings.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,7 @@ def validate!
296296
end
297297

298298
def key_for(key)
299-
key = Settings.normalize_uri(key).to_s if key.is_a?(String) && /https?:/ =~ key
300-
key = key.to_s.gsub(".", "__").gsub("-", "___").upcase
301-
"BUNDLE_#{key}"
299+
self.class.key_for(key)
302300
end
303301

304302
private
@@ -462,6 +460,12 @@ def load_config(config_file)
462460
\z
463461
/ix.freeze
464462

463+
def self.key_for(key)
464+
key = normalize_uri(key).to_s if key.is_a?(String) && /https?:/ =~ key
465+
key = key.to_s.gsub(".", "__").gsub("-", "___").upcase
466+
"BUNDLE_#{key}"
467+
end
468+
465469
# TODO: duplicates Rubygems#normalize_uri
466470
# TODO: is this the correct place to validate mirror URIs?
467471
def self.normalize_uri(uri)

bundler/spec/bundler/fetcher/downloader_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@
8383
/Authentication is required for www.uri-to-fetch.com/)
8484
end
8585

86+
it "should raise a Bundler::Fetcher::AuthenticationRequiredError with advices" do
87+
expect { subject.fetch(uri, options, counter) }.to raise_error(Bundler::Fetcher::AuthenticationRequiredError,
88+
/`bundle config set --global www\.uri-to-fetch\.com username:password`.*`BUNDLE_WWW__URI___TO___FETCH__COM`/m)
89+
end
90+
8691
context "when the there are credentials provided in the request" do
8792
let(:uri) { Bundler::URI("http://user:[email protected]") }
8893

0 commit comments

Comments
 (0)