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))c8de819fee
This commit is contained in:
		
							parent
							
								
									1d924ae410
								
							
						
					
					
						commit
						eb5a01970f
					
				
					 1 changed files with 9 additions and 2 deletions
				
			
		| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue