logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

safe_text_test.exs (981B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.EctoType.ActivityPub.ObjectValidators.SafeTextTest do
  5. use Pleroma.DataCase, async: true
  6. alias Pleroma.EctoType.ActivityPub.ObjectValidators.SafeText
  7. test "it lets normal text go through" do
  8. text = "hey how are you"
  9. assert {:ok, text} == SafeText.cast(text)
  10. end
  11. test "it removes html tags from text" do
  12. text = "hey look xss <script>alert('foo')</script>"
  13. assert {:ok, "hey look xss alert(&#39;foo&#39;)"} == SafeText.cast(text)
  14. end
  15. test "it keeps basic html tags" do
  16. text = "hey <a href='http://gensokyo.2hu'>look</a> xss <script>alert('foo')</script>"
  17. assert {:ok, "hey <a href=\"http://gensokyo.2hu\">look</a> xss alert(&#39;foo&#39;)"} ==
  18. SafeText.cast(text)
  19. end
  20. test "errors for non-text" do
  21. assert :error == SafeText.cast(1)
  22. end
  23. end