From 35b8c37c679fab367570c4b679551e39ae85f381 Mon Sep 17 00:00:00 2001 From: dylanlacey Date: Tue, 5 May 2020 14:38:08 +1000 Subject: [PATCH 1/2] (Ruby) Move SSL Config for Default HTTP client into own method. This change moves the SSL option configuration out of `http` and into `ssl_options`. Doing so allows subclasses to create their own SSL config, without having to clone `http` (and thus leading to less ongoing maintenance). Primarily, this change allows for the `Net::HTTP::Persistent` shim to only set `use_ssl` to true where needed; Newer releases of the library manage their own SSL config. --- rb/lib/selenium/webdriver/remote/http/default.rb | 14 +++++++++----- .../selenium/webdriver/remote/http/persistent.rb | 8 ++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/rb/lib/selenium/webdriver/remote/http/default.rb b/rb/lib/selenium/webdriver/remote/http/default.rb index bdc54968e1664..f7dc74e0892d1 100644 --- a/rb/lib/selenium/webdriver/remote/http/default.rb +++ b/rb/lib/selenium/webdriver/remote/http/default.rb @@ -50,11 +50,8 @@ def close def http @http ||= begin http = new_http_client - if server_url.scheme == 'https' - http.use_ssl = true - http.verify_mode = OpenSSL::SSL::VERIFY_NONE - end - + set_ssl_options(new_http_client) if server_url.scheme == 'https' + # Defaulting open_timeout to nil to be consistent with Ruby 2.2 and earlier. http.open_timeout = open_timeout http.read_timeout = read_timeout if read_timeout @@ -64,6 +61,8 @@ def http end end + + def start(http) http.start end @@ -139,6 +138,11 @@ def new_http_client end end + def set_ssl_options(client) + client.use_ssl = true + client.verify_mode = OpenSSL::SSL::VERIFY_NONE + end + def proxy @proxy ||= begin proxy = ENV['http_proxy'] || ENV['HTTP_PROXY'] diff --git a/rb/lib/selenium/webdriver/remote/http/persistent.rb b/rb/lib/selenium/webdriver/remote/http/persistent.rb index 10ea3fa2042bf..642210df72775 100644 --- a/rb/lib/selenium/webdriver/remote/http/persistent.rb +++ b/rb/lib/selenium/webdriver/remote/http/persistent.rb @@ -49,6 +49,14 @@ def new_http_client Net::HTTP::Persistent.new name: 'webdriver', proxy: proxy end + def set_ssl_options(client) + # Net::HTTP::Persistent manages its own SSL config for older version + if client.respond_to? :use_ssl= + client.use_ssl = true + client.verify_mode = OpenSSL::SSL::VERIFY_NONE + end + end + def response_for(request) http.request server_url, request end From 5cce7bb412cb03cf3caa75bfb1cb522500dbc6e6 Mon Sep 17 00:00:00 2001 From: dylanlacey Date: Tue, 5 May 2020 15:04:28 +1000 Subject: [PATCH 2/2] Clean up extra line space in default.rb --- rb/lib/selenium/webdriver/remote/http/default.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/rb/lib/selenium/webdriver/remote/http/default.rb b/rb/lib/selenium/webdriver/remote/http/default.rb index f7dc74e0892d1..68f66fea219ff 100644 --- a/rb/lib/selenium/webdriver/remote/http/default.rb +++ b/rb/lib/selenium/webdriver/remote/http/default.rb @@ -61,8 +61,6 @@ def http end end - - def start(http) http.start end