mirror of
https://github.com/ruby/ruby.git
synced 2026-01-27 12:34:21 +00:00
Adjust OpenSSL specs for digest algorithm lookup
https://github.com/ruby/openssl/pull/958 changed the common logic for digest algorithm lookup: - If the argument is neither an OpenSSL::Digest instance nor a String, it is now implicitly converted to String with #to_str. This is consistent with algorithm name lookup logic in ruby/openssl for pkeys and ciphers. - If the name is not recognized, OpenSSL::Digest::DigestError is raised instead of RuntimeError. Update the specs accordingly: - Remove specs that expect #to_str not to be called. - Relax regexps matching TypeError messages. - Expect OpenSSL::Digest::DigestError instead of RuntimeError for ruby/openssl 4.0.0 and later.
This commit is contained in:
parent
87ae631b40
commit
f7e7443aaa
Notes:
git
2025-11-06 16:19:59 +00:00
@ -23,18 +23,14 @@ describe "OpenSSL::Digest#initialize" do
|
||||
OpenSSL::Digest.new("sha512").name.should == "SHA512"
|
||||
end
|
||||
|
||||
it "throws an error when called with an unknown digest" do
|
||||
-> { OpenSSL::Digest.new("wd40") }.should raise_error(RuntimeError, /Unsupported digest algorithm \(wd40\)/)
|
||||
version_is OpenSSL::VERSION, "4.0.0" do
|
||||
it "throws an error when called with an unknown digest" do
|
||||
-> { OpenSSL::Digest.new("wd40") }.should raise_error(OpenSSL::Digest::DigestError, /wd40/)
|
||||
end
|
||||
end
|
||||
|
||||
it "cannot be called with a symbol" do
|
||||
-> { OpenSSL::Digest.new(:SHA1) }.should raise_error(TypeError, /wrong argument type Symbol/)
|
||||
end
|
||||
|
||||
it "does not call #to_str on the argument" do
|
||||
name = mock("digest name")
|
||||
name.should_not_receive(:to_str)
|
||||
-> { OpenSSL::Digest.new(name) }.should raise_error(TypeError, /wrong argument type/)
|
||||
-> { OpenSSL::Digest.new(:SHA1) }.should raise_error(TypeError)
|
||||
end
|
||||
end
|
||||
|
||||
@ -62,7 +58,7 @@ describe "OpenSSL::Digest#initialize" do
|
||||
end
|
||||
|
||||
it "cannot be called with a digest class" do
|
||||
-> { OpenSSL::Digest.new(OpenSSL::Digest::SHA1) }.should raise_error(TypeError, /wrong argument type Class/)
|
||||
-> { OpenSSL::Digest.new(OpenSSL::Digest::SHA1) }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
context "when called without an initial String argument" do
|
||||
|
||||
@ -107,21 +107,15 @@ describe "OpenSSL::KDF.pbkdf2_hmac" do
|
||||
it "raises a TypeError when hash is neither a String nor an OpenSSL::Digest" do
|
||||
-> {
|
||||
OpenSSL::KDF.pbkdf2_hmac("secret", **@defaults, hash: Object.new)
|
||||
}.should raise_error(TypeError, "wrong argument type Object (expected OpenSSL/Digest)")
|
||||
}.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "raises a TypeError when hash is neither a String nor an OpenSSL::Digest, it does not try to call #to_str" do
|
||||
hash = mock("hash")
|
||||
hash.should_not_receive(:to_str)
|
||||
-> {
|
||||
OpenSSL::KDF.pbkdf2_hmac("secret", **@defaults, hash: hash)
|
||||
}.should raise_error(TypeError, "wrong argument type MockObject (expected OpenSSL/Digest)")
|
||||
end
|
||||
|
||||
it "raises a RuntimeError for unknown digest algorithms" do
|
||||
-> {
|
||||
OpenSSL::KDF.pbkdf2_hmac("secret", **@defaults, hash: "wd40")
|
||||
}.should raise_error(RuntimeError, /Unsupported digest algorithm \(wd40\)/)
|
||||
version_is OpenSSL::VERSION, "4.0.0" do
|
||||
it "raises a OpenSSL::Digest::DigestError for unknown digest algorithms" do
|
||||
-> {
|
||||
OpenSSL::KDF.pbkdf2_hmac("secret", **@defaults, hash: "wd40")
|
||||
}.should raise_error(OpenSSL::Digest::DigestError, /wd40/)
|
||||
end
|
||||
end
|
||||
|
||||
it "treats salt as a required keyword" do
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user