require 'net/http' require 'test/unit' DOMAIN = 'localhost' CONFIG_ITEMS = { tls_1_2: { host: "tls-12.#{DOMAIN}", port: 44_312 }, tls_1_3: { host: "tls-13.#{DOMAIN}", port: 44_313 } }.freeze CA_FILE = 'test.crt' class TestRubyOpenSSLTLSMin < Test::Unit::TestCase def test_connection_to_tls_1_2_server_to_fail assert_raise_with_message(OpenSSL::SSL::SSLError, /tlsv1 alert protocol version/) do connect(CONFIG_ITEMS[:tls_1_2][:host], CONFIG_ITEMS[:tls_1_2][:port]) end end def test_onnection_to_tls_1_3_server_to_pass assert(connect(CONFIG_ITEMS[:tls_1_3][:host], CONFIG_ITEMS[:tls_1_3][:port])) end def connect(host, port) uri = URI("https://#{host}") Net::HTTP.start(host, port, use_ssl: true, ca_file: CA_FILE) do |http| http.get(uri) end end end