logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

normalize_markup_test.exs (1579B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Web.ActivityPub.MRF.NormalizeMarkupTest do
  5. use Pleroma.DataCase
  6. alias Pleroma.Web.ActivityPub.MRF.NormalizeMarkup
  7. @html_sample """
  8. <b>this is in bold</b>
  9. <p>this is a paragraph</p>
  10. this is a linebreak<br />
  11. this is a link with allowed "rel" attribute: <a href="http://example.com/" rel="tag">example.com</a>
  12. this is a link with not allowed "rel" attribute: <a href="http://example.com/" rel="tag noallowed">example.com</a>
  13. this is an image: <img src="http://example.com/image.jpg"><br />
  14. <script>alert('hacked')</script>
  15. """
  16. test "it filter html tags" do
  17. expected = """
  18. <b>this is in bold</b>
  19. <p>this is a paragraph</p>
  20. this is a linebreak<br/>
  21. this is a link with allowed &quot;rel&quot; attribute: <a href="http://example.com/" rel="tag">example.com</a>
  22. this is a link with not allowed &quot;rel&quot; attribute: <a href="http://example.com/">example.com</a>
  23. this is an image: <img src="http://example.com/image.jpg"/><br/>
  24. alert(&#39;hacked&#39;)
  25. """
  26. message = %{"type" => "Create", "object" => %{"content" => @html_sample}}
  27. assert {:ok, res} = NormalizeMarkup.filter(message)
  28. assert res["object"]["content"] == expected
  29. end
  30. test "it skips filter if type isn't `Create`" do
  31. message = %{"type" => "Note", "object" => %{}}
  32. assert {:ok, res} = NormalizeMarkup.filter(message)
  33. assert res == message
  34. end
  35. end