Merge branch 'issue/2069' into 'develop'
[akkoma] / test / pleroma / web / activity_pub / mrf / mention_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.MentionPolicyTest do
6 use Pleroma.DataCase
7
8 alias Pleroma.Web.ActivityPub.MRF.MentionPolicy
9
10 setup do: clear_config(:mrf_mention)
11
12 test "pass filter if allow list is empty" do
13 Pleroma.Config.delete([:mrf_mention])
14
15 message = %{
16 "type" => "Create",
17 "to" => ["https://example.com/ok"],
18 "cc" => ["https://example.com/blocked"]
19 }
20
21 assert MentionPolicy.filter(message) == {:ok, message}
22 end
23
24 describe "allow" do
25 test "empty" do
26 Pleroma.Config.put([:mrf_mention], %{actors: ["https://example.com/blocked"]})
27
28 message = %{
29 "type" => "Create"
30 }
31
32 assert MentionPolicy.filter(message) == {:ok, message}
33 end
34
35 test "to" do
36 Pleroma.Config.put([:mrf_mention], %{actors: ["https://example.com/blocked"]})
37
38 message = %{
39 "type" => "Create",
40 "to" => ["https://example.com/ok"]
41 }
42
43 assert MentionPolicy.filter(message) == {:ok, message}
44 end
45
46 test "cc" do
47 Pleroma.Config.put([:mrf_mention], %{actors: ["https://example.com/blocked"]})
48
49 message = %{
50 "type" => "Create",
51 "cc" => ["https://example.com/ok"]
52 }
53
54 assert MentionPolicy.filter(message) == {:ok, message}
55 end
56
57 test "both" do
58 Pleroma.Config.put([:mrf_mention], %{actors: ["https://example.com/blocked"]})
59
60 message = %{
61 "type" => "Create",
62 "to" => ["https://example.com/ok"],
63 "cc" => ["https://example.com/ok2"]
64 }
65
66 assert MentionPolicy.filter(message) == {:ok, message}
67 end
68 end
69
70 describe "deny" do
71 test "to" do
72 Pleroma.Config.put([:mrf_mention], %{actors: ["https://example.com/blocked"]})
73
74 message = %{
75 "type" => "Create",
76 "to" => ["https://example.com/blocked"]
77 }
78
79 assert MentionPolicy.filter(message) ==
80 {:reject, "[MentionPolicy] Rejected for mention of https://example.com/blocked"}
81 end
82
83 test "cc" do
84 Pleroma.Config.put([:mrf_mention], %{actors: ["https://example.com/blocked"]})
85
86 message = %{
87 "type" => "Create",
88 "to" => ["https://example.com/ok"],
89 "cc" => ["https://example.com/blocked"]
90 }
91
92 assert MentionPolicy.filter(message) ==
93 {:reject, "[MentionPolicy] Rejected for mention of https://example.com/blocked"}
94 end
95 end
96 end