X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=test%2Fupload_test.exs;h=f2cad4cf0cccaee9489ce88fdd5323610dc7198a;hb=c859cd1d61d81db4999c594ef61164d752d76145;hp=7117373bd718c28de40040653ea3725a3f851a3a;hpb=1d537bc74f5efaad5d18efdee97b8defa9b38199;p=akkoma diff --git a/test/upload_test.exs b/test/upload_test.exs index 7117373bd..f2cad4cf0 100644 --- a/test/upload_test.exs +++ b/test/upload_test.exs @@ -3,24 +3,27 @@ defmodule Pleroma.UploadTest do use Pleroma.DataCase describe "Storing a file with the Local uploader" do - setup do - uploader = Pleroma.Config.get([Pleroma.Upload, :uploader]) - filters = Pleroma.Config.get([Pleroma.Upload, :filters]) + setup [:ensure_local_uploader] - unless uploader == Pleroma.Uploaders.Local || filters != [] do - Pleroma.Config.put([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local) - Pleroma.Config.put([Pleroma.Upload, :filters], []) + test "returns a media url" do + File.cp!("test/fixtures/image.jpg", "test/fixtures/image_tmp.jpg") + + file = %Plug.Upload{ + content_type: "image/jpg", + path: Path.absname("test/fixtures/image_tmp.jpg"), + filename: "image.jpg" + } + + {:ok, data} = Upload.store(file) - on_exit(fn -> - Pleroma.Config.put([Pleroma.Upload, :uploader], uploader) - Pleroma.Config.put([Pleroma.Upload, :filters], filters) - end) - end + assert %{"url" => [%{"href" => url}]} = data - :ok + assert String.starts_with?(url, Pleroma.Web.base_url() <> "/media/") end - test "returns a media url" do + test "returns a media url with configured base_url" do + base_url = "https://cache.pleroma.social" + File.cp!("test/fixtures/image.jpg", "test/fixtures/image_tmp.jpg") file = %Plug.Upload{ @@ -29,11 +32,11 @@ defmodule Pleroma.UploadTest do filename: "image.jpg" } - {:ok, data} = Upload.store(file) + {:ok, data} = Upload.store(file, base_url: base_url) assert %{"url" => [%{"href" => url}]} = data - assert String.starts_with?(url, Pleroma.Web.base_url() <> "/media/") + assert String.starts_with?(url, base_url <> "/media/") end test "copies the file to the configured folder with deduping" do @@ -116,5 +119,19 @@ defmodule Pleroma.UploadTest do {:ok, data} = Upload.store(file) assert data["name"] == "test.txt" end + + test "copies the file to the configured folder with anonymizing filename" do + File.cp!("test/fixtures/image.jpg", "test/fixtures/image_tmp.jpg") + + file = %Plug.Upload{ + content_type: "image/jpg", + path: Path.absname("test/fixtures/image_tmp.jpg"), + filename: "an [image.jpg" + } + + {:ok, data} = Upload.store(file, filters: [Pleroma.Upload.Filter.AnonymizeFilename]) + + refute data["name"] == "an [image.jpg" + end end end