Merge branch 'chores/mrf-loglevel' into 'develop'

Fetcher: Correctly return MRF reject reason

See merge request pleroma/pleroma!2990
This commit is contained in:
rinpatch 2020-09-16 13:37:04 +00:00
commit eca8d26784
3 changed files with 23 additions and 10 deletions

View File

@ -98,8 +98,8 @@ defmodule Pleroma.Object.Fetcher do
{:containment, _} -> {:containment, _} ->
{:error, "Object containment failed."} {:error, "Object containment failed."}
{:transmogrifier, {:error, {:reject, nil}}} -> {:transmogrifier, {:error, {:reject, e}}} ->
{:reject, nil} {:reject, e}
{:transmogrifier, _} = e -> {:transmogrifier, _} = e ->
{:error, e} {:error, e}

View File

@ -154,8 +154,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
{:remote_limit_pass, _} -> {:remote_limit_pass, _} ->
{:error, :remote_limit} {:error, :remote_limit}
{:reject, reason} -> {:reject, _} = e ->
{:error, reason} {:error, e}
end end
end end

View File

@ -6,10 +6,13 @@ defmodule Pleroma.Object.FetcherTest do
use Pleroma.DataCase use Pleroma.DataCase
alias Pleroma.Activity alias Pleroma.Activity
alias Pleroma.Config
alias Pleroma.Object alias Pleroma.Object
alias Pleroma.Object.Fetcher alias Pleroma.Object.Fetcher
import Tesla.Mock
import ExUnit.CaptureLog
import Mock import Mock
import Tesla.Mock
setup do setup do
mock(fn mock(fn
@ -71,20 +74,20 @@ defmodule Pleroma.Object.FetcherTest do
setup do: clear_config([:instance, :federation_incoming_replies_max_depth]) setup do: clear_config([:instance, :federation_incoming_replies_max_depth])
test "it returns thread depth exceeded error if thread depth is exceeded" do test "it returns thread depth exceeded error if thread depth is exceeded" do
Pleroma.Config.put([:instance, :federation_incoming_replies_max_depth], 0) Config.put([:instance, :federation_incoming_replies_max_depth], 0)
assert {:error, "Max thread distance exceeded."} = assert {:error, "Max thread distance exceeded."} =
Fetcher.fetch_object_from_id(@ap_id, depth: 1) Fetcher.fetch_object_from_id(@ap_id, depth: 1)
end end
test "it fetches object if max thread depth is restricted to 0 and depth is not specified" do test "it fetches object if max thread depth is restricted to 0 and depth is not specified" do
Pleroma.Config.put([:instance, :federation_incoming_replies_max_depth], 0) Config.put([:instance, :federation_incoming_replies_max_depth], 0)
assert {:ok, _} = Fetcher.fetch_object_from_id(@ap_id) assert {:ok, _} = Fetcher.fetch_object_from_id(@ap_id)
end end
test "it fetches object if requested depth does not exceed max thread depth" do test "it fetches object if requested depth does not exceed max thread depth" do
Pleroma.Config.put([:instance, :federation_incoming_replies_max_depth], 10) Config.put([:instance, :federation_incoming_replies_max_depth], 10)
assert {:ok, _} = Fetcher.fetch_object_from_id(@ap_id, depth: 10) assert {:ok, _} = Fetcher.fetch_object_from_id(@ap_id, depth: 10)
end end
@ -120,6 +123,16 @@ defmodule Pleroma.Object.FetcherTest do
assert object == object_again assert object == object_again
end end
test "Return MRF reason when fetched status is rejected by one" do
clear_config([:mrf_keyword, :reject], ["yeah"])
clear_config([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.KeywordPolicy])
assert {:reject, "[KeywordPolicy] Matches with rejected keyword"} ==
Fetcher.fetch_object_from_id(
"http://mastodon.example.org/@admin/99541947525187367"
)
end
end end
describe "implementation quirks" do describe "implementation quirks" do
@ -212,7 +225,7 @@ defmodule Pleroma.Object.FetcherTest do
Pleroma.Signature, Pleroma.Signature,
[:passthrough], [:passthrough],
[] do [] do
Pleroma.Config.put([:activitypub, :sign_object_fetches], true) Config.put([:activitypub, :sign_object_fetches], true)
Fetcher.fetch_object_from_id("http://mastodon.example.org/@admin/99541947525187367") Fetcher.fetch_object_from_id("http://mastodon.example.org/@admin/99541947525187367")
@ -223,7 +236,7 @@ defmodule Pleroma.Object.FetcherTest do
Pleroma.Signature, Pleroma.Signature,
[:passthrough], [:passthrough],
[] do [] do
Pleroma.Config.put([:activitypub, :sign_object_fetches], false) Config.put([:activitypub, :sign_object_fetches], false)
Fetcher.fetch_object_from_id("http://mastodon.example.org/@admin/99541947525187367") Fetcher.fetch_object_from_id("http://mastodon.example.org/@admin/99541947525187367")