logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

invalidation_test.exs (2222B)


  1. defmodule Pleroma.Web.MediaProxy.InvalidationTest do
  2. use ExUnit.Case
  3. use Pleroma.Tests.Helpers
  4. alias Pleroma.Config
  5. alias Pleroma.Web.MediaProxy.Invalidation
  6. import ExUnit.CaptureLog
  7. import Mock
  8. import Tesla.Mock
  9. setup do: clear_config([:media_proxy])
  10. setup do
  11. on_exit(fn -> Cachex.clear(:banned_urls_cache) end)
  12. end
  13. describe "Invalidation.Http" do
  14. test "perform request to clear cache" do
  15. Config.put([:media_proxy, :enabled], false)
  16. Config.put([:media_proxy, :invalidation, :enabled], true)
  17. Config.put([:media_proxy, :invalidation, :provider], Invalidation.Http)
  18. Config.put([Invalidation.Http], method: :purge, headers: [{"x-refresh", 1}])
  19. image_url = "http://example.com/media/example.jpg"
  20. Pleroma.Web.MediaProxy.put_in_banned_urls(image_url)
  21. mock(fn
  22. %{
  23. method: :purge,
  24. url: "http://example.com/media/example.jpg",
  25. headers: [{"x-refresh", 1}]
  26. } ->
  27. %Tesla.Env{status: 200}
  28. end)
  29. assert capture_log(fn ->
  30. assert Pleroma.Web.MediaProxy.in_banned_urls(image_url)
  31. assert Invalidation.purge([image_url]) == {:ok, [image_url]}
  32. assert Pleroma.Web.MediaProxy.in_banned_urls(image_url)
  33. end) =~ "Running cache purge: [\"#{image_url}\"]"
  34. end
  35. end
  36. describe "Invalidation.Script" do
  37. test "run script to clear cache" do
  38. Config.put([:media_proxy, :enabled], false)
  39. Config.put([:media_proxy, :invalidation, :enabled], true)
  40. Config.put([:media_proxy, :invalidation, :provider], Invalidation.Script)
  41. Config.put([Invalidation.Script], script_path: "purge-nginx")
  42. image_url = "http://example.com/media/example.jpg"
  43. Pleroma.Web.MediaProxy.put_in_banned_urls(image_url)
  44. with_mocks [{System, [], [cmd: fn _, _ -> {"ok", 0} end]}] do
  45. assert capture_log(fn ->
  46. assert Pleroma.Web.MediaProxy.in_banned_urls(image_url)
  47. assert Invalidation.purge([image_url]) == {:ok, [image_url]}
  48. assert Pleroma.Web.MediaProxy.in_banned_urls(image_url)
  49. end) =~ "Running cache purge: [\"#{image_url}\"]"
  50. end
  51. end
  52. end
  53. end