logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

remote_fetcher_worker_test.exs (2076B)


  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. defmodule Pleroma.Workers.RemoteFetcherWorkerTest do
  5. use Pleroma.DataCase
  6. use Oban.Testing, repo: Pleroma.Repo
  7. alias Pleroma.Workers.RemoteFetcherWorker
  8. @deleted_object_one "https://deleted-404.example.com/"
  9. @deleted_object_two "https://deleted-410.example.com/"
  10. @unauthorized_object "https://unauthorized.example.com/"
  11. @depth_object "https://depth.example.com/"
  12. describe "RemoteFetcherWorker" do
  13. setup do
  14. Tesla.Mock.mock(fn
  15. %{method: :get, url: @deleted_object_one} ->
  16. %Tesla.Env{
  17. status: 404
  18. }
  19. %{method: :get, url: @deleted_object_two} ->
  20. %Tesla.Env{
  21. status: 410
  22. }
  23. %{method: :get, url: @unauthorized_object} ->
  24. %Tesla.Env{
  25. status: 403
  26. }
  27. %{method: :get, url: @depth_object} ->
  28. %Tesla.Env{
  29. status: 200
  30. }
  31. end)
  32. end
  33. test "does not requeue a deleted object" do
  34. assert {:discard, _} =
  35. RemoteFetcherWorker.perform(%Oban.Job{
  36. args: %{"op" => "fetch_remote", "id" => @deleted_object_one}
  37. })
  38. assert {:discard, _} =
  39. RemoteFetcherWorker.perform(%Oban.Job{
  40. args: %{"op" => "fetch_remote", "id" => @deleted_object_two}
  41. })
  42. end
  43. test "does not requeue an unauthorized object" do
  44. assert {:discard, _} =
  45. RemoteFetcherWorker.perform(%Oban.Job{
  46. args: %{"op" => "fetch_remote", "id" => @unauthorized_object}
  47. })
  48. end
  49. test "does not requeue an object that exceeded depth" do
  50. clear_config([:instance, :federation_incoming_replies_max_depth], 0)
  51. assert {:discard, _} =
  52. RemoteFetcherWorker.perform(%Oban.Job{
  53. args: %{"op" => "fetch_remote", "id" => @depth_object, "depth" => 1}
  54. })
  55. end
  56. end
  57. end