1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.MediaProxy.InvalidationTest do
7 use Pleroma.Tests.Helpers
10 alias Pleroma.Web.MediaProxy.Invalidation
12 import ExUnit.CaptureLog
16 setup do: clear_config([:media_proxy])
19 on_exit(fn -> Cachex.clear(:banned_urls_cache) end)
22 describe "Invalidation.Http" do
23 test "perform request to clear cache" do
24 Config.put([:media_proxy, :enabled], false)
25 Config.put([:media_proxy, :invalidation, :enabled], true)
26 Config.put([:media_proxy, :invalidation, :provider], Invalidation.Http)
28 Config.put([Invalidation.Http], method: :purge, headers: [{"x-refresh", 1}])
29 image_url = "http://example.com/media/example.jpg"
30 Pleroma.Web.MediaProxy.put_in_banned_urls(image_url)
35 url: "http://example.com/media/example.jpg",
36 headers: [{"x-refresh", 1}]
38 %Tesla.Env{status: 200}
41 assert capture_log(fn ->
42 assert Pleroma.Web.MediaProxy.in_banned_urls(image_url)
43 assert Invalidation.purge([image_url]) == {:ok, [image_url]}
44 assert Pleroma.Web.MediaProxy.in_banned_urls(image_url)
45 end) =~ "Running cache purge: [\"#{image_url}\"]"
49 describe "Invalidation.Script" do
50 test "run script to clear cache" do
51 Config.put([:media_proxy, :enabled], false)
52 Config.put([:media_proxy, :invalidation, :enabled], true)
53 Config.put([:media_proxy, :invalidation, :provider], Invalidation.Script)
54 Config.put([Invalidation.Script], script_path: "purge-nginx")
56 image_url = "http://example.com/media/example.jpg"
57 Pleroma.Web.MediaProxy.put_in_banned_urls(image_url)
59 with_mocks [{System, [], [cmd: fn _, _ -> {"ok", 0} end]}] do
60 assert capture_log(fn ->
61 assert Pleroma.Web.MediaProxy.in_banned_urls(image_url)
62 assert Invalidation.purge([image_url]) == {:ok, [image_url]}
63 assert Pleroma.Web.MediaProxy.in_banned_urls(image_url)
64 end) =~ "Running cache purge: [\"#{image_url}\"]"