66e98b7ee28eaec28f965c85d183d4f2a9c6f896
[akkoma] / test / pleroma / web / activity_pub / mrf / tag_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.TagPolicyTest do
6 use Pleroma.DataCase, async: true
7 import Pleroma.Factory
8
9 alias Pleroma.Web.ActivityPub.MRF.TagPolicy
10 @public "https://www.w3.org/ns/activitystreams#Public"
11
12 describe "mrf_tag:disable-any-subscription" do
13 test "rejects message" do
14 actor = insert(:user, tags: ["mrf_tag:disable-any-subscription"])
15 message = %{"object" => actor.ap_id, "type" => "Follow", "actor" => actor.ap_id}
16 assert {:reject, _} = TagPolicy.filter(message)
17 end
18 end
19
20 describe "mrf_tag:disable-remote-subscription" do
21 test "rejects non-local follow requests" do
22 actor = insert(:user, tags: ["mrf_tag:disable-remote-subscription"])
23 follower = insert(:user, tags: ["mrf_tag:disable-remote-subscription"], local: false)
24 message = %{"object" => actor.ap_id, "type" => "Follow", "actor" => follower.ap_id}
25 assert {:reject, _} = TagPolicy.filter(message)
26 end
27
28 test "allows non-local follow requests" do
29 actor = insert(:user, tags: ["mrf_tag:disable-remote-subscription"])
30 follower = insert(:user, tags: ["mrf_tag:disable-remote-subscription"], local: true)
31 message = %{"object" => actor.ap_id, "type" => "Follow", "actor" => follower.ap_id}
32 assert {:ok, _message} = TagPolicy.filter(message)
33 end
34 end
35
36 describe "mrf_tag:sandbox" do
37 test "removes from public timelines" do
38 actor = insert(:user, tags: ["mrf_tag:sandbox"])
39
40 message = %{
41 "actor" => actor.ap_id,
42 "type" => "Create",
43 "object" => %{},
44 "to" => [@public, "f"],
45 "cc" => [@public, "d"]
46 }
47
48 except_message = %{
49 "actor" => actor.ap_id,
50 "type" => "Create",
51 "object" => %{"to" => ["f", actor.follower_address], "cc" => ["d"]},
52 "to" => ["f", actor.follower_address],
53 "cc" => ["d"]
54 }
55
56 assert TagPolicy.filter(message) == {:ok, except_message}
57 end
58 end
59
60 describe "mrf_tag:force-unlisted" do
61 test "removes from the federated timeline" do
62 actor = insert(:user, tags: ["mrf_tag:force-unlisted"])
63
64 message = %{
65 "actor" => actor.ap_id,
66 "type" => "Create",
67 "object" => %{},
68 "to" => [@public, "f"],
69 "cc" => [actor.follower_address, "d"]
70 }
71
72 except_message = %{
73 "actor" => actor.ap_id,
74 "type" => "Create",
75 "object" => %{"to" => ["f", actor.follower_address], "cc" => ["d", @public]},
76 "to" => ["f", actor.follower_address],
77 "cc" => ["d", @public]
78 }
79
80 assert TagPolicy.filter(message) == {:ok, except_message}
81 end
82 end
83
84 describe "mrf_tag:media-strip" do
85 test "removes attachments" do
86 actor = insert(:user, tags: ["mrf_tag:media-strip"])
87
88 message = %{
89 "actor" => actor.ap_id,
90 "type" => "Create",
91 "object" => %{"attachment" => ["file1"]}
92 }
93
94 except_message = %{
95 "actor" => actor.ap_id,
96 "type" => "Create",
97 "object" => %{}
98 }
99
100 assert TagPolicy.filter(message) == {:ok, except_message}
101 end
102 end
103
104 describe "mrf_tag:media-force-nsfw" do
105 test "Mark as sensitive on presence of attachments" do
106 actor = insert(:user, tags: ["mrf_tag:media-force-nsfw"])
107
108 message = %{
109 "actor" => actor.ap_id,
110 "type" => "Create",
111 "object" => %{"tag" => ["test"], "attachment" => ["file1"]}
112 }
113
114 except_message = %{
115 "actor" => actor.ap_id,
116 "type" => "Create",
117 "object" => %{"tag" => ["test", "nsfw"], "attachment" => ["file1"], "sensitive" => true}
118 }
119
120 assert TagPolicy.filter(message) == {:ok, except_message}
121 end
122 end
123 end