From 43e925090b6cf33b889904f8b795f4583b20a59b Mon Sep 17 00:00:00 2001 From: Nishant Patel <91441876+nishantactivepipe@users.noreply.github.com> Date: Wed, 16 Feb 2022 16:59:28 +1100 Subject: [PATCH] [ruby/open-uri] fix: added test case that validates that bad TLS version is silently ignored https://github.com/ruby/open-uri/commit/4b91b11730 --- test/open-uri/test_ssl.rb | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/test/open-uri/test_ssl.rb b/test/open-uri/test_ssl.rb index a4e20b553f..2d6149e654 100644 --- a/test/open-uri/test_ssl.rb +++ b/test/open-uri/test_ssl.rb @@ -92,6 +92,26 @@ class TestOpenURISSL } end + def test_validation_ssl_version + with_https {|srv, dr, url| + setup_validation(srv, dr) + URI.open("#{url}/data", :ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE, :ssl_version => :TLSv1_2) {|f| + assert_equal("200", f.status[0]) + assert_equal("ddd", f.read) + } + } + end + + def test_validate_bad_ssl_version_silently + with_https {|srv, dr, url| + setup_validation(srv, dr) + URI.open("#{url}/data", :ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE, :ssl_version => :TLS_no_such_version) {|f| + assert_equal("200", f.status[0]) + assert_equal("ddd", f.read) + } + } + end + def test_validation_failure unless /mswin|mingw/ =~ RUBY_PLATFORM # on Windows, Errno::ECONNRESET will be raised, and it'll be eaten by @@ -107,16 +127,6 @@ class TestOpenURISSL } end - def test_validation_ssl_version - with_https {|srv, dr, url| - setup_validation(srv, dr) - URI.open("#{url}/data", :ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE, :ssl_version => :TLSv1_2) {|f| - assert_equal("200", f.status[0]) - assert_equal("ddd", f.read) - } - } - end - def with_https_proxy(proxy_log_tester=lambda {|proxy_log, proxy_access_log| assert_equal([], proxy_log) }) proxy_log = [] proxy_logger = WEBrick::Log.new(proxy_log, WEBrick::BasicLog::WARN)