mirror of
https://github.com/jnunemaker/httparty
synced 2023-03-27 23:23:07 -04:00
Cleanup ssl test helper.
This commit is contained in:
parent
0d9d4f67ff
commit
cb79fe9ce5
1 changed files with 16 additions and 11 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue