Skip to content

Commit dd39c04

Browse files
committed
feat: allow SSL verification to be disabled by setting environment variable PACT_DISABLE_SSL_VERIFICATION=true
1 parent 1c8d9fb commit dd39c04

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

lib/pact/consumer_contract/pact_file.rb

+15-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,13 @@ def prepare_request(uri, options)
108108
http.use_ssl = (uri.scheme == 'https')
109109
http.ca_file = ENV['SSL_CERT_FILE'] if ENV['SSL_CERT_FILE'] && ENV['SSL_CERT_FILE'] != ''
110110
http.ca_path = ENV['SSL_CERT_DIR'] if ENV['SSL_CERT_DIR'] && ENV['SSL_CERT_DIR'] != ''
111-
http.set_debug_output(Pact::Http::AuthorizationHeaderRedactor.new(Pact.configuration.output_stream)) if options[:verbose]
111+
http.set_debug_output(Pact::Http::AuthorizationHeaderRedactor.new(Pact.configuration.output_stream)) if verbose?(options)
112+
if disable_ssl_verification?
113+
if verbose?(options)
114+
Pact.configuration.output_stream.puts("SSL verification is disabled")
115+
end
116+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
117+
end
112118
http
113119
end
114120

@@ -139,5 +145,13 @@ def delay_retry(count)
139145
def windows_safe(uri)
140146
uri.start_with?("http") ? uri : uri.gsub("\\", File::SEPARATOR)
141147
end
148+
149+
def verbose?(options)
150+
options[:verbose] || ENV['VERBOSE'] == 'true'
151+
end
152+
153+
def disable_ssl_verification?
154+
ENV['PACT_DISABLE_SSL_VERIFICATION'] == 'true' || ENV['PACT_BROKER_DISABLE_SSL_VERIFICATION'] == 'true'
155+
end
142156
end
143157
end

0 commit comments

Comments
 (0)