From 5791c93f8e16fedfcad861d83e9a54da05fd6154 Mon Sep 17 00:00:00 2001 From: Kazuki Yamaguchi Date: Thu, 6 Feb 2025 23:56:07 +0900 Subject: [PATCH] [ruby/openssl] ssl: refactor test case test_verify_mode_server_cert Minimize the amount of code inside the assert_raise block to avoid accidentally catching a wrong exception. https://github.com/ruby/openssl/commit/5089b2d311 --- test/openssl/test_ssl.rb | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/test/openssl/test_ssl.rb b/test/openssl/test_ssl.rb index 711a94271b..f553cb1d93 100644 --- a/test/openssl/test_ssl.rb +++ b/test/openssl/test_ssl.rb @@ -348,27 +348,27 @@ class OpenSSL::TestSSL < OpenSSL::SSLTestCase empty_store = OpenSSL::X509::Store.new # Valid certificate, SSL_VERIFY_PEER + ctx = OpenSSL::SSL::SSLContext.new + ctx.verify_mode = OpenSSL::SSL::VERIFY_PEER + ctx.cert_store = populated_store assert_nothing_raised { - ctx = OpenSSL::SSL::SSLContext.new - ctx.verify_mode = OpenSSL::SSL::VERIFY_PEER - ctx.cert_store = populated_store server_connect(port, ctx) { |ssl| ssl.puts("abc"); ssl.gets } } # Invalid certificate, SSL_VERIFY_NONE + ctx = OpenSSL::SSL::SSLContext.new + ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE + ctx.cert_store = empty_store assert_nothing_raised { - ctx = OpenSSL::SSL::SSLContext.new - ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE - ctx.cert_store = empty_store server_connect(port, ctx) { |ssl| ssl.puts("abc"); ssl.gets } } # Invalid certificate, SSL_VERIFY_PEER - assert_handshake_error { - ctx = OpenSSL::SSL::SSLContext.new - ctx.verify_mode = OpenSSL::SSL::VERIFY_PEER - ctx.cert_store = empty_store - server_connect(port, ctx) { |ssl| ssl.puts("abc"); ssl.gets } + ctx = OpenSSL::SSL::SSLContext.new + ctx.verify_mode = OpenSSL::SSL::VERIFY_PEER + ctx.cert_store = empty_store + assert_raise(OpenSSL::SSL::SSLError) { + server_connect(port, ctx) } } end