Merge branch 'bugfix/oauth-token-padding' into 'develop'
[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 describe "hellthread filter tests" do
12 setup do
13 user = insert(:user)
14
15 message = %{
16 "actor" => user.ap_id,
17 "cc" => [user.follower_address],
18 "type" => "Create",
19 "to" => [
20 "https://www.w3.org/ns/activitystreams#Public",
21 "https://instace.tld/users/user1",
22 "https://instace.tld/users/user2",
23 "https://instace.tld/users/user3"
24 ]
25 }
26
27 [user: user, message: message]
28 end
29
30 test "reject test", %{message: message} do
31 Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 2})
32
33 {:reject, nil} = filter(message)
34 end
35
36 test "delist test", %{user: user, message: message} do
37 Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 2, reject_threshold: 0})
38
39 {:ok, message} = filter(message)
40 assert user.follower_address in message["to"]
41 assert "https://www.w3.org/ns/activitystreams#Public" in message["cc"]
42 end
43
44 test "excludes follower collection and public URI from threshold count", %{message: message} do
45 Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 3})
46
47 {:ok, _} = filter(message)
48 end
49 end
50 end