forked from AkkomaGang/akkoma
FloatingGhost
98cb255d12
OTP builds to 1.15 Changelog entry Ensure policies are fully loaded Fix :warn use main branch for linkify Fix warn in tests Migrations for phoenix 1.17 Revert "Migrations for phoenix 1.17" This reverts commit 6a3b2f15b74ea5e33150529385215b7a531f3999. Oban upgrade Add default empty whitelist mix format limit test to amd64 OTP 26 tests for 1.15 use OTP_VERSION tag baka just 1.15 Massive deps update Update locale, deps Mix format shell???? multiline??? ? max cases 1 use assert_recieve don't put_env in async tests don't async conn/fs tests mix format FIx some uploader issues Fix tests
62 lines
2.2 KiB
Elixir
62 lines
2.2 KiB
Elixir
# Pleroma: A lightweight social networking server
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
defmodule Pleroma.Web.MediaProxy.InvalidationTest do
|
|
use Pleroma.DataCase, async: false
|
|
|
|
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
|
|
clear_config([:media_proxy, :enabled], false)
|
|
clear_config([:media_proxy, :invalidation, :enabled], true)
|
|
clear_config([:media_proxy, :invalidation, :provider], Invalidation.Http)
|
|
|
|
clear_config([Invalidation.Http], method: :purge, headers: [{"x-refresh", 1}])
|
|
image_url = "http://example.com/media/example.jpg"
|
|
Pleroma.Web.MediaProxy.put_in_banned_urls(image_url)
|
|
|
|
mock(fn
|
|
%{
|
|
method: :purge,
|
|
url: "http://example.com/media/example.jpg",
|
|
headers: [{"x-refresh", 1}]
|
|
} ->
|
|
%Tesla.Env{status: 200}
|
|
end)
|
|
|
|
assert capture_log(fn ->
|
|
assert Pleroma.Web.MediaProxy.in_banned_urls(image_url)
|
|
assert Invalidation.purge([image_url]) == {:ok, [image_url]}
|
|
assert Pleroma.Web.MediaProxy.in_banned_urls(image_url)
|
|
end) =~ "Running cache purge: [\"#{image_url}\"]"
|
|
end
|
|
end
|
|
|
|
describe "Invalidation.Script" do
|
|
test "run script to clear cache" do
|
|
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")
|
|
|
|
image_url = "http://example.com/media/example.jpg"
|
|
Pleroma.Web.MediaProxy.put_in_banned_urls(image_url)
|
|
|
|
with_mocks [{System, [], [cmd: fn _, _ -> {"ok", 0} end]}] do
|
|
assert capture_log(fn ->
|
|
assert Pleroma.Web.MediaProxy.in_banned_urls(image_url)
|
|
assert Invalidation.purge([image_url]) == {:ok, [image_url]}
|
|
assert Pleroma.Web.MediaProxy.in_banned_urls(image_url)
|
|
end) =~ "Running cache purge: [\"#{image_url}\"]"
|
|
end
|
|
end
|
|
end
|
|
end
|