2020-10-12 11:00:50 -06:00
|
|
|
# Pleroma: A lightweight social networking server
|
2021-01-12 23:49:20 -07:00
|
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
2020-10-12 11:00:50 -06:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2020-06-14 12:02:57 -06:00
|
|
|
defmodule Pleroma.Web.MediaProxy.InvalidationTest do
|
2023-08-01 04:43:50 -06:00
|
|
|
use Pleroma.DataCase, async: false
|
2023-08-04 05:50:50 -06:00
|
|
|
@moduletag :mocked
|
2020-06-14 12:02:57 -06:00
|
|
|
|
|
|
|
alias Pleroma.Web.MediaProxy.Invalidation
|
|
|
|
|
|
|
|
import ExUnit.CaptureLog
|
|
|
|
import Mock
|
|
|
|
import Tesla.Mock
|
|
|
|
|
|
|
|
setup do: clear_config([:media_proxy])
|
|
|
|
|
|
|
|
describe "Invalidation.Http" do
|
|
|
|
test "perform request to clear cache" do
|
2021-01-26 10:58:43 -07:00
|
|
|
clear_config([:media_proxy, :enabled], false)
|
|
|
|
clear_config([:media_proxy, :invalidation, :enabled], true)
|
|
|
|
clear_config([:media_proxy, :invalidation, :provider], Invalidation.Http)
|
2020-06-14 12:02:57 -06:00
|
|
|
|
2021-01-26 10:58:43 -07:00
|
|
|
clear_config([Invalidation.Http], method: :purge, headers: [{"x-refresh", 1}])
|
2020-06-14 12:02:57 -06:00
|
|
|
image_url = "http://example.com/media/example.jpg"
|
2020-06-17 12:13:55 -06:00
|
|
|
Pleroma.Web.MediaProxy.put_in_banned_urls(image_url)
|
2020-06-14 12:02:57 -06:00
|
|
|
|
|
|
|
mock(fn
|
|
|
|
%{
|
|
|
|
method: :purge,
|
|
|
|
url: "http://example.com/media/example.jpg",
|
|
|
|
headers: [{"x-refresh", 1}]
|
|
|
|
} ->
|
|
|
|
%Tesla.Env{status: 200}
|
|
|
|
end)
|
|
|
|
|
|
|
|
assert capture_log(fn ->
|
2020-06-17 12:13:55 -06:00
|
|
|
assert Pleroma.Web.MediaProxy.in_banned_urls(image_url)
|
2020-06-14 12:02:57 -06:00
|
|
|
assert Invalidation.purge([image_url]) == {:ok, [image_url]}
|
2020-06-17 12:13:55 -06:00
|
|
|
assert Pleroma.Web.MediaProxy.in_banned_urls(image_url)
|
2020-06-14 12:02:57 -06:00
|
|
|
end) =~ "Running cache purge: [\"#{image_url}\"]"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "Invalidation.Script" do
|
|
|
|
test "run script to clear cache" do
|
2021-01-26 10:58:43 -07:00
|
|
|
clear_config([:media_proxy, :enabled], false)
|
|
|
|
clear_config([:media_proxy, :invalidation, :enabled], true)
|
|
|
|
clear_config([:media_proxy, :invalidation, :provider], Invalidation.Script)
|
|
|
|
clear_config([Invalidation.Script], script_path: "purge-nginx")
|
2020-06-14 12:02:57 -06:00
|
|
|
|
|
|
|
image_url = "http://example.com/media/example.jpg"
|
2020-06-17 12:13:55 -06:00
|
|
|
Pleroma.Web.MediaProxy.put_in_banned_urls(image_url)
|
2020-06-14 12:02:57 -06:00
|
|
|
|
|
|
|
with_mocks [{System, [], [cmd: fn _, _ -> {"ok", 0} end]}] do
|
|
|
|
assert capture_log(fn ->
|
2020-06-17 12:13:55 -06:00
|
|
|
assert Pleroma.Web.MediaProxy.in_banned_urls(image_url)
|
2020-06-14 12:02:57 -06:00
|
|
|
assert Invalidation.purge([image_url]) == {:ok, [image_url]}
|
2020-06-17 12:13:55 -06:00
|
|
|
assert Pleroma.Web.MediaProxy.in_banned_urls(image_url)
|
2020-06-14 12:02:57 -06:00
|
|
|
end) =~ "Running cache purge: [\"#{image_url}\"]"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|