Sha256: 2b724a1cf66983de4ad12a1be8689a4e9e5f2dcc27ab82ec691d3f25811e4097

Contents?: true

Size: 1.52 KB

Versions: 1

Compression:

Stored size: 1.52 KB

Contents

require 'pathname'

module HTTParty
  module SSLTestHelper
    def ssl_verify_test(mode, ca_basename, server_cert_filename, options = {}, &block)
      options = {
        format:  :json,
        timeout: 30
      }.merge(options)

      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.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, &block)
        else
          return HTTParty.get("https://localhost:#{test_server.port}/", options, &block)
        end
      ensure
        test_server.stop if test_server
      end

      test_server = SSLTestServer.new({
        rsa_key: path.join('server.key').read,
        cert:    path.join(server_cert_filename).read
      })

      test_server.start

      HTTParty.get("https://localhost:#{test_server.port}/", options, &block)
    ensure
      test_server.stop if test_server
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
httparty-0.17.0 spec/support/ssl_test_helper.rb