Merge remote-tracking branch 'pleroma/develop' into cycles-frontend-static
[akkoma] / test / pleroma / web / activity_pub / mrf / follow_bot_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.FollowBotPolicyTest do
6 use Pleroma.DataCase, async: true
7
8 alias Pleroma.User
9 alias Pleroma.Web.ActivityPub.MRF.FollowBotPolicy
10
11 import Pleroma.Factory
12
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)
18
19 message = %{
20 "@context" => "https://www.w3.org/ns/activitystreams",
21 "to" => [remote_user.follower_address],
22 "cc" => ["https://www.w3.org/ns/activitystreams#Public"],
23 "type" => "Create",
24 "object" => %{
25 "content" => "Test post",
26 "type" => "Note",
27 "attributedTo" => remote_user.ap_id,
28 "inReplyTo" => nil
29 },
30 "actor" => remote_user.ap_id
31 }
32
33 refute User.following?(bot, remote_user)
34
35 assert User.get_follow_requests(remote_user) |> length == 0
36
37 FollowBotPolicy.filter(message)
38
39 assert User.get_follow_requests(remote_user) |> length == 1
40 end
41
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)
46
47 message = %{
48 "@context" => "https://www.w3.org/ns/activitystreams",
49 "to" => [remote_user.follower_address],
50 "cc" => ["https://www.w3.org/ns/activitystreams#Public"],
51 "type" => "Create",
52 "object" => %{
53 "content" => "I don't like follow bots",
54 "type" => "Note",
55 "attributedTo" => remote_user.ap_id,
56 "inReplyTo" => nil
57 },
58 "actor" => remote_user.ap_id
59 }
60
61 refute User.following?(bot, remote_user)
62
63 assert User.get_follow_requests(remote_user) |> length == 0
64
65 FollowBotPolicy.filter(message)
66
67 assert User.get_follow_requests(remote_user) |> length == 0
68 end
69
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)
74
75 message = %{
76 "@context" => "https://www.w3.org/ns/activitystreams",
77 "to" => [local_user.follower_address],
78 "cc" => ["https://www.w3.org/ns/activitystreams#Public"],
79 "type" => "Create",
80 "object" => %{
81 "content" => "Hi I'm a local user",
82 "type" => "Note",
83 "attributedTo" => local_user.ap_id,
84 "inReplyTo" => nil
85 },
86 "actor" => local_user.ap_id
87 }
88
89 refute User.following?(bot, local_user)
90
91 assert User.get_follow_requests(local_user) |> length == 0
92
93 FollowBotPolicy.filter(message)
94
95 assert User.get_follow_requests(local_user) |> length == 0
96 end
97
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)
102
103 message = %{
104 "@context" => "https://www.w3.org/ns/activitystreams",
105 "to" => [remote_user.follower_address],
106 "cc" => ["https://www.w3.org/ns/activitystreams#Public"],
107 "type" => "Create",
108 "object" => %{
109 "content" => "I don't like randos following me",
110 "type" => "Note",
111 "attributedTo" => remote_user.ap_id,
112 "inReplyTo" => nil
113 },
114 "actor" => remote_user.ap_id
115 }
116
117 refute User.following?(bot, remote_user)
118
119 assert User.get_follow_requests(remote_user) |> length == 0
120
121 FollowBotPolicy.filter(message)
122
123 assert User.get_follow_requests(remote_user) |> length == 0
124 end
125 end
126 end