First
[anni] / test / pleroma / ecto_type / activity_pub / object_validators / safe_text_test.exs
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
5 defmodule Pleroma.EctoType.ActivityPub.ObjectValidators.SafeTextTest do
6   use Pleroma.DataCase, async: true
7
8   alias Pleroma.EctoType.ActivityPub.ObjectValidators.SafeText
9
10   test "it lets normal text go through" do
11     text = "hey how are you"
12     assert {:ok, text} == SafeText.cast(text)
13   end
14
15   test "it removes html tags from text" do
16     text = "hey look xss <script>alert('foo')</script>"
17     assert {:ok, "hey look xss alert(&#39;foo&#39;)"} == SafeText.cast(text)
18   end
19
20   test "it keeps basic html tags" do
21     text = "hey <a href='http://gensokyo.2hu'>look</a> xss <script>alert('foo')</script>"
22
23     assert {:ok, "hey <a href=\"http://gensokyo.2hu\">look</a> xss alert(&#39;foo&#39;)"} ==
24              SafeText.cast(text)
25   end
26
27   test "errors for non-text" do
28     assert :error == SafeText.cast(1)
29   end
30 end