summaryrefslogtreecommitdiff
path: root/spec/bundler/support
diff options
context:
space:
mode:
authorMartin Emde <martin.emde@gmail.com>2023-09-01 15:15:49 -0700
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2023-10-23 13:59:01 +0900
commitc667de72ff9de195e1cab4b1937973e841ff89ae (patch)
tree6dc6a88dbf8c44109593352055c8e798d562a83f /spec/bundler/support
parent6362bfdc337c1929a381734ded417b796f9767bf (diff)
[rubygems/rubygems] Improve errors and register checksums reliably
Improve error reporting for checksums, raises a new error class. Solve for multi-source checksum errors. Add CHECKSUMS to tool/bundler/(dev|standard|rubocop)26_gems.rb https://github.com/rubygems/rubygems/commit/26ceee0e76 Co-authored-by: Samuel Giddins <segiddins@segiddins.me>
Diffstat (limited to 'spec/bundler/support')
-rw-r--r--spec/bundler/support/artifice/compact_index_wrong_gem_checksum.rb3
-rw-r--r--spec/bundler/support/artifice/helpers/compact_index.rb12
-rw-r--r--spec/bundler/support/checksums.rb20
3 files changed, 17 insertions, 18 deletions
diff --git a/spec/bundler/support/artifice/compact_index_wrong_gem_checksum.rb b/spec/bundler/support/artifice/compact_index_wrong_gem_checksum.rb
index acc13a56ff..9bd2ca0a9d 100644
--- a/spec/bundler/support/artifice/compact_index_wrong_gem_checksum.rb
+++ b/spec/bundler/support/artifice/compact_index_wrong_gem_checksum.rb
@@ -7,7 +7,8 @@ class CompactIndexWrongGemChecksum < CompactIndexAPI
etag_response do
name = params[:name]
gem = gems.find {|g| g.name == name }
- checksum = ENV.fetch("BUNDLER_SPEC_#{name.upcase}_CHECKSUM") { "ab" * 22 }
+ # This generates the hexdigest "2222222222222222222222222222222222222222222222222222222222222222"
+ checksum = ENV.fetch("BUNDLER_SPEC_#{name.upcase}_CHECKSUM") { "IiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiI=" }
versions = gem ? gem.versions : []
versions.each {|v| v.checksum = checksum }
CompactIndex.info(versions)
diff --git a/spec/bundler/support/artifice/helpers/compact_index.rb b/spec/bundler/support/artifice/helpers/compact_index.rb
index ef507ca12d..dd9e94ef9b 100644
--- a/spec/bundler/support/artifice/helpers/compact_index.rb
+++ b/spec/bundler/support/artifice/helpers/compact_index.rb
@@ -79,11 +79,13 @@ class CompactIndexAPI < Endpoint
reqs = d.requirement.requirements.map {|r| r.join(" ") }.join(", ")
CompactIndex::Dependency.new(d.name, reqs)
end
- checksum = begin
- Digest(:SHA256).file("#{gem_repo}/gems/#{spec.original_name}.gem").hexdigest
- rescue StandardError
- nil
- end
+ begin
+ checksum = ENV.fetch("BUNDLER_SPEC_#{name.upcase}_CHECKSUM") do
+ Digest(:SHA256).file("#{gem_repo}/gems/#{spec.original_name}.gem").hexdigest
+ end
+ rescue StandardError
+ checksum = nil
+ end
CompactIndex::GemVersion.new(spec.version.version, spec.platform.to_s, checksum, nil,
deps, spec.required_ruby_version.to_s, spec.required_rubygems_version.to_s)
end
diff --git a/spec/bundler/support/checksums.rb b/spec/bundler/support/checksums.rb
index 7f5ecc14dd..b5579d5671 100644
--- a/spec/bundler/support/checksums.rb
+++ b/spec/bundler/support/checksums.rb
@@ -9,26 +9,22 @@ module Spec
end
def repo_gem(repo, name, version, platform = Gem::Platform::RUBY)
- gem_file = File.join(repo, "gems", "#{Bundler::GemHelpers.spec_full_name(name, version, platform)}.gem")
+ name_tuple = Gem::NameTuple.new(name, version, platform)
+ gem_file = File.join(repo, "gems", "#{name_tuple.full_name}.gem")
File.open(gem_file, "rb") do |f|
- checksums = Bundler::Checksum.from_io(f, "ChecksumsBuilder")
- checksum_entry(checksums, name, version, platform)
+ @checksums[name_tuple] = Bundler::Checksum.from_gem(f, "#{gem_file} (via ChecksumsBuilder#repo_gem)")
end
end
def no_checksum(name, version, platform = Gem::Platform::RUBY)
- checksum_entry(nil, name, version, platform)
- end
-
- def checksum_entry(checksums, name, version, platform = Gem::Platform::RUBY)
- lock_name = Bundler::GemHelpers.lock_name(name, version, platform)
- @checksums[lock_name] = checksums
+ name_tuple = Gem::NameTuple.new(name, version, platform)
+ @checksums[name_tuple] = nil
end
def to_lock
- @checksums.map do |lock_name, checksums|
- checksums &&= " #{checksums.map(&:to_lock).join(",")}"
- " #{lock_name}#{checksums}\n"
+ @checksums.map do |name_tuple, checksum|
+ checksum &&= " #{checksum.to_lock}"
+ " #{name_tuple.lock_name}#{checksum}\n"
end.sort.join.strip
end
end