From d0a27f1fc78d6e6be3559323fd1964d7a27cff19 Mon Sep 17 00:00:00 2001 From: kares Date: Fri, 8 Apr 2022 11:54:03 +0200 Subject: [PATCH 1/3] [jruby] handle missing session_new_cb= JRuby can not implement these using available SSL engine APIs --- lib/net/http.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/net/http.rb b/lib/net/http.rb index c858a192..6c2ba1c6 100644 --- a/lib/net/http.rb +++ b/lib/net/http.rb @@ -1036,7 +1036,9 @@ def connect @ssl_context.session_cache_mode = OpenSSL::SSL::SSLContext::SESSION_CACHE_CLIENT | OpenSSL::SSL::SSLContext::SESSION_CACHE_NO_INTERNAL_STORE - @ssl_context.session_new_cb = proc {|sock, sess| @ssl_session = sess } + if @ssl_context.respond_to?(:session_new_cb) # not implemented under JRuby + @ssl_context.session_new_cb = proc {|sock, sess| @ssl_session = sess } + end # Still do the post_connection_check below even if connecting # to IP address From f87f906a79760095eaa5e83fe8c9a6ef42869eb6 Mon Sep 17 00:00:00 2001 From: kares Date: Fri, 8 Apr 2022 11:55:41 +0200 Subject: [PATCH 2/3] [jruby] also do not call dummy session_cache_mode= as it issues a warn-ing message under JRuby --- lib/net/http.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/net/http.rb b/lib/net/http.rb index 6c2ba1c6..db8af1f6 100644 --- a/lib/net/http.rb +++ b/lib/net/http.rb @@ -1033,9 +1033,11 @@ def connect end end @ssl_context.set_params(ssl_parameters) - @ssl_context.session_cache_mode = - OpenSSL::SSL::SSLContext::SESSION_CACHE_CLIENT | - OpenSSL::SSL::SSLContext::SESSION_CACHE_NO_INTERNAL_STORE + unless @ssl_context.session_cache_mode.nil? # a dummy method on JRuby + @ssl_context.session_cache_mode = + OpenSSL::SSL::SSLContext::SESSION_CACHE_CLIENT | + OpenSSL::SSL::SSLContext::SESSION_CACHE_NO_INTERNAL_STORE + end if @ssl_context.respond_to?(:session_new_cb) # not implemented under JRuby @ssl_context.session_new_cb = proc {|sock, sess| @ssl_session = sess } end From 3647dbedd1cf152910df96800bebca5a50cd2092 Mon Sep 17 00:00:00 2001 From: kares Date: Fri, 8 Apr 2022 13:25:50 +0200 Subject: [PATCH 3/3] [test] handle/skip tests on JRuby --- test/net/http/test_https.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/net/http/test_https.rb b/test/net/http/test_https.rb index f4f1959a..72a69af1 100644 --- a/test/net/http/test_https.rb +++ b/test/net/http/test_https.rb @@ -152,12 +152,14 @@ def test_session_reuse end http.start - assert_equal false, http.instance_variable_get(:@socket).io.session_reused? + session_reused = http.instance_variable_get(:@socket).io.session_reused? + assert_false session_reused unless session_reused.nil? # can not detect re-use under JRuby http.get("/") http.finish http.start - assert_equal true, http.instance_variable_get(:@socket).io.session_reused? + session_reused = http.instance_variable_get(:@socket).io.session_reused? + assert_true session_reused unless session_reused.nil? # can not detect re-use under JRuby assert_equal $test_net_http_data, http.get("/").body http.finish end @@ -301,7 +303,7 @@ def test_max_version ex = assert_raise(OpenSSL::SSL::SSLError){ http.request_get("/") {|res| } } - re_msg = /\ASSL_connect returned=1 errno=0 |SSL_CTX_set_max_proto_version/ + re_msg = /\ASSL_connect returned=1 errno=0 |SSL_CTX_set_max_proto_version|No appropriate protocol/ assert_match(re_msg, ex.message) end