From bf1333ddcef6c7f4d52225aa50c2c55e892e3f66 Mon Sep 17 00:00:00 2001 From: mcclenney Date: Thu, 13 Feb 2020 15:16:00 -0600 Subject: [PATCH] feat: use certificates from SSL_CERT_FILE and SSL_CERT_DIR environment variables in HTTP connections --- lib/pact/consumer_contract/pact_file.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/pact/consumer_contract/pact_file.rb b/lib/pact/consumer_contract/pact_file.rb index 8e32201..fa6725e 100644 --- a/lib/pact/consumer_contract/pact_file.rb +++ b/lib/pact/consumer_contract/pact_file.rb @@ -81,7 +81,11 @@ def get_remote(uri, options) request = Net::HTTP::Get.new(uri) request.basic_auth(options[:username], options[:password]) if options[:username] request['Authorization'] = "Bearer #{options[:token]}" if options[:token] - Net::HTTP.start(uri.host, uri.port, :ENV, use_ssl: uri.scheme == 'https') do |http| + http = Net::HTTP.new(uri.host, uri.port, :ENV) + http.use_ssl = (uri.scheme == 'https') + http.ca_file = ENV['SSL_CERT_FILE'] if ENV['SSL_CERT_FILE'] && ENV['SSL_CERT_FILE'] != '' + http.ca_path = ENV['SSL_CERT_DIR'] if ENV['SSL_CERT_DIR'] && ENV['SSL_CERT_DIR'] != '' + http.start do |http| http.open_timeout = options[:open_timeout] || OPEN_TIMEOUT http.read_timeout = options[:read_timeout] || READ_TIMEOUT http.request(request)