1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.EctoType.ActivityPub.ObjectValidators.SafeTextTest do
6 use Pleroma.DataCase, async: true
8 alias Pleroma.EctoType.ActivityPub.ObjectValidators.SafeText
10 test "it lets normal text go through" do
11 text = "hey how are you"
12 assert {:ok, text} == SafeText.cast(text)
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('foo')"} == SafeText.cast(text)
20 test "it keeps basic html tags" do
21 text = "hey <a href='http://gensokyo.2hu'>look</a> xss <script>alert('foo')</script>"
23 assert {:ok, "hey <a href=\"http://gensokyo.2hu\">look</a> xss alert('foo')"} ==
27 test "errors for non-text" do
28 assert :error == SafeText.cast(1)