Sha256: 61a3d23998c3c75fef4e97e59ab58997bec5954130bea55de4d36e0143e8a6a2

Contents?: true

Size: 1.82 KB

Versions: 25

Compression:

Stored size: 1.82 KB

Contents

require 'test_helper'
require 'active_support/core_ext/class'

class PostsDataTest < Minitest::Test

  class SSLPoster
    include PostsData

    attr_accessor :logger
  end

  def setup
    @poster = SSLPoster.new
  end

  def test_ssl_request_retried_three_times_by_default
    requester = stubs(:requester)
    requester.expects(:post).raises(Errno::ECONNREFUSED).times(3)
    Connection.any_instance.stubs(:http => requester)

    assert_raises ActiveUtils::ConnectionError do
      @poster.raw_ssl_request(:post, "https://shopify.com", "", {})
    end
  end

  def test_ssl_request_never_retried_if_max_retries_set
    SSLPoster.max_retries = 1
    requester = stubs(:requester)
    requester.expects(:post).raises(Errno::ECONNREFUSED).times(1)
    Connection.any_instance.stubs(:http => requester)

    assert_raises ActiveUtils::ConnectionError do
      @poster.raw_ssl_request(:post, "https://shopify.com", "", {})
    end
  ensure
    SSLPoster.max_retries = ActiveUtils::Connection::MAX_RETRIES
  end

  def test_logger_warns_if_ssl_strict_disabled
    @poster.logger = stub()
    @poster.logger.expects(:warn).with("PostsDataTest::SSLPoster using ssl_strict=false, which is insecure")

    Connection.any_instance.stubs(:request)

    SSLPoster.ssl_strict = false
    @poster.raw_ssl_request(:post, "https://shopify.com", "", {})
  end

  def test_logger_no_warning_if_ssl_strict_enabled
    @poster.logger = stub()
    @poster.logger.stubs(:warn).never
    Connection.any_instance.stubs(:request)

    SSLPoster.ssl_strict = true
    @poster.raw_ssl_request(:post, "https://shopify.com", "", {})
  end

  def test_set_proxy_address_and_port
    SSLPoster.proxy_address = 'http://proxy.example.com'
    SSLPoster.proxy_port = '8888'
    assert_equal @poster.proxy_address, 'http://proxy.example.com'
    assert_equal @poster.proxy_port, '8888'
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
active_utils-3.2.4 test/unit/posts_data_test.rb
active_utils-3.2.3 test/unit/posts_data_test.rb
active_utils-3.2.2 test/unit/posts_data_test.rb
active_utils-3.2.0 test/unit/posts_data_test.rb
active_utils-3.1.0 test/unit/posts_data_test.rb