Skip to content

Commit 5089b2d

Browse files
committed
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.
1 parent e8db6ff commit 5089b2d

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

test/openssl/test_ssl.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -348,27 +348,27 @@ def test_verify_mode_server_cert
348348
empty_store = OpenSSL::X509::Store.new
349349

350350
# Valid certificate, SSL_VERIFY_PEER
351+
ctx = OpenSSL::SSL::SSLContext.new
352+
ctx.verify_mode = OpenSSL::SSL::VERIFY_PEER
353+
ctx.cert_store = populated_store
351354
assert_nothing_raised {
352-
ctx = OpenSSL::SSL::SSLContext.new
353-
ctx.verify_mode = OpenSSL::SSL::VERIFY_PEER
354-
ctx.cert_store = populated_store
355355
server_connect(port, ctx) { |ssl| ssl.puts("abc"); ssl.gets }
356356
}
357357

358358
# Invalid certificate, SSL_VERIFY_NONE
359+
ctx = OpenSSL::SSL::SSLContext.new
360+
ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE
361+
ctx.cert_store = empty_store
359362
assert_nothing_raised {
360-
ctx = OpenSSL::SSL::SSLContext.new
361-
ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE
362-
ctx.cert_store = empty_store
363363
server_connect(port, ctx) { |ssl| ssl.puts("abc"); ssl.gets }
364364
}
365365

366366
# Invalid certificate, SSL_VERIFY_PEER
367-
assert_handshake_error {
368-
ctx = OpenSSL::SSL::SSLContext.new
369-
ctx.verify_mode = OpenSSL::SSL::VERIFY_PEER
370-
ctx.cert_store = empty_store
371-
server_connect(port, ctx) { |ssl| ssl.puts("abc"); ssl.gets }
367+
ctx = OpenSSL::SSL::SSLContext.new
368+
ctx.verify_mode = OpenSSL::SSL::VERIFY_PEER
369+
ctx.cert_store = empty_store
370+
assert_raise(OpenSSL::SSL::SSLError) {
371+
server_connect(port, ctx)
372372
}
373373
}
374374
end

0 commit comments

Comments
 (0)