diff options
Diffstat (limited to 'spec/bundler/bundler/digest_spec.rb')
-rw-r--r-- | spec/bundler/bundler/digest_spec.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/spec/bundler/bundler/digest_spec.rb b/spec/bundler/bundler/digest_spec.rb new file mode 100644 index 0000000000..f876827964 --- /dev/null +++ b/spec/bundler/bundler/digest_spec.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +require "openssl" +require "bundler/digest" + +RSpec.describe Bundler::Digest do + context "SHA1" do + subject { Bundler::Digest } + let(:stdlib) { OpenSSL::Digest::SHA1 } + + it "is compatible with stdlib" do + random_strings = ["foo", "skfjsdlkfjsdf", "3924m", "ldskfj"] + + # https://www.rfc-editor.org/rfc/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 +end |