summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMark Felder <feld@feld.me>2024-03-15 15:10:45 -0400
committerMark Felder <feld@feld.me>2024-08-12 17:06:29 -0400
commit488c4b8b983f99d036e3f3bf67dec782f9959319 (patch)
tree9e16bee7544d50f56b35601b32ffa1d56b9b411b /test
parentc29441f30d0229192868ec4149a46fea562b0997 (diff)
downloadpleroma-488c4b8b983f99d036e3f3bf67dec782f9959319.tar.gz
pleroma-488c4b8b983f99d036e3f3bf67dec782f9959319.zip
MRF.FODirectReply
Force replies to followers-only posts to always be direct
Diffstat (limited to 'test')
-rw-r--r--test/pleroma/web/activity_pub/mrf/fo_direct_reply_test.exs87
1 files changed, 87 insertions, 0 deletions
diff --git a/test/pleroma/web/activity_pub/mrf/fo_direct_reply_test.exs b/test/pleroma/web/activity_pub/mrf/fo_direct_reply_test.exs
new file mode 100644
index 000000000..7afc83ffc
--- /dev/null
+++ b/test/pleroma/web/activity_pub/mrf/fo_direct_reply_test.exs
@@ -0,0 +1,87 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.ActivityPub.MRF.FODirectReplyTest do
+ use Pleroma.DataCase
+ import Pleroma.Factory
+
+ require Pleroma.Constants
+
+ alias Pleroma.Object
+ alias Pleroma.Web.ActivityPub.MRF.FODirectReply
+ alias Pleroma.Web.CommonAPI
+
+ test "replying to followers-only/private is changed to direct" do
+ batman = insert(:user, nickname: "batman")
+ robin = insert(:user, nickname: "robin")
+
+ {:ok, post} =
+ CommonAPI.post(batman, %{
+ status: "Has anyone seen Selina Kyle's latest selfies?",
+ visibility: "private"
+ })
+
+ reply = %{
+ "type" => "Create",
+ "actor" => robin.ap_id,
+ "to" => [batman.ap_id, robin.follower_address],
+ "cc" => [],
+ "object" => %{
+ "type" => "Note",
+ "actor" => robin.ap_id,
+ "content" => "@batman 🤤 ❤️ 🐈‍⬛",
+ "to" => [batman.ap_id, robin.follower_address],
+ "cc" => [],
+ "inReplyTo" => Object.normalize(post).data["id"]
+ }
+ }
+
+ expected_to = [batman.ap_id]
+ expected_cc = []
+
+ assert {:ok, filtered} = FODirectReply.filter(reply)
+
+ assert expected_to == filtered["to"]
+ assert expected_cc == filtered["cc"]
+ assert expected_to == filtered["object"]["to"]
+ assert expected_cc == filtered["object"]["cc"]
+ end
+
+ test "replies to public posts are unmodified" do
+ batman = insert(:user, nickname: "batman")
+ robin = insert(:user, nickname: "robin")
+
+ {:ok, post} =
+ CommonAPI.post(batman, %{status: "Has anyone seen Selina Kyle's latest selfies?"})
+
+ reply = %{
+ "type" => "Create",
+ "actor" => robin.ap_id,
+ "to" => [batman.ap_id, robin.follower_address],
+ "cc" => [],
+ "object" => %{
+ "type" => "Note",
+ "actor" => robin.ap_id,
+ "content" => "@batman 🤤 ❤️ 🐈<200d>⬛",
+ "to" => [batman.ap_id, robin.follower_address],
+ "cc" => [],
+ "inReplyTo" => Object.normalize(post).data["id"]
+ }
+ }
+
+ assert {:ok, filtered} = FODirectReply.filter(reply)
+
+ assert match?(^filtered, reply)
+ end
+
+ test "non-reply posts are unmodified" do
+ batman = insert(:user, nickname: "batman")
+
+ {:ok, post} = CommonAPI.post(batman, %{status: "To the Batmobile!"})
+
+ assert {:ok, filtered} = FODirectReply.filter(post)
+
+ assert match?(^filtered, post)
+ end
+end