From 9d7667ff3e9697d114d810e697ed4b3e62b97345 Mon Sep 17 00:00:00 2001 From: John Nunemaker Date: Sun, 15 Apr 2012 22:51:39 -0400 Subject: [PATCH] Formatting cleanup. --- spec/support/ssl_test_helper.rb | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/spec/support/ssl_test_helper.rb b/spec/support/ssl_test_helper.rb index 702e1b1..213a51d 100644 --- a/spec/support/ssl_test_helper.rb +++ b/spec/support/ssl_test_helper.rb @@ -3,16 +3,23 @@ require 'pathname' module HTTParty module SSLTestHelper def ssl_verify_test(mode, ca_basename, server_cert_filename) - path = Pathname(__FILE__).join('..', '..', 'fixtures', 'ssl', 'generated').expand_path - options = { - :format => :json, - :timeout => 30, - } + test_server = nil + 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__))) - if mode - ca_path = path.join(ca_basename) - raise ArgumentError.new("#{ca_path} does not exist") unless ca_path.exist? - options[mode] = ca_path.to_s + 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}/", :format => :json, :timeout => 30, mode => ca_path) + else + return HTTParty.get("https://localhost:#{test_server.port}/", :format => :json, :timeout => 30) + end + ensure + test_server.stop if test_server end test_server = SSLTestServer.new({