Sha256: 6953cd57909763d1c842ccaa7af3f669e7df117a6253e6991d785367f958693e

Contents?: true

Size: 1.44 KB

Versions: 33

Compression:

Stored size: 1.44 KB

Contents

require "helper"

class IntegrationTestHelpers < Loofah::TestCase
  context ".strip_tags" do
    context "on safe markup" do
      it "strip out tags" do
        assert_equal "omgwtfbbq!!1!", Loofah::Helpers.strip_tags("<div>omgwtfbbq</div><span>!!1!</span>")
      end
    end

    context "on hack attack" do
      it "strip escape html entities" do
        bad_shit = "&lt;script&gt;alert('evil')&lt;/script&gt;"
        assert_equal bad_shit, Loofah::Helpers.strip_tags(bad_shit)
      end
    end
  end

  context ".sanitize" do
    context "on safe markup" do
      it "render the safe html" do
        html = "<div>omgwtfbbq</div><span>!!1!</span>"
        assert_equal html, Loofah::Helpers.sanitize(html)
      end
    end

    context "on hack attack" do
      it "strip the unsafe tags" do
        assert_equal "alert('evil')<span>w00t</span>", Loofah::Helpers.sanitize("<script>alert('evil')</script><span>w00t</span>")
      end

      it "strips form tags" do
        assert_equal "alert('evil')<span>w00t</span>", Loofah::Helpers.sanitize("<script>alert('evil')</script><form action=\"/foo/bar\" method=\"post\"><input></form><span>w00t</span>")
      end
    end
  end

  context ".sanitize_css" do
    it "removes unsafe css properties" do
      assert_match(/display:\s*block;\s*background-color:\s*blue;/, Loofah::Helpers.sanitize_css("display:block;background-image:url(http://www.ragingplatypus.com/i/cam-full.jpg);background-color:blue"))
    end
  end
end

Version data entries

33 entries across 25 versions & 6 rubygems

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