1
0
Fork 0
mirror of https://github.com/jnunemaker/httparty synced 2023-03-27 23:23:07 -04:00
httparty/spec/support/ssl_test_helper.rb
Narsimham Chelluri bc551bd1f2 Made SSL connections use the system certificate store by default.
- Set http.verify_mode to OpenSSL::SSL::VERIFY_PEER by default
- Use OpenSSL::X509::Store.new as certificate store unless another is specified

Adapted from Faraday.
See: b25adc0ca6/lib/faraday/adapter/net_http.rb (L100)
2013-08-01 01:32:25 -07:00

47 lines
1.5 KiB
Ruby

require 'pathname'
module HTTParty
module SSLTestHelper
def ssl_verify_test(mode, ca_basename, server_cert_filename, options = {})
options = {
:format => :json,
:timeout => 30,
}.merge(options)
if mode
ca_path = File.expand_path("../../fixtures/ssl/generated/#{ca_basename}", __FILE__)
raise ArgumentError.new("#{ca_path} does not exist") unless File.exist?(ca_path)
options[mode] = ca_path
end
begin
test_server = SSLTestServer.new(
:rsa_key => File.read(File.expand_path("../../fixtures/ssl/generated/server.key", __FILE__)),
:cert => File.read(File.expand_path("../../fixtures/ssl/generated/#{server_cert_filename}", __FILE__)))
test_server.start
if mode
ca_path = File.expand_path("../../fixtures/ssl/generated/#{ca_basename}", __FILE__)
raise ArgumentError.new("#{ca_path} does not exist") unless File.exist?(ca_path)
return HTTParty.get("https://localhost:#{test_server.port}/", options)
else
return HTTParty.get("https://localhost:#{test_server.port}/", options)
end
ensure
test_server.stop if test_server
end
test_server = SSLTestServer.new({
:rsa_key => path.join('server.key').read,
:cert => path.join(server_cert_filename).read,
})
test_server.start
HTTParty.get("https://localhost:#{test_server.port}/", options)
ensure
test_server.stop if test_server
end
end
end