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.Web.ActivityPub.MRF.HellthreadPolicyTest do
9 import Pleroma.Web.ActivityPub.MRF.HellthreadPolicy
15 "actor" => user.ap_id,
16 "cc" => [user.follower_address],
19 "https://www.w3.org/ns/activitystreams#Public",
20 "https://instance.tld/users/user1",
21 "https://instance.tld/users/user2",
22 "https://instance.tld/users/user3"
30 "actor" => user.ap_id,
31 "cc" => [user.follower_address],
34 "https://www.w3.org/ns/activitystreams#Public",
35 "https://instance.tld/users/user1",
36 "https://instance.tld/users/user2",
37 "https://instance.tld/users/user3"
44 [user: user, message: message, update_message: update_message]
47 setup do: clear_config(:mrf_hellthread)
50 test "rejects the message if the recipient count is above reject_threshold", %{
52 update_message: update_message
54 clear_config([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 2})
56 assert {:reject, "[HellthreadPolicy] 3 recipients is over the limit of 2"} ==
59 assert {:reject, "[HellthreadPolicy] 3 recipients is over the limit of 2"} ==
60 filter(update_message)
63 test "does not reject the message if the recipient count is below reject_threshold", %{
65 update_message: update_message
67 clear_config([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 3})
69 assert {:ok, ^message} = filter(message)
70 assert {:ok, ^update_message} = filter(update_message)
75 test "delists the message if the recipient count is above delist_threshold", %{
78 update_message: update_message
80 clear_config([:mrf_hellthread], %{delist_threshold: 2, reject_threshold: 0})
82 {:ok, message} = filter(message)
83 assert user.follower_address in message["to"]
84 assert "https://www.w3.org/ns/activitystreams#Public" in message["cc"]
86 {:ok, update_message} = filter(update_message)
87 assert user.follower_address in update_message["to"]
88 assert "https://www.w3.org/ns/activitystreams#Public" in update_message["cc"]
91 test "does not delist the message if the recipient count is below delist_threshold", %{
93 update_message: update_message
95 clear_config([:mrf_hellthread], %{delist_threshold: 4, reject_threshold: 0})
97 assert {:ok, ^message} = filter(message)
98 assert {:ok, ^update_message} = filter(update_message)
102 test "excludes follower collection and public URI from threshold count", %{
104 update_message: update_message
106 clear_config([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 3})
108 assert {:ok, ^message} = filter(message)
109 assert {:ok, ^update_message} = filter(update_message)