Sha256: 9ce6a9b480b14eba4971145a4c671d05cd79a3b659ec61f7e88761eb039cd5b3

Contents?: true

Size: 1.39 KB

Versions: 43

Compression:

Stored size: 1.39 KB

Contents

require "test_helper"

class HTML::Pipeline::CamoFilterTest < Test::Unit::TestCase
  CamoFilter = HTML::Pipeline::CamoFilter

  def setup
    @asset_proxy_url        = 'https//assets.example.org'
    @asset_proxy_secret_key = 'ssssh-secret'
    @options = {
      :asset_proxy            => @asset_proxy_url,
      :asset_proxy_secret_key => @asset_proxy_secret_key
    }
  end

  def test_camouflaging_http_image_urls
    orig = %(<p><img src="http://twitter.com/img.png"></p>)
    assert_includes 'img src="' + @asset_proxy_url,
      CamoFilter.call(orig, @options).to_s
  end

  def test_rewrites_dotcom_image_urls
    orig = %(<p><img src="http://github.com/img.png"></p>)
    assert_equal "<p><img src=\"https://github.com/img.png\"></p>",
      CamoFilter.call(orig, @options).to_s
  end

  def test_not_camouflaging_https_image_urls
    orig = %(<p><img src="https://foo.com/img.png"></p>)
    assert_doesnt_include 'img src="' + @asset_proxy_url,
      CamoFilter.call(orig, @options).to_s
  end

  def test_handling_images_with_no_src_attribute
    orig = %(<p><img></p>)
    assert_nothing_raised do
      CamoFilter.call(orig, @options).to_s
    end
  end
    
  def test_required_context_validation
    exception = assert_raise(ArgumentError) { 
      CamoFilter.call("", {}) 
    }
    assert_match /:asset_proxy[^_]/, exception.message
    assert_match /:asset_proxy_secret_key/, exception.message
  end
end

Version data entries

43 entries across 43 versions & 4 rubygems

Version Path
html-pipeline-0.3.0 test/html/pipeline/camo_filter_test.rb
html-pipeline-0.2.1 test/html/pipeline/camo_filter_test.rb
html-pipeline-0.2.0 test/html/pipeline/camo_filter_test.rb
html-pipeline-0.1.0 test/html/pipeline/camo_filter_test.rb
html-pipeline-linuxfr-0.14.6 test/html/pipeline/camo_filter_test.rb
html-pipeline-linuxfr-0.14.5 test/html/pipeline/camo_filter_test.rb
html-pipeline-linuxfr-0.14.4 test/html/pipeline/camo_filter_test.rb
html-pipeline-linuxfr-0.14.3 test/html/pipeline/camo_filter_test.rb
html-pipeline-linuxfr-0.14.2 test/html/pipeline/camo_filter_test.rb
html-pipeline-linuxfr-0.14.1 test/html/pipeline/camo_filter_test.rb
html-pipeline-linuxfr-0.14.0 test/html/pipeline/camo_filter_test.rb
html-pipeline-linuxfr-0.0.14 test/html/pipeline/camo_filter_test.rb
html-pipeline-0.0.14 test/html/pipeline/camo_filter_test.rb
html-pipeline-0.0.13 test/html/pipeline/camo_filter_test.rb
geothird-html-pipeline-0.0.12 test/html/pipeline/camo_filter_test.rb
html-pipeline-0.0.12 test/html/pipeline/camo_filter_test.rb
html-pipeline-0.0.11 test/html/pipeline/camo_filter_test.rb
html-pipeline-0.0.10 test/html/pipeline/camo_filter_test.rb
html-pipeline-0.0.8 test/html/pipeline/camo_filter_test.rb
html-pipeline-0.0.7 test/html/pipeline/camo_filter_test.rb