Skip to content

Commit

Permalink
Support verify_hostname (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanmb authored Sep 16, 2024
1 parent 2d35fce commit 77febb6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion faraday-net_http_persistent.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 3 additions & 2 deletions lib/faraday/adapter/net_http_persistent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down
17 changes: 13 additions & 4 deletions spec/faraday/adapter/net_http_persistent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit 77febb6

Please sign in to comment.