[前][次][番号順一覧][スレッド一覧]

ruby-changes:72044

From: David <ko1@a...>
Date: Thu, 2 Jun 2022 22:23:56 +0900 (JST)
Subject: [ruby-changes:72044] eb5a01970f (master): [rubygems/rubygems] Add test cases from SHA1 RFC and improve test failure message

https://git.ruby-lang.org/ruby.git/commit/?id=eb5a01970f

From eb5a01970ffd7a84029cf7d541c942418a2d8f44 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?David=20Rodr=C3=ADguez?= <deivid.rodriguez@r...>
Date: Thu, 2 Jun 2022 12:08:05 +0200
Subject: [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
---
 spec/bundler/bundler/digest_spec.rb | 11 +++++++++--
 1 file 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 https://github.com/ruby/ruby/blob/trunk/spec/bundler/bundler/digest_spec.rb#L9
     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
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]