From 77febb639078061517ddcaabb1766837c9d7f164 Mon Sep 17 00:00:00 2001 From: Stefan Budeanu Date: Mon, 16 Sep 2024 09:57:28 -0400 Subject: [PATCH] Support verify_hostname (#25) --- faraday-net_http_persistent.gemspec | 2 +- lib/faraday/adapter/net_http_persistent.rb | 5 +++-- .../faraday/adapter/net_http_persistent_spec.rb | 17 +++++++++++++---- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/faraday-net_http_persistent.gemspec b/faraday-net_http_persistent.gemspec index aba0c0c..bc1c31a 100644 --- a/faraday-net_http_persistent.gemspec +++ b/faraday-net_http_persistent.gemspec @@ -25,5 +25,5 @@ Gem::Specification.new do |spec| spec.require_paths = ["lib"] spec.add_dependency "faraday", "~> 2.5" - spec.add_dependency "net-http-persistent", "~> 4.0" + spec.add_dependency "net-http-persistent", ">= 4.0.4", "< 5" end diff --git a/lib/faraday/adapter/net_http_persistent.rb b/lib/faraday/adapter/net_http_persistent.rb index b601bd2..4396c70 100644 --- a/lib/faraday/adapter/net_http_persistent.rb +++ b/lib/faraday/adapter/net_http_persistent.rb @@ -183,7 +183,8 @@ def request_with_wrapped_block(http, env) ca_file: :ca_file, ssl_version: :version, min_version: :min_version, - max_version: :max_version + max_version: :max_version, + verify_hostname: :verify_hostname }.freeze def configure_ssl(http, ssl) @@ -193,7 +194,7 @@ def configure_ssl(http, ssl) http_set(http, :cert_store, ssl_cert_store(ssl)) SSL_CONFIGURATIONS - .select { |_, key| ssl[key] } + .select { |_, key| !ssl[key].nil? } .each { |target, key| http_set(http, target, ssl[key]) } end diff --git a/spec/faraday/adapter/net_http_persistent_spec.rb b/spec/faraday/adapter/net_http_persistent_spec.rb index f7512da..3fea6ca 100644 --- a/spec/faraday/adapter/net_http_persistent_spec.rb +++ b/spec/faraday/adapter/net_http_persistent_spec.rb @@ -37,8 +37,18 @@ http = adapter.send(:connection, url: url, request: {}) - # `pool` is only present in net_http_persistent >= 3.0 - expect(http.pool.size).to eq(5) if http.respond_to?(:pool) + expect(http.pool.size).to eq(5) + end + + it "allows to set verify_hostname in SSL settings to false" do + url = URI("https://example.com") + + adapter = described_class.new(nil) + + http = adapter.send(:connection, url: url, request: {}) + adapter.send(:configure_ssl, http, verify_hostname: false) + + expect(http.verify_hostname).to eq(false) end context "min_version" do @@ -50,8 +60,7 @@ http = adapter.send(:connection, url: url, request: {}) adapter.send(:configure_ssl, http, min_version: :TLS1_2) - # `min_version` is only present in net_http_persistent >= 3.1 (UNRELEASED) - expect(http.min_version).to eq(:TLS1_2) if http.respond_to?(:min_version) + expect(http.min_version).to eq(:TLS1_2) end end end