[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
This commit is contained in:
parent
a8b36314ec
commit
5791c93f8e
@ -348,27 +348,27 @@ class OpenSSL::TestSSL < OpenSSL::SSLTestCase
|
|||||||
empty_store = OpenSSL::X509::Store.new
|
empty_store = OpenSSL::X509::Store.new
|
||||||
|
|
||||||
# Valid certificate, SSL_VERIFY_PEER
|
# 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 {
|
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 }
|
server_connect(port, ctx) { |ssl| ssl.puts("abc"); ssl.gets }
|
||||||
}
|
}
|
||||||
|
|
||||||
# Invalid certificate, SSL_VERIFY_NONE
|
# 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 {
|
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 }
|
server_connect(port, ctx) { |ssl| ssl.puts("abc"); ssl.gets }
|
||||||
}
|
}
|
||||||
|
|
||||||
# Invalid certificate, SSL_VERIFY_PEER
|
# Invalid certificate, SSL_VERIFY_PEER
|
||||||
assert_handshake_error {
|
ctx = OpenSSL::SSL::SSLContext.new
|
||||||
ctx = OpenSSL::SSL::SSLContext.new
|
ctx.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
||||||
ctx.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
ctx.cert_store = empty_store
|
||||||
ctx.cert_store = empty_store
|
assert_raise(OpenSSL::SSL::SSLError) {
|
||||||
server_connect(port, ctx) { |ssl| ssl.puts("abc"); ssl.gets }
|
server_connect(port, ctx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user