Merge branch 'develop' of git.pleroma.social:pleroma/pleroma into remake-remodel-dms
[akkoma] / test / web / activity_pub / object_validators / types / safe_text_test.exs
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
5 defmodule Pleroma.Web.ActivityPub.ObjectValidators.Types.SafeTextTest do
6 use Pleroma.DataCase
7
8 alias Pleroma.Web.ActivityPub.ObjectValidators.Types.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 "errors for non-text" do
21 assert :error == SafeText.cast(1)
22 end
23 end