Merge branch 'develop' into 'docs/add-clients-to-ex_doc'
[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 describe "reject" do
30 test "rejects the message if the recipient count is above reject_threshold", %{
31 message: message
32 } do
33 Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 2})
34
35 {:reject, nil} = filter(message)
36 end
37
38 test "does not reject the message if the recipient count is below reject_threshold", %{
39 message: message
40 } do
41 Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 3})
42
43 assert {:ok, ^message} = filter(message)
44 end
45 end
46
47 describe "delist" do
48 test "delists the message if the recipient count is above delist_threshold", %{
49 user: user,
50 message: message
51 } do
52 Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 2, reject_threshold: 0})
53
54 {:ok, message} = filter(message)
55 assert user.follower_address in message["to"]
56 assert "https://www.w3.org/ns/activitystreams#Public" in message["cc"]
57 end
58
59 test "does not delist the message if the recipient count is below delist_threshold", %{
60 message: message
61 } do
62 Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 4, reject_threshold: 0})
63
64 assert {:ok, ^message} = filter(message)
65 end
66 end
67
68 test "excludes follower collection and public URI from threshold count", %{message: message} do
69 Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 3})
70
71 assert {:ok, ^message} = filter(message)
72 end
73 end