2012-04-15 23:29:36 -04:00
|
|
|
require 'pathname'
|
|
|
|
|
2010-07-08 22:21:38 -04:00
|
|
|
module HTTParty
|
|
|
|
module SSLTestHelper
|
2013-08-01 04:32:25 -04:00
|
|
|
def ssl_verify_test(mode, ca_basename, server_cert_filename, options = {})
|
2012-04-15 23:13:48 -04:00
|
|
|
options = {
|
2014-05-15 16:45:32 -04:00
|
|
|
format: :json,
|
2015-04-17 19:25:08 -04:00
|
|
|
timeout: 30
|
2013-08-01 04:32:25 -04:00
|
|
|
}.merge(options)
|
2012-04-15 23:13:48 -04:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2012-04-15 22:51:39 -04:00
|
|
|
begin
|
|
|
|
test_server = SSLTestServer.new(
|
2014-05-15 16:45:32 -04:00
|
|
|
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 23:13:48 -04:00
|
|
|
|
2012-04-15 22:51:39 -04:00
|
|
|
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)
|
2013-08-01 04:32:25 -04:00
|
|
|
return HTTParty.get("https://localhost:#{test_server.port}/", options)
|
2012-04-15 22:51:39 -04:00
|
|
|
else
|
2013-08-01 04:32:25 -04:00
|
|
|
return HTTParty.get("https://localhost:#{test_server.port}/", options)
|
2012-04-15 22:51:39 -04:00
|
|
|
end
|
|
|
|
ensure
|
|
|
|
test_server.stop if test_server
|
2012-04-15 23:13:48 -04:00
|
|
|
end
|
|
|
|
|
2012-04-15 23:29:36 -04:00
|
|
|
test_server = SSLTestServer.new({
|
2014-05-15 16:45:32 -04:00
|
|
|
rsa_key: path.join('server.key').read,
|
2015-04-17 19:25:08 -04:00
|
|
|
cert: path.join(server_cert_filename).read
|
2012-04-15 23:29:36 -04:00
|
|
|
})
|
2012-04-15 22:51:39 -04:00
|
|
|
|
2012-04-15 23:29:36 -04:00
|
|
|
test_server.start
|
2010-07-08 22:21:38 -04:00
|
|
|
|
2012-04-15 23:29:36 -04:00
|
|
|
HTTParty.get("https://localhost:#{test_server.port}/", options)
|
|
|
|
ensure
|
|
|
|
test_server.stop if test_server
|
2010-07-08 22:21:38 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|