RemoteReportPolicy: add :reject_all
option, fix tests
This commit is contained in:
parent
4533f171ab
commit
b7c91876d2
3 changed files with 40 additions and 1 deletions
|
@ -435,6 +435,7 @@
|
||||||
config :pleroma, :mrf_inline_quote, template: "<bdi>RT:</bdi> {url}"
|
config :pleroma, :mrf_inline_quote, template: "<bdi>RT:</bdi> {url}"
|
||||||
|
|
||||||
config :pleroma, :mrf_remote_report,
|
config :pleroma, :mrf_remote_report,
|
||||||
|
reject_all: false,
|
||||||
reject_anonymous: true,
|
reject_anonymous: true,
|
||||||
reject_empty_message: true
|
reject_empty_message: true
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.RemoteReportPolicy do
|
||||||
@impl true
|
@impl true
|
||||||
def filter(%{"type" => "Flag"} = object) do
|
def filter(%{"type" => "Flag"} = object) do
|
||||||
with {_, false} <- {:local, local?(object)},
|
with {_, false} <- {:local, local?(object)},
|
||||||
|
{:ok, _} <- maybe_reject_all(object),
|
||||||
{:ok, _} <- maybe_reject_anonymous(object),
|
{:ok, _} <- maybe_reject_anonymous(object),
|
||||||
{:ok, _} <- maybe_reject_empty_message(object) do
|
{:ok, _} <- maybe_reject_empty_message(object) do
|
||||||
{:ok, object}
|
{:ok, object}
|
||||||
|
@ -19,6 +20,14 @@ def filter(%{"type" => "Flag"} = object) do
|
||||||
|
|
||||||
def filter(object), do: {:ok, object}
|
def filter(object), do: {:ok, object}
|
||||||
|
|
||||||
|
defp maybe_reject_all(object) do
|
||||||
|
if Config.get([:mrf_remote_report, :reject_all]) do
|
||||||
|
{:reject, "[RemoteReportPolicy] Remote report"}
|
||||||
|
else
|
||||||
|
{:ok, object}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
defp maybe_reject_anonymous(%{"actor" => actor} = object) do
|
defp maybe_reject_anonymous(%{"actor" => actor} = object) do
|
||||||
with true <- Config.get([:mrf_remote_report, :reject_anonymous]),
|
with true <- Config.get([:mrf_remote_report, :reject_anonymous]),
|
||||||
%URI{path: "/actor"} <- URI.parse(actor) do
|
%URI{path: "/actor"} <- URI.parse(actor) do
|
||||||
|
@ -62,6 +71,12 @@ def config_description do
|
||||||
label: "MRF Remote Report",
|
label: "MRF Remote Report",
|
||||||
description: "Drop remote reports if they don't contain enough information.",
|
description: "Drop remote reports if they don't contain enough information.",
|
||||||
children: [
|
children: [
|
||||||
|
%{
|
||||||
|
key: :reject_all,
|
||||||
|
type: :boolean,
|
||||||
|
description: "Reject all remote reports? (this option takes precedence)",
|
||||||
|
suggestions: [false]
|
||||||
|
},
|
||||||
%{
|
%{
|
||||||
key: :reject_anonymous,
|
key: :reject_anonymous,
|
||||||
type: :boolean,
|
type: :boolean,
|
||||||
|
|
|
@ -3,6 +3,10 @@ defmodule Pleroma.Web.ActivityPub.MRF.RemoteReportPolicyTest do
|
||||||
|
|
||||||
alias Pleroma.Web.ActivityPub.MRF.RemoteReportPolicy
|
alias Pleroma.Web.ActivityPub.MRF.RemoteReportPolicy
|
||||||
|
|
||||||
|
setup do
|
||||||
|
clear_config([:mrf_remote_report, :reject_all], false)
|
||||||
|
end
|
||||||
|
|
||||||
test "doesn't impact local report" do
|
test "doesn't impact local report" do
|
||||||
clear_config([:mrf_remote_report, :reject_anonymous], true)
|
clear_config([:mrf_remote_report, :reject_anonymous], true)
|
||||||
clear_config([:mrf_remote_report, :reject_empty_message], true)
|
clear_config([:mrf_remote_report, :reject_empty_message], true)
|
||||||
|
@ -17,6 +21,7 @@ test "doesn't impact local report" do
|
||||||
|
|
||||||
test "rejects anonymous report if `reject_anonymous: true`" do
|
test "rejects anonymous report if `reject_anonymous: true`" do
|
||||||
clear_config([:mrf_remote_report, :reject_anonymous], true)
|
clear_config([:mrf_remote_report, :reject_anonymous], true)
|
||||||
|
clear_config([:mrf_remote_report, :reject_empty_message], true)
|
||||||
|
|
||||||
activity = %{
|
activity = %{
|
||||||
"type" => "Flag",
|
"type" => "Flag",
|
||||||
|
@ -28,6 +33,7 @@ test "rejects anonymous report if `reject_anonymous: true`" do
|
||||||
|
|
||||||
test "preserves anonymous report if `reject_anonymous: false`" do
|
test "preserves anonymous report if `reject_anonymous: false`" do
|
||||||
clear_config([:mrf_remote_report, :reject_anonymous], false)
|
clear_config([:mrf_remote_report, :reject_anonymous], false)
|
||||||
|
clear_config([:mrf_remote_report, :reject_empty_message], false)
|
||||||
|
|
||||||
activity = %{
|
activity = %{
|
||||||
"type" => "Flag",
|
"type" => "Flag",
|
||||||
|
@ -38,6 +44,7 @@ test "preserves anonymous report if `reject_anonymous: false`" do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "rejects empty message report if `reject_empty_message: true`" do
|
test "rejects empty message report if `reject_empty_message: true`" do
|
||||||
|
clear_config([:mrf_remote_report, :reject_anonymous], false)
|
||||||
clear_config([:mrf_remote_report, :reject_empty_message], true)
|
clear_config([:mrf_remote_report, :reject_empty_message], true)
|
||||||
|
|
||||||
activity = %{
|
activity = %{
|
||||||
|
@ -49,6 +56,7 @@ test "rejects empty message report if `reject_empty_message: true`" do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "rejects empty message report (\"\") if `reject_empty_message: true`" do
|
test "rejects empty message report (\"\") if `reject_empty_message: true`" do
|
||||||
|
clear_config([:mrf_remote_report, :reject_anonymous], false)
|
||||||
clear_config([:mrf_remote_report, :reject_empty_message], true)
|
clear_config([:mrf_remote_report, :reject_empty_message], true)
|
||||||
|
|
||||||
activity = %{
|
activity = %{
|
||||||
|
@ -61,6 +69,7 @@ test "rejects empty message report (\"\") if `reject_empty_message: true`" do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "preserves empty message report if `reject_empty_message: false`" do
|
test "preserves empty message report if `reject_empty_message: false`" do
|
||||||
|
clear_config([:mrf_remote_report, :reject_anonymous], false)
|
||||||
clear_config([:mrf_remote_report, :reject_empty_message], false)
|
clear_config([:mrf_remote_report, :reject_empty_message], false)
|
||||||
|
|
||||||
activity = %{
|
activity = %{
|
||||||
|
@ -72,7 +81,7 @@ test "preserves empty message report if `reject_empty_message: false`" do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "preserves anonymous, empty message report with all settings disabled" do
|
test "preserves anonymous, empty message report with all settings disabled" do
|
||||||
clear_config([:mrf_remote_report, :reject_empty_message], false)
|
clear_config([:mrf_remote_report, :reject_anonymous], false)
|
||||||
clear_config([:mrf_remote_report, :reject_empty_message], false)
|
clear_config([:mrf_remote_report, :reject_empty_message], false)
|
||||||
|
|
||||||
activity = %{
|
activity = %{
|
||||||
|
@ -82,4 +91,18 @@ test "preserves anonymous, empty message report with all settings disabled" do
|
||||||
|
|
||||||
assert {:ok, _} = RemoteReportPolicy.filter(activity)
|
assert {:ok, _} = RemoteReportPolicy.filter(activity)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "reject remote report if `reject_all: true`" do
|
||||||
|
clear_config([:mrf_remote_report, :reject_all], true)
|
||||||
|
clear_config([:mrf_remote_report, :reject_anonymous], false)
|
||||||
|
clear_config([:mrf_remote_report, :reject_empty_message], false)
|
||||||
|
|
||||||
|
activity = %{
|
||||||
|
"type" => "Flag",
|
||||||
|
"actor" => "https://mastodon.social/users/Gargron",
|
||||||
|
"content" => "Transphobia"
|
||||||
|
}
|
||||||
|
|
||||||
|
assert {:reject, _} = RemoteReportPolicy.filter(activity)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue