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

25 lines
970 B
Ruby
Raw Normal View History

module HTTParty
module SSLTestHelper
def ssl_verify_test(mode, ca_basename, server_cert_filename)
test_server = nil
begin
test_server = SSLTestServer.new(
:rsa_key => File.read(File.expand_path("../../fixtures/ssl/generated/server.key", __FILE__)),
2012-04-15 22:51:39 -04:00
: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)
2012-04-15 22:51:39 -04:00
return HTTParty.get("https://localhost:#{test_server.port}/", :format => :json, :timeout => 30, mode => ca_path)
else
2012-04-15 22:51:39 -04:00
return HTTParty.get("https://localhost:#{test_server.port}/", :format => :json, :timeout => 30)
end
ensure
test_server.stop if test_server
end
end
end
end