From 355f1ddb0c47791f529488b7bcc78aa97c09f243 Mon Sep 17 00:00:00 2001 From: John Nunemaker Date: Sun, 15 Apr 2012 23:13:48 -0400 Subject: [PATCH] Cleanup ssl test helper. --- spec/support/ssl_test_helper.rb | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/spec/support/ssl_test_helper.rb b/spec/support/ssl_test_helper.rb index 8783111..a29ab4a 100644 --- a/spec/support/ssl_test_helper.rb +++ b/spec/support/ssl_test_helper.rb @@ -1,21 +1,26 @@ module HTTParty module SSLTestHelper def ssl_verify_test(mode, ca_basename, server_cert_filename) - test_server = nil + 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 + 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__))) + 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__)), + }) 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 + HTTParty.get("https://localhost:#{test_server.port}/", options) ensure test_server.stop if test_server end