logo

pleroma

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

remote_fetcher_worker_test.exs (2577B)


  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. @content_type_object "https://bad_content_type.example.com/"
  13. describe "RemoteFetcherWorker" do
  14. setup do
  15. Tesla.Mock.mock(fn
  16. %{method: :get, url: @deleted_object_one} ->
  17. %Tesla.Env{
  18. status: 404
  19. }
  20. %{method: :get, url: @deleted_object_two} ->
  21. %Tesla.Env{
  22. status: 410
  23. }
  24. %{method: :get, url: @unauthorized_object} ->
  25. %Tesla.Env{
  26. status: 403
  27. }
  28. %{method: :get, url: @depth_object} ->
  29. %Tesla.Env{
  30. status: 200
  31. }
  32. %{method: :get, url: @content_type_object} ->
  33. %Tesla.Env{
  34. status: 200,
  35. headers: [{"content-type", "application/json"}],
  36. body: File.read!("test/fixtures/spoofed-object.json")
  37. }
  38. end)
  39. end
  40. test "does not retry jobs for a deleted object" do
  41. [
  42. %{"op" => "fetch_remote", "id" => @deleted_object_one},
  43. %{"op" => "fetch_remote", "id" => @deleted_object_two}
  44. ]
  45. |> Enum.each(fn job -> assert {:cancel, _} = perform_job(RemoteFetcherWorker, job) end)
  46. end
  47. test "does not retry jobs for an unauthorized object" do
  48. assert {:cancel, _} =
  49. perform_job(RemoteFetcherWorker, %{
  50. "op" => "fetch_remote",
  51. "id" => @unauthorized_object
  52. })
  53. end
  54. test "does not retry jobs for an an object that exceeded depth" do
  55. clear_config([:instance, :federation_incoming_replies_max_depth], 0)
  56. assert {:cancel, _} =
  57. perform_job(RemoteFetcherWorker, %{
  58. "op" => "fetch_remote",
  59. "id" => @depth_object,
  60. "depth" => 1
  61. })
  62. end
  63. test "does not retry jobs for when object returns wrong content type" do
  64. assert {:cancel, _} =
  65. perform_job(RemoteFetcherWorker, %{
  66. "op" => "fetch_remote",
  67. "id" => @content_type_object
  68. })
  69. end
  70. end
  71. end