summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorAndy Brody <git@abrody.com>2019-07-27 03:28:14 -0400
committerAndy Brody <git@abrody.com>2019-07-27 03:38:07 -0400
commitdeeec0483d074bacd6861c4028743c41c5e2cd0d (patch)
treebaed22e35e9d1f4cf7eddcb2acdbbfeb9a9dcd35 /test
parent4fb4c3f73d9acf6b2d1ed179ec85768ed5af663e (diff)
downloadruby-openssl-deeec0483d074bacd6861c4028743c41c5e2cd0d.tar.gz
x509name: return nil for wrong type in Name#<=>
Previously, OpenSSL::X509::Name#{cmp,<=>} would raise a TypeError if you attempted to compare a Name object with another object of a different type. Most Ruby classes instead return nil in this situation. The old behavior resulted in some strange outcomes: >> n1 = OpenSSL::X509::Name.new >> 'abc' == n1 => false >> n1 == 'abc' TypeError: wrong argument type String (expected OpenSSL/X509/NAME) With the new behavior, cmp/<=> will return nil if the other object is not an X509::Name instead of raising an error. This allows `==` to also return false instead of raising an error for type mismatches. New behavior: >> n1 = OpenSSL::X509::Name.new >> n1 == 'abc' => false >> n1 <=> 'abc' => nil
Diffstat (limited to 'test')
-rw-r--r--test/test_x509name.rb6
1 files changed, 6 insertions, 0 deletions
diff --git a/test/test_x509name.rb b/test/test_x509name.rb
index e31b5e29..531af19f 100644
--- a/test/test_x509name.rb
+++ b/test/test_x509name.rb
@@ -402,6 +402,9 @@ class OpenSSL::TestX509Name < OpenSSL::TestCase
n2 = OpenSSL::X509::Name.parse_rfc2253 'CN=a'
assert_equal n1, n2
+
+ assert_equal false, n1 == 'abc'
+ assert_equal false, n2 == nil
end
def test_spaceship
@@ -415,6 +418,9 @@ class OpenSSL::TestX509Name < OpenSSL::TestCase
assert_equal -1, n2 <=> n3
assert_equal 1, n3 <=> n1
assert_equal 1, n3 <=> n2
+ assert_equal nil, n1 <=> 'abc'
+ assert_equal nil, n2 <=> 123
+ assert_equal nil, n3 <=> nil
end
def name_hash(name)