Make AntiLinkSpamPolicy history-aware

This commit is contained in:
Tusooa Zhu 2022-07-24 00:18:09 -04:00
parent d877d2a4e7
commit 997f08b350
No known key found for this signature in database
GPG Key ID: 7B467EDE43A08224
2 changed files with 32 additions and 4 deletions

View File

@ -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

View File

@ -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,11 +50,23 @@ test "it disallows posts with links" do
assert user.note_count == 0
message =
@linkful_message
|> Map.put("actor", user.ap_id)
message = %{
"type" => "Create",
"actor" => user.ap_id,
"object" => %{
"formerRepresentations" => %{
"type" => "OrderedCollection",
"orderedItems" => [
%{
"content" => "<a href='https://example.com'>hi world!</a>"
}
]
},
"content" => "mew"
}
}
{:reject, _} = AntiLinkSpamPolicy.filter(message)
{:reject, _} = MRF.filter_one(AntiLinkSpamPolicy, message)
end
test "it allows posts with links for local users" do
@ -67,6 +80,18 @@ test "it allows posts with links for local users" do
{:ok, _message} = AntiLinkSpamPolicy.filter(message)
end
test "it disallows posts with links in history" do
user = insert(:user, local: false)
assert user.note_count == 0
message =
@linkful_message
|> Map.put("actor", user.ap_id)
{:reject, _} = AntiLinkSpamPolicy.filter(message)
end
end
describe "with old user" do