Skip to content

Commit

Permalink
feat: allow SSL verification to be disabled in the HAL client by sett…
Browse files Browse the repository at this point in the history
…ing the environment variable PACT_DISABLE_SSL_VERIFICATION=true
  • Loading branch information
bethesque committed Oct 1, 2021
1 parent 8a3a2f4 commit ce07d32
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/pact/hal/http_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require 'pact/hal/authorization_header_redactor'
require 'net/http'
require 'rack'
require 'openssl'

module Pact
module Hal
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit ce07d32

Please sign in to comment.