diff options
author | The Bundler Bot <bot@bundler.io> | 2018-01-19 17:44:46 +0000 |
---|---|---|
committer | Colby Swandale <me@colby.fyi> | 2018-04-20 10:27:30 +1000 |
commit | f09228d722a465445354ee335c895c4f5fcc2654 (patch) | |
tree | 7705dd0231ee3432e2894b1e9165b623e6c53f24 | |
parent | 5d463bb5368772337351d6e1fa3eca8f7c98faf6 (diff) | |
download | bundler-f09228d722a465445354ee335c895c4f5fcc2654.tar.gz |
Auto merge of #6264 - bundler:colby/client-index-gzip-error, r=indirect
handle gzip corruption errors in the compact index client
Bundler will raise an exception and crash if the Gzip that the Compact Client Index downloaded was corrupt.
See #6261
Handle the exception and allow Bundler to continue without crashing
(cherry picked from commit 596ae6b29f59d00f0bfb0d4519c32c11e4d15aaf)
-rw-r--r-- | lib/bundler/compact_index_client/updater.rb | 7 | ||||
-rw-r--r-- | spec/bundler/compact_index_client/updater_spec.rb | 33 |
2 files changed, 36 insertions, 4 deletions
diff --git a/lib/bundler/compact_index_client/updater.rb b/lib/bundler/compact_index_client/updater.rb index 3a4e4441ca..950306fee5 100644 --- a/lib/bundler/compact_index_client/updater.rb +++ b/lib/bundler/compact_index_client/updater.rb @@ -78,6 +78,13 @@ module Bundler update(local_path, remote_path, :retrying) end + rescue Errno::EACCES + raise Bundler::PermissionError, + "Bundler does not have write access to create a temp directory " \ + "within #{Dir.tmpdir}. Bundler must have write access to your " \ + "systems temp directory to function properly. " + rescue Zlib::GzipFile::Error + raise Bundler::HTTPError end def etag_for(path) diff --git a/spec/bundler/compact_index_client/updater_spec.rb b/spec/bundler/compact_index_client/updater_spec.rb index 3c4f212b60..fd554a7b0d 100644 --- a/spec/bundler/compact_index_client/updater_spec.rb +++ b/spec/bundler/compact_index_client/updater_spec.rb @@ -5,16 +5,16 @@ require "bundler/compact_index_client" require "bundler/compact_index_client/updater" RSpec.describe Bundler::CompactIndexClient::Updater do - subject(:updater) { described_class.new(fetcher) } - let(:fetcher) { double(:fetcher) } + let(:local_path) { Pathname("/tmp/localpath") } + let(:remote_path) { double(:remote_path) } + + subject(:updater) { described_class.new(fetcher) } context "when the ETag header is missing" do # Regression test for https://github.com/bundler/bundler/issues/5463 let(:response) { double(:response, :body => "") } - let(:local_path) { Pathname("/tmp/localpath") } - let(:remote_path) { double(:remote_path) } it "MisMatchedChecksumError is raised" do # Twice: #update retries on failure @@ -27,4 +27,29 @@ RSpec.describe Bundler::CompactIndexClient::Updater do end.to raise_error(Bundler::CompactIndexClient::Updater::MisMatchedChecksumError) end end + + context "when the download is corrupt" do + let(:response) { double(:response, :body => "") } + + it "raises HTTPError" do + expect(response).to receive(:[]).with("Content-Encoding") { "gzip" } + expect(fetcher).to receive(:call) { response } + + expect do + updater.update(local_path, remote_path) + end.to raise_error(Bundler::HTTPError) + end + end + + context "when bundler doesn't have permissions on Dir.tmpdir" do + let(:response) { double(:response, :body => "") } + + it "Errno::EACCES is raised" do + allow(Dir).to receive(:mktmpdir) { raise Errno::EACCES } + + expect do + updater.update(local_path, remote_path) + end.to raise_error(Bundler::PermissionError) + end + end end |