a78752a12e9ff6007fd8e79d082f5ffae92754c5
[akkoma] / test / web / activity_pub / mrf / hellthread_policy_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicyTest do
6 use Pleroma.DataCase
7 import Pleroma.Factory
8
9 import Pleroma.Web.ActivityPub.MRF.HellthreadPolicy
10
11 setup do
12 user = insert(:user)
13
14 message = %{
15 "actor" => user.ap_id,
16 "cc" => [user.follower_address],
17 "type" => "Create",
18 "to" => [
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"
23 ]
24 }
25
26 [user: user, message: message]
27 end
28
29 clear_config(:mrf_hellthread)
30
31 describe "reject" do
32 test "rejects the message if the recipient count is above reject_threshold", %{
33 message: message
34 } do
35 Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 2})
36
37 {:reject, nil} = filter(message)
38 end
39
40 test "does not reject the message if the recipient count is below reject_threshold", %{
41 message: message
42 } do
43 Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 3})
44
45 assert {:ok, ^message} = filter(message)
46 end
47 end
48
49 describe "delist" do
50 test "delists the message if the recipient count is above delist_threshold", %{
51 user: user,
52 message: message
53 } do
54 Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 2, reject_threshold: 0})
55
56 {:ok, message} = filter(message)
57 assert user.follower_address in message["to"]
58 assert "https://www.w3.org/ns/activitystreams#Public" in message["cc"]
59 end
60
61 test "does not delist the message if the recipient count is below delist_threshold", %{
62 message: message
63 } do
64 Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 4, reject_threshold: 0})
65
66 assert {:ok, ^message} = filter(message)
67 end
68 end
69
70 test "excludes follower collection and public URI from threshold count", %{message: message} do
71 Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 3})
72
73 assert {:ok, ^message} = filter(message)
74 end
75 end