08f7be542f99315e8f1bf3a72d4eeb429300bb91
[akkoma] / test / 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 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) == {:reject, nil}
80 end
81
82 test "cc" do
83 Pleroma.Config.put([:mrf_mention], %{actors: ["https://example.com/blocked"]})
84
85 message = %{
86 "type" => "Create",
87 "to" => ["https://example.com/ok"],
88 "cc" => ["https://example.com/blocked"]
89 }
90
91 assert MentionPolicy.filter(message) == {:reject, nil}
92 end
93 end
94 end