summaryrefslogtreecommitdiff
path: root/spec/ruby/library/openssl/kdf
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2025-11-07 00:45:10 +0900
committerKazuki Yamaguchi <k.github.xq3nw23egf7xvpit@rhe.jp>2025-11-06 08:19:28 -0800
commitf7e7443aaa9bdebefbdbfbd57cdda3a0d7febfdd (patch)
tree163dc9681a2815f1e1a1ea459d01529cbf754e23 /spec/ruby/library/openssl/kdf
parent87ae631b406ee6996558544f9781abbac697f7a9 (diff)
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.
Diffstat (limited to 'spec/ruby/library/openssl/kdf')
-rw-r--r--spec/ruby/library/openssl/kdf/pbkdf2_hmac_spec.rb20
1 files changed, 7 insertions, 13 deletions
diff --git a/spec/ruby/library/openssl/kdf/pbkdf2_hmac_spec.rb b/spec/ruby/library/openssl/kdf/pbkdf2_hmac_spec.rb
index 40f8597275..1112972060 100644
--- a/spec/ruby/library/openssl/kdf/pbkdf2_hmac_spec.rb
+++ b/spec/ruby/library/openssl/kdf/pbkdf2_hmac_spec.rb
@@ -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