From d18a2e4e360bd6e630101a7dd2f4ae0902ac43a1 Mon Sep 17 00:00:00 2001 From: Roman Chvanikov Date: Tue, 28 Jan 2020 17:22:24 +0300 Subject: [PATCH] Add test for custom base_url when deleting an attachment --- .../workers/attachments_cleanup_worker.ex | 3 -- test/object_test.exs | 33 +++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/lib/pleroma/workers/attachments_cleanup_worker.ex b/lib/pleroma/workers/attachments_cleanup_worker.ex index 4f7a1a193..2cbc6b64d 100644 --- a/lib/pleroma/workers/attachments_cleanup_worker.ex +++ b/lib/pleroma/workers/attachments_cleanup_worker.ex @@ -8,8 +8,6 @@ defmodule Pleroma.Workers.AttachmentsCleanupWorker do alias Pleroma.Object alias Pleroma.Repo - require Logger - use Pleroma.Workers.WorkerHelper, queue: "attachments_cleanup" @impl Oban.Worker @@ -83,7 +81,6 @@ def perform( file_path = String.trim_leading(href, "#{base_url}/#{prefix}") - Logger.warn("Deleting file #{file_path} (orig: #{href}, base_url: #{base_url})") uploader.delete_file(file_path) end diff --git a/test/object_test.exs b/test/object_test.exs index 9b4e6f0bf..c6b2bc399 100644 --- a/test/object_test.exs +++ b/test/object_test.exs @@ -177,6 +177,39 @@ test "with objects that have legacy data.url attribute" do assert {:ok, []} == File.ls("#{uploads_dir}/#{path}") end + + test "With custom base_url" do + Pleroma.Config.put([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local) + Pleroma.Config.put([Pleroma.Upload, :base_url], "https://sub.domain.tld/dir/") + + file = %Plug.Upload{ + content_type: "image/jpg", + path: Path.absname("test/fixtures/image.jpg"), + filename: "an_image.jpg" + } + + user = insert(:user) + + {:ok, %Object{} = attachment} = + Pleroma.Web.ActivityPub.ActivityPub.upload(file, actor: user.ap_id) + + %{data: %{"attachment" => [%{"url" => [%{"href" => href}]}]}} = + note = insert(:note, %{user: user, data: %{"attachment" => [attachment.data]}}) + + uploads_dir = Pleroma.Config.get!([Pleroma.Uploaders.Local, :uploads]) + + path = href |> Path.dirname() |> Path.basename() + + assert {:ok, ["an_image.jpg"]} == File.ls("#{uploads_dir}/#{path}") + + Object.delete(note) + + ObanHelpers.perform(all_enqueued(worker: Pleroma.Workers.AttachmentsCleanupWorker)) + + assert Object.get_by_id(attachment.id) == nil + + assert {:ok, []} == File.ls("#{uploads_dir}/#{path}") + end end describe "normalizer" do