1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.MediaProxy.InvalidationTest do
8 alias Pleroma.Web.MediaProxy.Invalidation
10 import ExUnit.CaptureLog
14 setup do: clear_config([:media_proxy])
16 describe "Invalidation.Http" do
17 test "perform request to clear cache" do
18 clear_config([:media_proxy, :enabled], false)
19 clear_config([:media_proxy, :invalidation, :enabled], true)
20 clear_config([:media_proxy, :invalidation, :provider], Invalidation.Http)
22 clear_config([Invalidation.Http], method: :purge, headers: [{"x-refresh", 1}])
23 image_url = "http://example.com/media/example.jpg"
24 Pleroma.Web.MediaProxy.put_in_banned_urls(image_url)
29 url: "http://example.com/media/example.jpg",
30 headers: [{"x-refresh", 1}]
32 %Tesla.Env{status: 200}
35 assert capture_log(fn ->
36 assert Pleroma.Web.MediaProxy.in_banned_urls(image_url)
37 assert Invalidation.purge([image_url]) == {:ok, [image_url]}
38 assert Pleroma.Web.MediaProxy.in_banned_urls(image_url)
39 end) =~ "Running cache purge: [\"#{image_url}\"]"
43 describe "Invalidation.Script" do
44 test "run script to clear cache" do
45 clear_config([:media_proxy, :enabled], false)
46 clear_config([:media_proxy, :invalidation, :enabled], true)
47 clear_config([:media_proxy, :invalidation, :provider], Invalidation.Script)
48 clear_config([Invalidation.Script], script_path: "purge-nginx")
50 image_url = "http://example.com/media/example.jpg"
51 Pleroma.Web.MediaProxy.put_in_banned_urls(image_url)
53 with_mocks [{System, [], [cmd: fn _, _ -> {"ok", 0} end]}] do
54 assert capture_log(fn ->
55 assert Pleroma.Web.MediaProxy.in_banned_urls(image_url)
56 assert Invalidation.purge([image_url]) == {:ok, [image_url]}
57 assert Pleroma.Web.MediaProxy.in_banned_urls(image_url)
58 end) =~ "Running cache purge: [\"#{image_url}\"]"