Also use actor_type to determine if an account is a bot in antiFollowbotPolicy
[akkoma] / test / pleroma / web / activity_pub / mrf / anti_followbot_policy_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.ActivityPub.MRF.AntiFollowbotPolicyTest do
6 use Pleroma.DataCase, async: true
7 import Pleroma.Factory
8
9 alias Pleroma.User
10 alias Pleroma.Web.ActivityPub.MRF.AntiFollowbotPolicy
11
12 describe "blocking based on attributes" do
13 test "matches followbots by nickname" do
14 actor = insert(:user, %{nickname: "followbot@example.com"})
15 target = insert(:user)
16
17 message = %{
18 "@context" => "https://www.w3.org/ns/activitystreams",
19 "type" => "Follow",
20 "actor" => actor.ap_id,
21 "object" => target.ap_id,
22 "id" => "https://example.com/activities/1234"
23 }
24
25 assert {:reject, "[AntiFollowbotPolicy]" <> _} = AntiFollowbotPolicy.filter(message)
26 end
27
28 test "matches followbots by display name" do
29 actor = insert(:user, %{name: "Federation Bot"})
30 target = insert(:user)
31
32 message = %{
33 "@context" => "https://www.w3.org/ns/activitystreams",
34 "type" => "Follow",
35 "actor" => actor.ap_id,
36 "object" => target.ap_id,
37 "id" => "https://example.com/activities/1234"
38 }
39
40 assert {:reject, "[AntiFollowbotPolicy]" <> _} = AntiFollowbotPolicy.filter(message)
41 end
42
43 test "matches followbots by actor_type" do
44 actor = insert(:user, %{actor_type: "Service"})
45 target = insert(:user)
46
47 message = %{
48 "@context" => "https://www.w3.org/ns/activitystreams",
49 "type" => "Follow",
50 "actor" => actor.ap_id,
51 "object" => target.ap_id,
52 "id" => "https://example.com/activities/1234"
53 }
54
55 assert {:reject, "[AntiFollowbotPolicy]" <> _} = AntiFollowbotPolicy.filter(message)
56 end
57 end
58
59 describe "it allows" do
60 test "non-followbots" do
61 actor = insert(:user)
62 target = insert(:user)
63
64 message = %{
65 "@context" => "https://www.w3.org/ns/activitystreams",
66 "type" => "Follow",
67 "actor" => actor.ap_id,
68 "object" => target.ap_id,
69 "id" => "https://example.com/activities/1234"
70 }
71
72 {:ok, _} = AntiFollowbotPolicy.filter(message)
73 end
74
75 test "bots if the target follows the bots" do
76 actor = insert(:user, %{actor_type: "Service"})
77 target = insert(:user)
78
79 User.follow(target, actor)
80
81 message = %{
82 "@context" => "https://www.w3.org/ns/activitystreams",
83 "type" => "Follow",
84 "actor" => actor.ap_id,
85 "object" => target.ap_id,
86 "id" => "https://example.com/activities/1234"
87 }
88
89 {:ok, _} = AntiFollowbotPolicy.filter(message)
90 end
91 end
92
93 test "it gracefully handles nil display names" do
94 actor = insert(:user, %{name: nil})
95 target = insert(:user)
96
97 message = %{
98 "@context" => "https://www.w3.org/ns/activitystreams",
99 "type" => "Follow",
100 "actor" => actor.ap_id,
101 "object" => target.ap_id,
102 "id" => "https://example.com/activities/1234"
103 }
104
105 {:ok, _} = AntiFollowbotPolicy.filter(message)
106 end
107 end