1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ActivityPub.MRF.TagPolicyTest do
9 alias Pleroma.Web.ActivityPub.MRF.TagPolicy
10 @public "https://www.w3.org/ns/activitystreams#Public"
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"}
16 assert {:reject, nil} = TagPolicy.filter(message)
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, nil} = TagPolicy.filter(message)
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)
36 describe "mrf_tag:sandbox" do
37 test "removes from public timelines" do
38 actor = insert(:user, tags: ["mrf_tag:sandbox"])
41 "actor" => actor.ap_id,
44 "to" => [@public, "f"],
45 "cc" => [@public, "d"]
49 "actor" => actor.ap_id,
51 "object" => %{"to" => ["f", actor.follower_address], "cc" => ["d"]},
52 "to" => ["f", actor.follower_address],
56 assert TagPolicy.filter(message) == {:ok, except_message}
60 describe "mrf_tag:force-unlisted" do
61 test "removes from the federated timeline" do
62 actor = insert(:user, tags: ["mrf_tag:force-unlisted"])
65 "actor" => actor.ap_id,
68 "to" => [@public, "f"],
69 "cc" => [actor.follower_address, "d"]
73 "actor" => actor.ap_id,
75 "object" => %{"to" => ["f", actor.follower_address], "cc" => ["d", @public]},
76 "to" => ["f", actor.follower_address],
77 "cc" => ["d", @public]
80 assert TagPolicy.filter(message) == {:ok, except_message}
84 describe "mrf_tag:media-strip" do
85 test "removes attachments" do
86 actor = insert(:user, tags: ["mrf_tag:media-strip"])
89 "actor" => actor.ap_id,
91 "object" => %{"attachment" => ["file1"]}
95 "actor" => actor.ap_id,
100 assert TagPolicy.filter(message) == {:ok, except_message}
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"])
109 "actor" => actor.ap_id,
111 "object" => %{"tag" => ["test"], "attachment" => ["file1"]}
115 "actor" => actor.ap_id,
117 "object" => %{"tag" => ["test", "nsfw"], "attachment" => ["file1"], "sensitive" => true}
120 assert TagPolicy.filter(message) == {:ok, except_message}