Skip to content

Commit

Permalink
[rubygems/rubygems] Remove test-only & unused methods from Checksum::…
Browse files Browse the repository at this point in the history
  • Loading branch information
martinemde authored and matzbot committed Dec 15, 2023
1 parent 0a31cb1 commit 1cfe874
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 21 deletions.
11 changes: 0 additions & 11 deletions lib/bundler/checksum.rb
Expand Up @@ -163,21 +163,10 @@ def initialize
@store = {}
end

def initialize_copy(other)
@store = {}
other.store.each do |lock_name, checksums|
store[lock_name] = checksums.dup
end
end

def inspect
"#<#{self.class}:#{object_id} size=#{store.size}>"
end

def fetch(spec, algo = DEFAULT_ALGORITHM)
store[spec.name_tuple.lock_name]&.fetch(algo, nil)
end

# Replace when the new checksum is from the same source.
# The primary purpose of this registering checksums from gems where there are
# duplicates of the same gem (according to full_name) in the index.
Expand Down
23 changes: 13 additions & 10 deletions spec/bundler/bundler/lockfile_parser_spec.rb
Expand Up @@ -119,12 +119,13 @@
let(:bundler_version) { Gem::Version.new("1.12.0.rc.2") }
let(:ruby_version) { "ruby 2.1.3p242" }
let(:lockfile_path) { Bundler.default_lockfile.relative_path_from(Dir.pwd) }
let(:rake_checksum) do
let(:rake_sha256_checksum) do
Bundler::Checksum.from_lock(
"sha256=814828c34f1315d7e7b7e8295184577cc4e969bad6156ac069d02d63f58d82e8",
"#{lockfile_path}:20:17"
)
end
let(:rake_checksums) { [rake_sha256_checksum] }

shared_examples_for "parsing" do
it "parses correctly" do
Expand All @@ -135,9 +136,9 @@
expect(subject.platforms).to eq platforms
expect(subject.bundler_version).to eq bundler_version
expect(subject.ruby_version).to eq ruby_version
checksum = subject.sources.last.checksum_store.fetch(specs.last)
expect(checksum).to be_match(rake_checksum)
expect(checksum.sources.first.to_s).to match(/the lockfile CHECKSUMS at #{Regexp.escape(lockfile_path.to_s)}:\d+:\d+/)
rake_spec = specs.last
checksums = subject.sources.last.checksum_store.to_lock(specs.last)
expect(checksums).to eq("#{rake_spec.name_tuple.lock_name} #{rake_checksums.map(&:to_lock).sort.join(",")}")
end
end

Expand Down Expand Up @@ -174,18 +175,20 @@
end

context "when the checksum is of an unknown algorithm" do
let(:rake_sha512_checksum) do
Bundler::Checksum.from_lock(
"sha512=pVDn9GLmcFkz8vj1ueiVxj5uGKkAyaqYjEX8zG6L5O4BeVg3wANaKbQdpj/B82Nd/MHVszy6polHcyotUdwilQ==",
"#{lockfile_path}:20:17"
)
end
let(:lockfile_contents) do
super().sub(
"sha256=",
"sha512=pVDn9GLmcFkz8vj1ueiVxj5uGKkAyaqYjEX8zG6L5O4BeVg3wANaKbQdpj/B82Nd/MHVszy6polHcyotUdwilQ==,sha256="
)
end
let(:rake_checksums) { [rake_sha256_checksum, rake_sha512_checksum] }
include_examples "parsing"

it "preserves the checksum as is" do
checksum = subject.sources.last.checksum_store.fetch(specs.last, "sha512")
expect(checksum.algo).to eq("sha512")
end
end

context "when CHECKSUMS has duplicate checksums in the lockfile that don't match" do
Expand All @@ -198,7 +201,7 @@
Bundler found mismatched checksums. This is a potential security risk.
rake (10.3.2) #{bad_checksum}
from the lockfile CHECKSUMS at #{lockfile_path}:20:17
rake (10.3.2) #{rake_checksum.to_lock}
rake (10.3.2) #{rake_sha256_checksum.to_lock}
from the lockfile CHECKSUMS at #{lockfile_path}:21:17
To resolve this issue you can either:
Expand Down

0 comments on commit 1cfe874

Please sign in to comment.