6e9daa7f97cbbe2ec6acfc80f6ebd6e0d244a108
[akkoma] / test / web / activity_pub / mrf / hellthread_policy_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 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 alias Pleroma.Web.CommonAPI
12
13 setup do
14 user = insert(:user)
15
16 message = %{
17 "actor" => user.ap_id,
18 "cc" => [user.follower_address],
19 "type" => "Create",
20 "to" => [
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"
25 ],
26 "object" => %{
27 "type" => "Note"
28 }
29 }
30
31 [user: user, message: message]
32 end
33
34 setup do: clear_config(:mrf_hellthread)
35
36 test "doesn't die on chat messages" do
37 Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 2, reject_threshold: 0})
38
39 user = insert(:user)
40 other_user = insert(:user)
41
42 {:ok, activity} = CommonAPI.post_chat_message(user, other_user, "moin")
43
44 assert {:ok, _} = filter(activity.data)
45 end
46
47 describe "reject" do
48 test "rejects the message if the recipient count is above reject_threshold", %{
49 message: message
50 } do
51 Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 2})
52
53 {:reject, nil} = filter(message)
54 end
55
56 test "does not reject the message if the recipient count is below reject_threshold", %{
57 message: message
58 } do
59 Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 3})
60
61 assert {:ok, ^message} = filter(message)
62 end
63 end
64
65 describe "delist" do
66 test "delists the message if the recipient count is above delist_threshold", %{
67 user: user,
68 message: message
69 } do
70 Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 2, reject_threshold: 0})
71
72 {:ok, message} = filter(message)
73 assert user.follower_address in message["to"]
74 assert "https://www.w3.org/ns/activitystreams#Public" in message["cc"]
75 end
76
77 test "does not delist the message if the recipient count is below delist_threshold", %{
78 message: message
79 } do
80 Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 4, reject_threshold: 0})
81
82 assert {:ok, ^message} = filter(message)
83 end
84 end
85
86 test "excludes follower collection and public URI from threshold count", %{message: message} do
87 Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 3})
88
89 assert {:ok, ^message} = filter(message)
90 end
91 end