1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ActivityPub.MRF.FollowBotPolicyTest do
6 use Pleroma.DataCase, async: true
9 alias Pleroma.Web.ActivityPub.MRF.FollowBotPolicy
11 import Pleroma.Factory
13 describe "FollowBotPolicy" do
14 test "follows remote users" do
15 bot = insert(:user, actor_type: "Service")
16 remote_user = insert(:user, local: false)
17 clear_config([:mrf_follow_bot, :follower_nickname], bot.nickname)
20 "@context" => "https://www.w3.org/ns/activitystreams",
21 "to" => [remote_user.follower_address],
22 "cc" => ["https://www.w3.org/ns/activitystreams#Public"],
25 "content" => "Test post",
27 "attributedTo" => remote_user.ap_id,
30 "actor" => remote_user.ap_id
33 refute User.following?(bot, remote_user)
35 assert User.get_follow_requests(remote_user) |> length == 0
37 FollowBotPolicy.filter(message)
39 assert User.get_follow_requests(remote_user) |> length == 1
42 test "does not follow users with #nobot in bio" do
43 bot = insert(:user, actor_type: "Service")
44 remote_user = insert(:user, %{local: false, bio: "go away bots! #nobot"})
45 clear_config([:mrf_follow_bot, :follower_nickname], bot.nickname)
48 "@context" => "https://www.w3.org/ns/activitystreams",
49 "to" => [remote_user.follower_address],
50 "cc" => ["https://www.w3.org/ns/activitystreams#Public"],
53 "content" => "I don't like follow bots",
55 "attributedTo" => remote_user.ap_id,
58 "actor" => remote_user.ap_id
61 refute User.following?(bot, remote_user)
63 assert User.get_follow_requests(remote_user) |> length == 0
65 FollowBotPolicy.filter(message)
67 assert User.get_follow_requests(remote_user) |> length == 0
70 test "does not follow local users" do
71 bot = insert(:user, actor_type: "Service")
72 local_user = insert(:user, local: true)
73 clear_config([:mrf_follow_bot, :follower_nickname], bot.nickname)
76 "@context" => "https://www.w3.org/ns/activitystreams",
77 "to" => [local_user.follower_address],
78 "cc" => ["https://www.w3.org/ns/activitystreams#Public"],
81 "content" => "Hi I'm a local user",
83 "attributedTo" => local_user.ap_id,
86 "actor" => local_user.ap_id
89 refute User.following?(bot, local_user)
91 assert User.get_follow_requests(local_user) |> length == 0
93 FollowBotPolicy.filter(message)
95 assert User.get_follow_requests(local_user) |> length == 0
98 test "does not follow users requiring follower approval" do
99 bot = insert(:user, actor_type: "Service")
100 remote_user = insert(:user, %{local: false, is_locked: true})
101 clear_config([:mrf_follow_bot, :follower_nickname], bot.nickname)
104 "@context" => "https://www.w3.org/ns/activitystreams",
105 "to" => [remote_user.follower_address],
106 "cc" => ["https://www.w3.org/ns/activitystreams#Public"],
109 "content" => "I don't like randos following me",
111 "attributedTo" => remote_user.ap_id,
114 "actor" => remote_user.ap_id
117 refute User.following?(bot, remote_user)
119 assert User.get_follow_requests(remote_user) |> length == 0
121 FollowBotPolicy.filter(message)
123 assert User.get_follow_requests(remote_user) |> length == 0