logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma
commit: eca8d267846afc802f9a5ceed036482a9c90b4e2
parent: adbd0032fab0f2515689fd2ab6629fb8cd05b09d
Author: rinpatch <rinpatch@sdf.org>
Date:   Wed, 16 Sep 2020 13:37:04 +0000

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

Fetcher: Correctly return MRF reject reason

See merge request pleroma/pleroma!2990

Diffstat:

Mlib/pleroma/object/fetcher.ex4++--
Mlib/pleroma/web/activity_pub/activity_pub.ex4++--
Mtest/object/fetcher_test.exs25+++++++++++++++++++------
3 files changed, 23 insertions(+), 10 deletions(-)

diff --git a/lib/pleroma/object/fetcher.ex b/lib/pleroma/object/fetcher.ex @@ -98,8 +98,8 @@ defmodule Pleroma.Object.Fetcher do {:containment, _} -> {:error, "Object containment failed."} - {:transmogrifier, {:error, {:reject, nil}}} -> - {:reject, nil} + {:transmogrifier, {:error, {:reject, e}}} -> + {:reject, e} {:transmogrifier, _} = e -> {:error, e} diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -154,8 +154,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do {:remote_limit_pass, _} -> {:error, :remote_limit} - {:reject, reason} -> - {:error, reason} + {:reject, _} = e -> + {:error, e} end end diff --git a/test/object/fetcher_test.exs b/test/object/fetcher_test.exs @@ -6,10 +6,13 @@ defmodule Pleroma.Object.FetcherTest do use Pleroma.DataCase alias Pleroma.Activity + alias Pleroma.Config alias Pleroma.Object alias Pleroma.Object.Fetcher - import Tesla.Mock + + import ExUnit.CaptureLog import Mock + import Tesla.Mock setup do mock(fn @@ -71,20 +74,20 @@ defmodule Pleroma.Object.FetcherTest do setup do: clear_config([:instance, :federation_incoming_replies_max_depth]) 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."} = Fetcher.fetch_object_from_id(@ap_id, depth: 1) end 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) end 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) end @@ -120,6 +123,16 @@ defmodule Pleroma.Object.FetcherTest do assert object == object_again 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 describe "implementation quirks" do @@ -212,7 +225,7 @@ defmodule Pleroma.Object.FetcherTest do Pleroma.Signature, [:passthrough], [] 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") @@ -223,7 +236,7 @@ defmodule Pleroma.Object.FetcherTest do Pleroma.Signature, [:passthrough], [] 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")