logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git
commit: ad0a5deb67f454b0529a4faf72399cd9ecc9c0e6
parent a2708f7fe31c6009b0c9954e5de3b74c45f9818f
Author: Mark Felder <feld@feld.me>
Date:   Wed, 27 Dec 2023 22:28:41 -0500

Prevent requeuing Remote Fetcher jobs that exceed thread depth

Diffstat:

Mchangelog.d/handle_object_fetch_failures.change2+-
Mlib/pleroma/object/fetcher.ex2+-
Mlib/pleroma/workers/remote_fetcher_worker.ex3+++
Mtest/pleroma/object/fetcher_test.exs3+--
Mtest/pleroma/workers/remote_fetcher_worker_test.exs15+++++++++++++++
5 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/changelog.d/handle_object_fetch_failures.change b/changelog.d/handle_object_fetch_failures.change @@ -1 +1 @@ -Remote object fetch failures will prevent the object fetch job from retrying if the object has been deleted or the fetch was denied with a 403. +Remote object fetch failures will prevent the object fetch job from retrying if the object request returns 403, 404, 410, or exceeds the maximum thread depth. diff --git a/lib/pleroma/object/fetcher.ex b/lib/pleroma/object/fetcher.ex @@ -74,7 +74,7 @@ defmodule Pleroma.Object.Fetcher do else {:allowed_depth, false} = e -> log_fetch_error(id, e) - {:error, "Max thread distance exceeded."} + {:error, :allowed_depth} {:containment, reason} = e -> log_fetch_error(id, e) diff --git a/lib/pleroma/workers/remote_fetcher_worker.ex b/lib/pleroma/workers/remote_fetcher_worker.ex @@ -21,6 +21,9 @@ defmodule Pleroma.Workers.RemoteFetcherWorker do {:error, :not_found} -> {:cancel, :not_found} + {:error, :allowed_depth} -> + {:cancel, :allowed_depth} + _ -> :error end diff --git a/test/pleroma/object/fetcher_test.exs b/test/pleroma/object/fetcher_test.exs @@ -101,8 +101,7 @@ defmodule Pleroma.Object.FetcherTest do test "it returns thread depth exceeded error if thread depth is exceeded" do clear_config([:instance, :federation_incoming_replies_max_depth], 0) - assert {:error, "Max thread distance exceeded."} = - Fetcher.fetch_object_from_id(@ap_id, depth: 1) + assert {:error, :allowed_depth} = 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 diff --git a/test/pleroma/workers/remote_fetcher_worker_test.exs b/test/pleroma/workers/remote_fetcher_worker_test.exs @@ -13,6 +13,7 @@ defmodule Pleroma.Workers.RemoteFetcherWorkerTest do @deleted_object_two "https://deleted-410.example.com/" @unauthorized_object "https://unauthorized.example.com/" @unreachable_object "https://unreachable.example.com/" + @depth_object "https://depth.example.com/" describe "it does not" do setup do @@ -31,6 +32,11 @@ defmodule Pleroma.Workers.RemoteFetcherWorkerTest do %Tesla.Env{ status: 403 } + + %{method: :get, url: @depth_object} -> + %Tesla.Env{ + status: 200 + } end) end @@ -63,5 +69,14 @@ defmodule Pleroma.Workers.RemoteFetcherWorkerTest do args: %{"op" => "fetch_remote", "id" => @unreachable_object} }) end + + test "requeue an object that exceeded depth" do + clear_config([:instance, :federation_incoming_replies_max_depth], 0) + + assert {:cancel, _} = + RemoteFetcherWorker.perform(%Oban.Job{ + args: %{"op" => "fetch_remote", "id" => @depth_object, "depth" => 1} + }) + end end end