mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
ba9207f301
As mentioned in https://github.com/rails/rails/pull/40770#issuecomment-748347066 we should default to SHA256 where SHA1 is used today. This switches over the ActiveSupport::Digest to use SHA256 for new applications. It also updates the constants to always refer to and use the OpenSSL constants as well, as also discussed in that PR.
27 lines
952 B
Ruby
27 lines
952 B
Ruby
# frozen_string_literal: true
|
|
|
|
require_relative "abstract_unit"
|
|
require "openssl"
|
|
|
|
class DigestTest < ActiveSupport::TestCase
|
|
class InvalidDigest; end
|
|
def test_with_default_hash_digest_class
|
|
assert_equal OpenSSL::Digest::MD5.hexdigest("hello friend"), ActiveSupport::Digest.hexdigest("hello friend")
|
|
end
|
|
|
|
def test_with_custom_hash_digest_class
|
|
original_hash_digest_class = ActiveSupport::Digest.hash_digest_class
|
|
|
|
ActiveSupport::Digest.hash_digest_class = OpenSSL::Digest::SHA1
|
|
digest = ActiveSupport::Digest.hexdigest("hello friend")
|
|
|
|
assert_equal 32, digest.length
|
|
assert_equal OpenSSL::Digest::SHA1.hexdigest("hello friend")[0...32], digest
|
|
ensure
|
|
ActiveSupport::Digest.hash_digest_class = original_hash_digest_class
|
|
end
|
|
|
|
def test_should_raise_argument_error_if_custom_digest_is_missing_hexdigest_method
|
|
assert_raises(ArgumentError) { ActiveSupport::Digest.hash_digest_class = InvalidDigest }
|
|
end
|
|
end
|