diff --git a/lib/pact/hal/http_client.rb b/lib/pact/hal/http_client.rb index 416f5ec9..06e4b13d 100644 --- a/lib/pact/hal/http_client.rb +++ b/lib/pact/hal/http_client.rb @@ -2,6 +2,7 @@ require 'pact/hal/authorization_header_redactor' require 'net/http' require 'rack' +require 'openssl' module Pact module Hal @@ -48,10 +49,16 @@ def create_request uri, http_method, body = nil, headers = {} def perform_request request, uri response = Retry.until_true do http = Net::HTTP.new(uri.host, uri.port, :ENV) - http.set_debug_output(output_stream) if verbose || ENV['VERBOSE'] == 'true' + http.set_debug_output(output_stream) if verbose? 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'] != '' + if ENV['PACT_DISABLE_SSL_VERIFICATION'] == 'true' || ENV['PACT_BROKER_DISABLE_SSL_VERIFICATION'] == 'true' + if verbose? + Pact.configuration.error_stream.puts("Making request without SSL verification") + end + http.verify_mode = OpenSSL::SSL::VERIFY_NONE + end http.start do |http| http.request request end @@ -63,6 +70,10 @@ def output_stream AuthorizationHeaderRedactor.new(Pact.configuration.output_stream) end + def verbose? + verbose || ENV['VERBOSE'] == 'true' + end + class Response < SimpleDelegator def body bod = raw_body