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

48 lines
1.5 KiB
Ruby
Raw Normal View History

2012-04-15 23:29:36 -04:00
require 'pathname'
module HTTParty
module SSLTestHelper
def ssl_verify_test(mode, ca_basename, server_cert_filename, options = {})
2012-04-15 23:13:48 -04:00
options = {
format: :json,
2015-04-17 19:25:08 -04:00
timeout: 30
}.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(
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)
return HTTParty.get("https://localhost:#{test_server.port}/", options)
2012-04-15 22:51:39 -04:00
else
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({
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
2012-04-15 23:29:36 -04:00
HTTParty.get("https://localhost:#{test_server.port}/", options)
ensure
test_server.stop if test_server
end
end
end