1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ActivityPub.MRF.AntiFollowbotPolicyTest do
6 use Pleroma.DataCase, async: true
10 alias Pleroma.Web.ActivityPub.MRF.AntiFollowbotPolicy
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)
18 "@context" => "https://www.w3.org/ns/activitystreams",
20 "actor" => actor.ap_id,
21 "object" => target.ap_id,
22 "id" => "https://example.com/activities/1234"
25 assert {:reject, "[AntiFollowbotPolicy]" <> _} = AntiFollowbotPolicy.filter(message)
28 test "matches followbots by display name" do
29 actor = insert(:user, %{name: "Federation Bot"})
30 target = insert(:user)
33 "@context" => "https://www.w3.org/ns/activitystreams",
35 "actor" => actor.ap_id,
36 "object" => target.ap_id,
37 "id" => "https://example.com/activities/1234"
40 assert {:reject, "[AntiFollowbotPolicy]" <> _} = AntiFollowbotPolicy.filter(message)
43 test "matches followbots by actor_type" do
44 actor = insert(:user, %{actor_type: "Service"})
45 target = insert(:user)
48 "@context" => "https://www.w3.org/ns/activitystreams",
50 "actor" => actor.ap_id,
51 "object" => target.ap_id,
52 "id" => "https://example.com/activities/1234"
55 assert {:reject, "[AntiFollowbotPolicy]" <> _} = AntiFollowbotPolicy.filter(message)
59 describe "it allows" do
60 test "non-followbots" do
62 target = insert(:user)
65 "@context" => "https://www.w3.org/ns/activitystreams",
67 "actor" => actor.ap_id,
68 "object" => target.ap_id,
69 "id" => "https://example.com/activities/1234"
72 {:ok, _} = AntiFollowbotPolicy.filter(message)
75 test "bots if the target follows the bots" do
76 actor = insert(:user, %{actor_type: "Service"})
77 target = insert(:user)
79 User.follow(target, actor)
82 "@context" => "https://www.w3.org/ns/activitystreams",
84 "actor" => actor.ap_id,
85 "object" => target.ap_id,
86 "id" => "https://example.com/activities/1234"
89 {:ok, _} = AntiFollowbotPolicy.filter(message)
93 test "it gracefully handles nil display names" do
94 actor = insert(:user, %{name: nil})
95 target = insert(:user)
98 "@context" => "https://www.w3.org/ns/activitystreams",
100 "actor" => actor.ap_id,
101 "object" => target.ap_id,
102 "id" => "https://example.com/activities/1234"
105 {:ok, _} = AntiFollowbotPolicy.filter(message)