diff options
author | David RodrÃguez <deivid.rodriguez@riseup.net> | 2023-08-10 21:37:15 +0200 |
---|---|---|
committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2023-08-16 15:03:38 +0900 |
commit | fe240b672b709e800f2b4fb996f04f2005329dab (patch) | |
tree | dc70b846c0c51d0bdb54a57ea5e5b0a4b4b6db4b /spec | |
parent | e678affe70d7597464368197fb55d277f0c26bab (diff) |
[rubygems/rubygems] Show better error when PAT can't authenticate to a private server
Before:
```
Fetching gem metadata from https://rubygems.org/........
Fetching source index from https://rubygems.pkg.github.com/my-org/
Bad username or password for https://x-access-token@rubygems.pkg.github.com/my-org/.
Please double-check your credentials and correct them.
```
After:
```
Fetching gem metadata from https://rubygems.org/........
Fetching source index from https://rubygems.pkg.github.com/my-org/
Access token could not be authenticated for https://x-access-token@rubygems.pkg.github.com/my-org/.
Make sure it's valid and has the necessary scopes configured.
```
https://github.com/rubygems/rubygems/commit/2ae69c964a
Diffstat (limited to 'spec')
-rw-r--r-- | spec/bundler/bundler/fetcher/downloader_spec.rb | 10 | ||||
-rw-r--r-- | spec/bundler/bundler/fetcher/index_spec.rb | 23 |
2 files changed, 13 insertions, 20 deletions
diff --git a/spec/bundler/bundler/fetcher/downloader_spec.rb b/spec/bundler/bundler/fetcher/downloader_spec.rb index 0412ddb83a..22aa3a8b0c 100644 --- a/spec/bundler/bundler/fetcher/downloader_spec.rb +++ b/spec/bundler/bundler/fetcher/downloader_spec.rb @@ -98,6 +98,16 @@ RSpec.describe Bundler::Fetcher::Downloader do end end + context "when the request response is a Net::HTTPForbidden" do + let(:http_response) { Net::HTTPForbidden.new("1.1", 403, "Forbidden") } + let(:uri) { Bundler::URI("http://user:password@www.uri-to-fetch.com") } + + it "should raise a Bundler::Fetcher::AuthenticationForbiddenError with the uri host" do + expect { subject.fetch(uri, options, counter) }.to raise_error(Bundler::Fetcher::AuthenticationForbiddenError, + /Access token could not be authenticated for www.uri-to-fetch.com/) + end + end + context "when the request response is a Net::HTTPNotFound" do let(:http_response) { Net::HTTPNotFound.new("1.1", 404, "Not Found") } diff --git a/spec/bundler/bundler/fetcher/index_spec.rb b/spec/bundler/bundler/fetcher/index_spec.rb index f0db07583c..971b64ce8f 100644 --- a/spec/bundler/bundler/fetcher/index_spec.rb +++ b/spec/bundler/bundler/fetcher/index_spec.rb @@ -63,26 +63,9 @@ RSpec.describe Bundler::Fetcher::Index do context "when a 403 response occurs" do let(:error_message) { "403" } - before do - allow(remote_uri).to receive(:userinfo).and_return(userinfo) - end - - context "and there was userinfo" do - let(:userinfo) { double(:userinfo) } - - it "should raise a Bundler::Fetcher::BadAuthenticationError" do - expect { subject.specs(gem_names) }.to raise_error(Bundler::Fetcher::BadAuthenticationError, - %r{Bad username or password for http://remote-uri.org}) - end - end - - context "and there was no userinfo" do - let(:userinfo) { nil } - - it "should raise a Bundler::Fetcher::AuthenticationRequiredError" do - expect { subject.specs(gem_names) }.to raise_error(Bundler::Fetcher::AuthenticationRequiredError, - %r{Authentication is required for http://remote-uri.org}) - end + it "should raise a Bundler::Fetcher::AuthenticationForbiddenError" do + expect { subject.specs(gem_names) }.to raise_error(Bundler::Fetcher::AuthenticationForbiddenError, + %r{Access token could not be authenticated for http://remote-uri.org}) end end |