1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicyTest do
9 import Pleroma.Web.ActivityPub.MRF.HellthreadPolicy
11 alias Pleroma.Web.CommonAPI
17 "actor" => user.ap_id,
18 "cc" => [user.follower_address],
21 "https://www.w3.org/ns/activitystreams#Public",
22 "https://instance.tld/users/user1",
23 "https://instance.tld/users/user2",
24 "https://instance.tld/users/user3"
31 [user: user, message: message]
34 setup do: clear_config(:mrf_hellthread)
36 test "doesn't die on chat messages" do
37 clear_config([:mrf_hellthread], %{delist_threshold: 2, reject_threshold: 0})
40 other_user = insert(:user)
42 {:ok, activity} = CommonAPI.post_chat_message(user, other_user, "moin")
44 assert {:ok, _} = filter(activity.data)
48 test "rejects the message if the recipient count is above reject_threshold", %{
51 clear_config([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 2})
53 assert {:reject, "[HellthreadPolicy] 3 recipients is over the limit of 2"} ==
57 test "does not reject the message if the recipient count is below reject_threshold", %{
60 clear_config([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 3})
62 assert {:ok, ^message} = filter(message)
67 test "delists the message if the recipient count is above delist_threshold", %{
71 clear_config([:mrf_hellthread], %{delist_threshold: 2, reject_threshold: 0})
73 {:ok, message} = filter(message)
74 assert user.follower_address in message["to"]
75 assert "https://www.w3.org/ns/activitystreams#Public" in message["cc"]
78 test "does not delist the message if the recipient count is below delist_threshold", %{
81 clear_config([:mrf_hellthread], %{delist_threshold: 4, reject_threshold: 0})
83 assert {:ok, ^message} = filter(message)
87 test "excludes follower collection and public URI from threshold count", %{message: message} do
88 clear_config([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 3})
90 assert {:ok, ^message} = filter(message)