1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[rubygems/rubygems] Add test cases from SHA1 RFC and improve test failure message

I found that the current test cases did not cover the bitwise AND
performed on modified words after each iteration
(7e5765a66c/bundler/lib/bundler/digest.rb (L50))

https://github.com/rubygems/rubygems/commit/c8de819fee
This commit is contained in:
David Rodríguez 2022-06-02 12:08:05 +02:00 committed by git
parent 1d924ae410
commit eb5a01970f

View file

@ -9,8 +9,15 @@ RSpec.describe Bundler::Digest do
let(:stdlib) { ::Digest::SHA1 }
it "is compatible with stdlib" do
["foo", "skfjsdlkfjsdf", "3924m", "ldskfj"].each do |payload|
expect(subject.sha1(payload)).to be == stdlib.hexdigest(payload)
random_strings = ["foo", "skfjsdlkfjsdf", "3924m", "ldskfj"]
# https://datatracker.ietf.org/doc/html/rfc3174#section-7.3
rfc3174_test_cases = ["abc", "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", "a", "01234567" * 8]
(random_strings + rfc3174_test_cases).each do |payload|
sha1 = subject.sha1(payload)
sha1_stdlib = stdlib.hexdigest(payload)
expect(sha1).to be == sha1_stdlib, "#{payload}'s sha1 digest (#{sha1}) did not match stlib's result (#{sha1_stdlib})"
end
end
end