1 # Pleroma: A lightweight social networking server
2 # Copyright © 2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicyTest do
9 alias Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicy
14 "content" => "hi world!"
21 "content" => "<a href='https://example.com'>hi world!</a>"
33 describe "with new user" do
34 test "it allows posts without links" do
37 assert user.info.note_count == 0
41 |> Map.put("actor", user.ap_id)
43 {:ok, _message} = AntiLinkSpamPolicy.filter(message)
46 test "it disallows posts with links" do
49 assert user.info.note_count == 0
53 |> Map.put("actor", user.ap_id)
55 {:reject, _} = AntiLinkSpamPolicy.filter(message)
59 describe "with old user" do
60 test "it allows posts without links" do
61 user = insert(:user, info: %{note_count: 1})
63 assert user.info.note_count == 1
67 |> Map.put("actor", user.ap_id)
69 {:ok, _message} = AntiLinkSpamPolicy.filter(message)
72 test "it allows posts with links" do
73 user = insert(:user, info: %{note_count: 1})
75 assert user.info.note_count == 1
79 |> Map.put("actor", user.ap_id)
81 {:ok, _message} = AntiLinkSpamPolicy.filter(message)
85 describe "with followed new user" do
86 test "it allows posts without links" do
87 user = insert(:user, info: %{follower_count: 1})
89 assert user.info.follower_count == 1
93 |> Map.put("actor", user.ap_id)
95 {:ok, _message} = AntiLinkSpamPolicy.filter(message)
98 test "it allows posts with links" do
99 user = insert(:user, info: %{follower_count: 1})
101 assert user.info.follower_count == 1
105 |> Map.put("actor", user.ap_id)
107 {:ok, _message} = AntiLinkSpamPolicy.filter(message)
111 describe "with unknown actors" do
112 test "it rejects posts without links" do
115 |> Map.put("actor", "http://invalid.actor")
117 {:reject, _} = AntiLinkSpamPolicy.filter(message)
120 test "it rejects posts with links" do
123 |> Map.put("actor", "http://invalid.actor")
125 {:reject, _} = AntiLinkSpamPolicy.filter(message)
129 describe "with contentless-objects" do
130 test "it does not reject them or error out" do
131 user = insert(:user, info: %{note_count: 1})
135 |> Map.put("actor", user.ap_id)
137 {:ok, _message} = AntiLinkSpamPolicy.filter(message)