diff --git a/lib/faraday/adapter/net_http_persistent.rb b/lib/faraday/adapter/net_http_persistent.rb index 0f43f8cff..1cf1a295d 100644 --- a/lib/faraday/adapter/net_http_persistent.rb +++ b/lib/faraday/adapter/net_http_persistent.rb @@ -63,16 +63,22 @@ def perform_request(http, env) raise end + SSL_CONFIGURATIONS = { + certificate: :client_cert, + private_key: :client_key, + ca_file: :ca_file, + ssl_version: :version, + min_version: :min_version, + max_version: :max_version + }.freeze + def configure_ssl(http, ssl) http_set(http, :verify_mode, ssl_verify_mode(ssl)) http_set(http, :cert_store, ssl_cert_store(ssl)) - http_set(http, :certificate, ssl[:client_cert]) if ssl[:client_cert] - http_set(http, :private_key, ssl[:client_key]) if ssl[:client_key] - http_set(http, :ca_file, ssl[:ca_file]) if ssl[:ca_file] - http_set(http, :ssl_version, ssl[:version]) if ssl[:version] - http_set(http, :min_version, ssl[:min_version]) if ssl[:min_version] - http_set(http, :max_version, ssl[:max_version]) if ssl[:max_version] + SSL_CONFIGURATIONS + .select { |_, key| ssl[key] } + .each { |target, key| http_set(http, target, ssl[key]) } end def http_set(http, attr, value) diff --git a/spec/faraday/adapter/net_http_persistent_spec.rb b/spec/faraday/adapter/net_http_persistent_spec.rb index 77746ccb7..9a80418a3 100644 --- a/spec/faraday/adapter/net_http_persistent_spec.rb +++ b/spec/faraday/adapter/net_http_persistent_spec.rb @@ -40,4 +40,26 @@ # `pool` is only present in net_http_persistent >= 3.0 expect(http.pool.size).to eq(5) if http.respond_to?(:pool) end + + context 'min_version' do + let(:conn_options) do + { + headers: { 'X-Faraday-Adapter' => adapter }, + ssl: { + min_version: :TLS1_2 + } + } + end + + it 'allows to set min_version in SSL settings' do + url = URI('https://example.com') + + adapter = described_class.new(nil) + + http = adapter.send(:net_http_connection, url: url, request: {}) + + # `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) + end + end end