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-linuxfr-0.14.23 test/html/pipeline/camo_filter_test.rb
html-pipeline-linuxfr-0.14.22 test/html/pipeline/camo_filter_test.rb
html-pipeline-linuxfr-0.14.21 test/html/pipeline/camo_filter_test.rb
html-pipeline-linuxfr-0.14.20 test/html/pipeline/camo_filter_test.rb
html-pipeline-linuxfr-0.14.19 test/html/pipeline/camo_filter_test.rb
html-pipeline-linuxfr-0.14.18 test/html/pipeline/camo_filter_test.rb
html-pipeline-linuxfr-0.14.17 test/html/pipeline/camo_filter_test.rb
html-pipeline-linuxfr-0.14.16 test/html/pipeline/camo_filter_test.rb
html-pipeline-linuxfr-0.14.15 test/html/pipeline/camo_filter_test.rb
html-pipeline-linuxfr-0.14.14 test/html/pipeline/camo_filter_test.rb
html-pipeline-linuxfr-0.14.13 test/html/pipeline/camo_filter_test.rb
html-pipeline-linuxfr-0.14.12 test/html/pipeline/camo_filter_test.rb
html-pipeline-linuxfr-0.14.11 test/html/pipeline/camo_filter_test.rb
html-pipeline-1.1.0 test/html/pipeline/camo_filter_test.rb
html-pipeline-linuxfr-0.14.10 test/html/pipeline/camo_filter_test.rb
html-pipeline-linuxfr-0.14.9 test/html/pipeline/camo_filter_test.rb
html-pipeline-1.0.0 test/html/pipeline/camo_filter_test.rb
html-pipeline-linuxfr-0.14.8 test/html/pipeline/camo_filter_test.rb
html-pipeline-linuxfr-0.14.7 test/html/pipeline/camo_filter_test.rb
html-pipeline-0.3.1 test/html/pipeline/camo_filter_test.rb