logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git
commit: 997f08b3500a983e8b27db9a6e4745582bb4763c
parent d877d2a4e7449e942b4d192f283824eebcade563
Author: Tusooa Zhu <tusooa@kazv.moe>
Date:   Sun, 24 Jul 2022 00:18:09 -0400

Make AntiLinkSpamPolicy history-aware

Diffstat:

Mlib/pleroma/web/activity_pub/mrf/anti_link_spam_policy.ex3+++
Mtest/pleroma/web/activity_pub/mrf/anti_link_spam_policy_test.exs33+++++++++++++++++++++++++++++----
2 files changed, 32 insertions(+), 4 deletions(-)

diff --git a/lib/pleroma/web/activity_pub/mrf/anti_link_spam_policy.ex b/lib/pleroma/web/activity_pub/mrf/anti_link_spam_policy.ex @@ -9,6 +9,9 @@ defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicy do require Logger + @impl true + def history_awareness, do: :auto + # has the user successfully posted before? defp old_user?(%User{} = u) do u.note_count > 0 || u.follower_count > 0 diff --git a/test/pleroma/web/activity_pub/mrf/anti_link_spam_policy_test.exs b/test/pleroma/web/activity_pub/mrf/anti_link_spam_policy_test.exs @@ -7,6 +7,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicyTest do import Pleroma.Factory import ExUnit.CaptureLog + alias Pleroma.Web.ActivityPub.MRF alias Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicy @linkless_message %{ @@ -49,15 +50,39 @@ defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicyTest do assert user.note_count == 0 + message = %{ + "type" => "Create", + "actor" => user.ap_id, + "object" => %{ + "formerRepresentations" => %{ + "type" => "OrderedCollection", + "orderedItems" => [ + %{ + "content" => "<a href='https://example.com'>hi world!</a>" + } + ] + }, + "content" => "mew" + } + } + + {:reject, _} = MRF.filter_one(AntiLinkSpamPolicy, message) + end + + test "it allows posts with links for local users" do + user = insert(:user) + + assert user.note_count == 0 + message = @linkful_message |> Map.put("actor", user.ap_id) - {:reject, _} = AntiLinkSpamPolicy.filter(message) + {:ok, _message} = AntiLinkSpamPolicy.filter(message) end - test "it allows posts with links for local users" do - user = insert(:user) + test "it disallows posts with links in history" do + user = insert(:user, local: false) assert user.note_count == 0 @@ -65,7 +90,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicyTest do @linkful_message |> Map.put("actor", user.ap_id) - {:ok, _message} = AntiLinkSpamPolicy.filter(message) + {:reject, _} = AntiLinkSpamPolicy.filter(message) end end