MRF Policies: Return a {:reject, reason} instead of {:reject, nil}
[akkoma] / test / web / activity_pub / mrf / anti_followbot_policy_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 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
7 import Pleroma.Factory
8
9 alias Pleroma.Web.ActivityPub.MRF.AntiFollowbotPolicy
10
11 describe "blocking based on attributes" do
12 test "matches followbots by nickname" do
13 actor = insert(:user, %{nickname: "followbot@example.com"})
14 target = insert(:user)
15
16 message = %{
17 "@context" => "https://www.w3.org/ns/activitystreams",
18 "type" => "Follow",
19 "actor" => actor.ap_id,
20 "object" => target.ap_id,
21 "id" => "https://example.com/activities/1234"
22 }
23
24 assert {:reject, "[AntiFollowbotPolicy]" <> _} = AntiFollowbotPolicy.filter(message)
25 end
26
27 test "matches followbots by display name" do
28 actor = insert(:user, %{name: "Federation Bot"})
29 target = insert(:user)
30
31 message = %{
32 "@context" => "https://www.w3.org/ns/activitystreams",
33 "type" => "Follow",
34 "actor" => actor.ap_id,
35 "object" => target.ap_id,
36 "id" => "https://example.com/activities/1234"
37 }
38
39 assert {:reject, "[AntiFollowbotPolicy]" <> _} = AntiFollowbotPolicy.filter(message)
40 end
41 end
42
43 test "it allows non-followbots" do
44 actor = insert(:user)
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 {:ok, _} = AntiFollowbotPolicy.filter(message)
56 end
57
58 test "it gracefully handles nil display names" do
59 actor = insert(:user, %{name: nil})
60 target = insert(:user)
61
62 message = %{
63 "@context" => "https://www.w3.org/ns/activitystreams",
64 "type" => "Follow",
65 "actor" => actor.ap_id,
66 "object" => target.ap_id,
67 "id" => "https://example.com/activities/1234"
68 }
69
70 {:ok, _} = AntiFollowbotPolicy.filter(message)
71 end
72 end