Sha256: 9d6f62c265098d5ca3f2d4dade0efdc96a6463432bae603a3743639bea4e33af

Contents?: true

Size: 1.72 KB

Versions: 15

Compression:

Stored size: 1.72 KB

Contents

require "helper"

class UnitTestHelpers < Loofah::TestCase

  HTML_STRING = "<div>omgwtfbbq</div>"

  describe "Helpers" do
    context ".strip_tags" do
      it "invoke Loofah.fragment.text" do
        mock_doc = Object.new
        mock(Loofah).fragment(HTML_STRING) { mock_doc }
        mock(mock_doc).text

        Loofah::Helpers.strip_tags HTML_STRING
      end
    end

    context ".sanitize" do
      it "invoke Loofah.scrub_fragment(:strip).to_s" do
        mock_doc = Object.new
        mock_node = Object.new
        mock(Loofah).fragment(HTML_STRING) { mock_doc }
        mock(mock_doc).scrub!(:strip) { mock_doc }
        mock(mock_doc).xpath("./form") { [mock_node] }
        mock(mock_node).remove
        mock(mock_doc).to_s

        Loofah::Helpers.sanitize HTML_STRING
      end
    end

    context ".sanitize_css" do
      it "invokes HTML5lib's css scrubber" do
        mock(Loofah::HTML5::Scrub).scrub_css("foobar")
        Loofah::Helpers.sanitize_css("foobar")
      end
    end

    describe "ActionView" do
      describe "FullSanitizer#sanitize" do
        it "calls .strip_tags" do
          mock(Loofah::Helpers).strip_tags("foobar")
          Loofah::Helpers::ActionView::FullSanitizer.new.sanitize "foobar"
        end
      end

      describe "SafeListSanitizer#sanitize" do
        it "calls .sanitize" do
          mock(Loofah::Helpers).sanitize("foobar")
          Loofah::Helpers::ActionView::SafeListSanitizer.new.sanitize "foobar"
        end
      end

      describe "SafeListSanitizer#sanitize_css" do
        it "calls .sanitize_css" do
          mock(Loofah::Helpers).sanitize_css("foobar")
          Loofah::Helpers::ActionView::SafeListSanitizer.new.sanitize_css "foobar"
        end
      end
    end
  end
end

Version data entries

15 entries across 11 versions & 5 rubygems

Version Path
argon-1.3.1 vendor/bundle/ruby/2.7.0/gems/loofah-2.4.0/test/unit/test_helpers.rb
symbolic_enum-1.1.5 vendor/bundle/ruby/2.7.0/gems/loofah-2.4.0/test/unit/test_helpers.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/loofah-2.4.0/test/unit/test_helpers.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/loofah-2.3.0/test/unit/test_helpers.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/loofah-2.3.1/test/unit/test_helpers.rb
loofah-2.4.0 test/unit/test_helpers.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/loofah-2.3.0/test/unit/test_helpers.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/loofah-2.3.1/test/unit/test_helpers.rb
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/loofah-2.3.1/test/unit/test_helpers.rb
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/loofah-2.3.1/test/unit/test_helpers.rb
zuora_connect_ui-0.9.1 vendor/ruby/2.6.0/gems/loofah-2.3.0/test/unit/test_helpers.rb
zuora_connect_ui-0.9.1 vendor/ruby/2.6.0/gems/loofah-2.3.1/test/unit/test_helpers.rb
loofah-2.3.1 test/unit/test_helpers.rb
zuora_connect_ui-0.9.0 vendor/ruby/2.6.0/gems/loofah-2.3.0/test/unit/test_helpers.rb
loofah-2.3.0 test/unit/test_helpers.rb