summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Giddins <segiddins@segiddins.me>2016-04-28 23:58:26 -0500
committerSamuel Giddins <segiddins@segiddins.me>2016-04-28 23:58:47 -0500
commit5041bc663dec449226f413738b43dbfa913d1b0d (patch)
tree295bfed9fa33d000274b55807fc40a16a482b27d
parent7d9380fec7a4d1efdc356155e27ddefb18d80cf6 (diff)
downloadbundler-seg-checksum-mismatch-error.tar.gz
[CompactIndex] Fall back when the versions checksum mismatchesseg-checksum-mismatch-error
-rw-r--r--lib/bundler/fetcher/compact_index.rb3
-rw-r--r--lib/bundler/vendor/compact_index_client/lib/compact_index_client/updater.rb2
-rw-r--r--spec/install/gems/compact_index_spec.rb14
-rw-r--r--spec/support/artifice/compact_index_checksum_mismatch.rb15
4 files changed, 33 insertions, 1 deletions
diff --git a/lib/bundler/fetcher/compact_index.rb b/lib/bundler/fetcher/compact_index.rb
index c1beee6c75..3d24a9d728 100644
--- a/lib/bundler/fetcher/compact_index.rb
+++ b/lib/bundler/fetcher/compact_index.rb
@@ -61,6 +61,9 @@ module Bundler
def available?
# Read info file checksums out of /versions, so we can know if gems are up to date
fetch_uri.scheme != "file" && compact_index_client.update_and_parse_checksums!
+ rescue CompactIndexClient::Updater::MisMatchedChecksumError => e
+ Bundler.ui.warn(e.message)
+ nil
end
compact_index_request :available?
diff --git a/lib/bundler/vendor/compact_index_client/lib/compact_index_client/updater.rb b/lib/bundler/vendor/compact_index_client/lib/compact_index_client/updater.rb
index e447d7a2b8..630318a9be 100644
--- a/lib/bundler/vendor/compact_index_client/lib/compact_index_client/updater.rb
+++ b/lib/bundler/vendor/compact_index_client/lib/compact_index_client/updater.rb
@@ -56,7 +56,7 @@ class Bundler::CompactIndexClient
def etag_for(path)
sum = checksum_for_file(path)
- sum ? '"' << sum << '"' : nil
+ sum ? %("#{sum}") : nil
end
def checksum_for_file(path)
diff --git a/spec/install/gems/compact_index_spec.rb b/spec/install/gems/compact_index_spec.rb
index 13645f0ae6..c00e73523b 100644
--- a/spec/install/gems/compact_index_spec.rb
+++ b/spec/install/gems/compact_index_spec.rb
@@ -139,6 +139,20 @@ describe "compact index api" do
should_be_installed "rack 1.0.0"
end
+ it "falls back when the versions endpoint has a checksum mismatch" do
+ gemfile <<-G
+ source "#{source_uri}"
+ gem "rack"
+ G
+
+ bundle! :install, :verbose => true, :artifice => "compact_index_checksum_mismatch"
+ expect(out).to include("Fetching gem metadata from #{source_uri}")
+ expect(out).to include <<-'WARN'
+The checksum of /versions does not match the checksum provided by the server! Something is wrong (local checksum is "\"d41d8cd98f00b204e9800998ecf8427e\"", was expecting "\"123\"").
+ WARN
+ should_be_installed "rack 1.0.0"
+ end
+
it "handles host redirects" do
gemfile <<-G
source "#{source_uri}"
diff --git a/spec/support/artifice/compact_index_checksum_mismatch.rb b/spec/support/artifice/compact_index_checksum_mismatch.rb
new file mode 100644
index 0000000000..4ac328736c
--- /dev/null
+++ b/spec/support/artifice/compact_index_checksum_mismatch.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+require File.expand_path("../compact_index", __FILE__)
+
+Artifice.deactivate
+
+class CompactIndexChecksumMismatch < CompactIndexAPI
+ get "/versions" do
+ headers "ETag" => quote("123")
+ headers "Surrogate-Control" => "max-age=2592000, stale-while-revalidate=60"
+ content_type "text/plain"
+ body ""
+ end
+end
+
+Artifice.activate_with(CompactIndexChecksumMismatch)