aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Rodríguez <deivid.rodriguez@riseup.net>2022-06-02 12:08:05 +0200
committergit <svn-admin@ruby-lang.org>2022-06-02 22:23:42 +0900
commiteb5a01970ffd7a84029cf7d541c942418a2d8f44 (patch)
tree308abd9c132b6a029dca8f252fd48a3b7c92461a
parent1d924ae410c4183d0c064c4ed13877b49833d038 (diff)
downloadruby-eb5a01970ffd7a84029cf7d541c942418a2d8f44.tar.gz
[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 (https://github.com/rubygems/rubygems/blob/7e5765a66c9fe5187b167f619f34db5db121f2df/bundler/lib/bundler/digest.rb#L50) https://github.com/rubygems/rubygems/commit/c8de819fee
-rw-r--r--spec/bundler/bundler/digest_spec.rb11
1 files changed, 9 insertions, 2 deletions
diff --git a/spec/bundler/bundler/digest_spec.rb b/spec/bundler/bundler/digest_spec.rb
index d6bb043fd0..841cc0259e 100644
--- a/spec/bundler/bundler/digest_spec.rb
+++ b/spec/bundler/bundler/digest_spec.rb
@@ -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