2010-07-08 22:21:38 -04:00
|
|
|
module HTTParty
|
|
|
|
module SSLTestHelper
|
|
|
|
def ssl_verify_test(mode, ca_basename, server_cert_filename)
|
2012-04-15 23:13:48 -04:00
|
|
|
options = {
|
|
|
|
:format => :json,
|
|
|
|
:timeout => 30,
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2010-07-08 22:21:38 -04:00
|
|
|
begin
|
2012-04-15 23:13:48 -04:00
|
|
|
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__)),
|
|
|
|
})
|
2012-04-15 22:51:39 -04:00
|
|
|
|
2010-07-08 22:21:38 -04:00
|
|
|
test_server.start
|
|
|
|
|
2012-04-15 23:13:48 -04:00
|
|
|
HTTParty.get("https://localhost:#{test_server.port}/", options)
|
2010-07-08 22:21:38 -04:00
|
|
|
ensure
|
|
|
|
test_server.stop if test_server
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|