total rebase
[anni] / test / pleroma / workers / remote_fetcher_worker_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2023 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Workers.RemoteFetcherWorkerTest do
6   use Pleroma.DataCase
7   use Oban.Testing, repo: Pleroma.Repo
8
9   alias Pleroma.Workers.RemoteFetcherWorker
10
11   @deleted_object_one "https://deleted-404.example.com/"
12   @deleted_object_two "https://deleted-410.example.com/"
13   @unauthorized_object "https://unauthorized.example.com/"
14   @depth_object "https://depth.example.com/"
15
16   describe "RemoteFetcherWorker" do
17     setup do
18       Tesla.Mock.mock(fn
19         %{method: :get, url: @deleted_object_one} ->
20           %Tesla.Env{
21             status: 404
22           }
23
24         %{method: :get, url: @deleted_object_two} ->
25           %Tesla.Env{
26             status: 410
27           }
28
29         %{method: :get, url: @unauthorized_object} ->
30           %Tesla.Env{
31             status: 403
32           }
33
34         %{method: :get, url: @depth_object} ->
35           %Tesla.Env{
36             status: 200
37           }
38       end)
39     end
40
41     test "does not requeue a deleted object" do
42       assert {:discard, _} =
43                RemoteFetcherWorker.perform(%Oban.Job{
44                  args: %{"op" => "fetch_remote", "id" => @deleted_object_one}
45                })
46
47       assert {:discard, _} =
48                RemoteFetcherWorker.perform(%Oban.Job{
49                  args: %{"op" => "fetch_remote", "id" => @deleted_object_two}
50                })
51     end
52
53     test "does not requeue an unauthorized object" do
54       assert {:discard, _} =
55                RemoteFetcherWorker.perform(%Oban.Job{
56                  args: %{"op" => "fetch_remote", "id" => @unauthorized_object}
57                })
58     end
59
60     test "does not requeue an object that exceeded depth" do
61       clear_config([:instance, :federation_incoming_replies_max_depth], 0)
62
63       assert {:discard, _} =
64                RemoteFetcherWorker.perform(%Oban.Job{
65                  args: %{"op" => "fetch_remote", "id" => @depth_object, "depth" => 1}
66                })
67     end
68   end
69 end