Sha256: 83fd0b83ae16fb49284bb69570429e4f6be59e12ff77f4f0de04ec1b4f450182

Contents?: true

Size: 1.51 KB

Versions: 16

Compression:

Stored size: 1.51 KB

Contents

require 'pathname'

module HTTParty
  module SSLTestHelper
    def ssl_verify_test(mode, ca_basename, server_cert_filename, options = {})
      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)
        else
          return HTTParty.get("https://localhost:#{test_server.port}/", options)
        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)
    ensure
      test_server.stop if test_server
    end
  end
end

Version data entries

16 entries across 15 versions & 5 rubygems

Version Path
alloy_sdk-0.1.0 vendor/bundle/ruby/3.0.0/gems/httparty-0.13.1/spec/support/ssl_test_helper.rb
alloy_sdk-0.1.0 vendor/bundle/ruby/2.6.0/gems/httparty-0.13.1/spec/support/ssl_test_helper.rb
allegro_api_client-0.0.9 gems/ruby/2.1.0/gems/httparty-0.13.1/spec/support/ssl_test_helper.rb
allegro_api_client-0.0.8 gems/ruby/2.1.0/gems/httparty-0.13.1/spec/support/ssl_test_helper.rb
allegro_api_client-0.0.7 gems/ruby/2.1.0/gems/httparty-0.13.1/spec/support/ssl_test_helper.rb
asana2flowdock-1.0.0 vendor/bundle/ruby/1.9.1/gems/httparty-0.13.1/spec/support/ssl_test_helper.rb
allegro_api_client-0.0.6 gems/ruby/2.1.0/gems/httparty-0.13.1/spec/support/ssl_test_helper.rb
allegro_api_client-0.0.5 gems/ruby/2.1.0/gems/httparty-0.13.1/spec/support/ssl_test_helper.rb
allegro_api_client-0.0.4 gems/ruby/2.1.0/gems/httparty-0.13.1/spec/support/ssl_test_helper.rb
allegro_api_client-0.0.3 gems/ruby/2.1.0/gems/httparty-0.13.1/spec/support/ssl_test_helper.rb
allegro_api_client-0.0.2 gems/ruby/2.1.0/gems/httparty-0.13.1/spec/support/ssl_test_helper.rb
allegro_api_client-0.0.1 gems/ruby/2.1.0/gems/httparty-0.13.1/spec/support/ssl_test_helper.rb
httparty-0.13.1 spec/support/ssl_test_helper.rb
yoyle439587298-0.13.0 spec/support/ssl_test_helper.rb
httparty-0.13.0 spec/support/ssl_test_helper.rb
httparty-0.12.0 spec/support/ssl_test_helper.rb