2023-12-27 21:06:10 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
|
|
|
# Copyright © 2017-2023 Pleroma Authors <https://pleroma.social/>
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Workers.RemoteFetcherWorkerTest do
|
|
|
|
use Pleroma.DataCase
|
|
|
|
use Oban.Testing, repo: Pleroma.Repo
|
|
|
|
|
|
|
|
alias Pleroma.Workers.RemoteFetcherWorker
|
|
|
|
|
|
|
|
@deleted_object_one "https://deleted-404.example.com/"
|
|
|
|
@deleted_object_two "https://deleted-410.example.com/"
|
|
|
|
@unauthorized_object "https://unauthorized.example.com/"
|
2023-12-28 03:28:41 +00:00
|
|
|
@depth_object "https://depth.example.com/"
|
2023-12-27 21:06:10 +00:00
|
|
|
|
2023-12-28 03:37:06 +00:00
|
|
|
describe "RemoteFetcherWorker" do
|
2023-12-27 21:06:10 +00:00
|
|
|
setup do
|
|
|
|
Tesla.Mock.mock(fn
|
|
|
|
%{method: :get, url: @deleted_object_one} ->
|
|
|
|
%Tesla.Env{
|
|
|
|
status: 404
|
|
|
|
}
|
|
|
|
|
|
|
|
%{method: :get, url: @deleted_object_two} ->
|
|
|
|
%Tesla.Env{
|
|
|
|
status: 410
|
|
|
|
}
|
|
|
|
|
|
|
|
%{method: :get, url: @unauthorized_object} ->
|
|
|
|
%Tesla.Env{
|
|
|
|
status: 403
|
|
|
|
}
|
2023-12-28 03:28:41 +00:00
|
|
|
|
|
|
|
%{method: :get, url: @depth_object} ->
|
|
|
|
%Tesla.Env{
|
|
|
|
status: 200
|
|
|
|
}
|
2023-12-27 21:06:10 +00:00
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
2023-12-28 03:37:06 +00:00
|
|
|
test "does not requeue a deleted object" do
|
2023-12-29 04:52:05 +00:00
|
|
|
assert {:discard, _} =
|
2023-12-27 21:06:10 +00:00
|
|
|
RemoteFetcherWorker.perform(%Oban.Job{
|
|
|
|
args: %{"op" => "fetch_remote", "id" => @deleted_object_one}
|
|
|
|
})
|
|
|
|
|
2023-12-29 04:52:05 +00:00
|
|
|
assert {:discard, _} =
|
2023-12-27 21:06:10 +00:00
|
|
|
RemoteFetcherWorker.perform(%Oban.Job{
|
|
|
|
args: %{"op" => "fetch_remote", "id" => @deleted_object_two}
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2023-12-28 03:37:06 +00:00
|
|
|
test "does not requeue an unauthorized object" do
|
2023-12-29 04:52:05 +00:00
|
|
|
assert {:discard, _} =
|
2023-12-27 21:06:10 +00:00
|
|
|
RemoteFetcherWorker.perform(%Oban.Job{
|
|
|
|
args: %{"op" => "fetch_remote", "id" => @unauthorized_object}
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2023-12-28 03:37:06 +00:00
|
|
|
test "does not requeue an object that exceeded depth" do
|
2023-12-28 03:28:41 +00:00
|
|
|
clear_config([:instance, :federation_incoming_replies_max_depth], 0)
|
|
|
|
|
2023-12-29 04:52:05 +00:00
|
|
|
assert {:discard, _} =
|
2023-12-28 03:28:41 +00:00
|
|
|
RemoteFetcherWorker.perform(%Oban.Job{
|
|
|
|
args: %{"op" => "fetch_remote", "id" => @depth_object, "depth" => 1}
|
|
|
|
})
|
|
|
|
end
|
2023-12-27 21:06:10 +00:00
|
|
|
end
|
|
|
|
end
|