mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-11-14 05:04:49 +00:00
Allow the Remote Fetcher to attempt fetching an unreachable instance
This commit is contained in:
parent
fed7a78c77
commit
2e369aef71
2 changed files with 11 additions and 29 deletions
|
@ -3,32 +3,27 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.Workers.RemoteFetcherWorker do
|
defmodule Pleroma.Workers.RemoteFetcherWorker do
|
||||||
alias Pleroma.Instances
|
|
||||||
alias Pleroma.Object.Fetcher
|
alias Pleroma.Object.Fetcher
|
||||||
|
|
||||||
use Pleroma.Workers.WorkerHelper, queue: "remote_fetcher"
|
use Pleroma.Workers.WorkerHelper, queue: "remote_fetcher"
|
||||||
|
|
||||||
@impl Oban.Worker
|
@impl Oban.Worker
|
||||||
def perform(%Job{args: %{"op" => "fetch_remote", "id" => id} = args}) do
|
def perform(%Job{args: %{"op" => "fetch_remote", "id" => id} = args}) do
|
||||||
if Instances.reachable?(id) do
|
case Fetcher.fetch_object_from_id(id, depth: args["depth"]) do
|
||||||
case Fetcher.fetch_object_from_id(id, depth: args["depth"]) do
|
{:ok, _object} ->
|
||||||
{:ok, _object} ->
|
:ok
|
||||||
:ok
|
|
||||||
|
|
||||||
{:error, :forbidden} ->
|
{:error, :forbidden} ->
|
||||||
{:discard, :forbidden}
|
{:discard, :forbidden}
|
||||||
|
|
||||||
{:error, :not_found} ->
|
{:error, :not_found} ->
|
||||||
{:discard, :not_found}
|
{:discard, :not_found}
|
||||||
|
|
||||||
{:error, :allowed_depth} ->
|
{:error, :allowed_depth} ->
|
||||||
{:discard, :allowed_depth}
|
{:discard, :allowed_depth}
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
:error
|
:error
|
||||||
end
|
|
||||||
else
|
|
||||||
{:discard, "Unreachable instance"}
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,13 +6,11 @@ defmodule Pleroma.Workers.RemoteFetcherWorkerTest do
|
||||||
use Pleroma.DataCase
|
use Pleroma.DataCase
|
||||||
use Oban.Testing, repo: Pleroma.Repo
|
use Oban.Testing, repo: Pleroma.Repo
|
||||||
|
|
||||||
alias Pleroma.Instances
|
|
||||||
alias Pleroma.Workers.RemoteFetcherWorker
|
alias Pleroma.Workers.RemoteFetcherWorker
|
||||||
|
|
||||||
@deleted_object_one "https://deleted-404.example.com/"
|
@deleted_object_one "https://deleted-404.example.com/"
|
||||||
@deleted_object_two "https://deleted-410.example.com/"
|
@deleted_object_two "https://deleted-410.example.com/"
|
||||||
@unauthorized_object "https://unauthorized.example.com/"
|
@unauthorized_object "https://unauthorized.example.com/"
|
||||||
@unreachable_object "https://unreachable.example.com/"
|
|
||||||
@depth_object "https://depth.example.com/"
|
@depth_object "https://depth.example.com/"
|
||||||
|
|
||||||
describe "RemoteFetcherWorker" do
|
describe "RemoteFetcherWorker" do
|
||||||
|
@ -59,17 +57,6 @@ defmodule Pleroma.Workers.RemoteFetcherWorkerTest do
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
test "does not fetch an unreachable instance" do
|
|
||||||
Instances.set_consistently_unreachable(@unreachable_object)
|
|
||||||
|
|
||||||
refute Instances.reachable?(@unreachable_object)
|
|
||||||
|
|
||||||
assert {:discard, _} =
|
|
||||||
RemoteFetcherWorker.perform(%Oban.Job{
|
|
||||||
args: %{"op" => "fetch_remote", "id" => @unreachable_object}
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
test "does not requeue an object that exceeded depth" do
|
test "does not requeue an object that exceeded depth" do
|
||||||
clear_config([:instance, :federation_incoming_replies_max_depth], 0)
|
clear_config([:instance, :federation_incoming_replies_max_depth], 0)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue