From 65e7307d6853064d9c09c80f1aca0c487001f9f4 Mon Sep 17 00:00:00 2001 From: href Date: Fri, 30 Nov 2018 17:44:12 +0100 Subject: Upload: bring back base_url --- test/media_proxy_test.exs | 17 +++++++++++++++++ test/upload_test.exs | 18 ++++++++++++++++++ 2 files changed, 35 insertions(+) (limited to 'test') diff --git a/test/media_proxy_test.exs b/test/media_proxy_test.exs index c69ed7ea4..d71f9f13a 100644 --- a/test/media_proxy_test.exs +++ b/test/media_proxy_test.exs @@ -82,6 +82,23 @@ defmodule Pleroma.MediaProxyTest do [_, "proxy", sig, base64 | _] = URI.parse(encoded).path |> String.split("/") assert decode_url(sig, base64) == {:error, :invalid_signature} end + + test "uses the configured base_url" do + base_url = Pleroma.Config.get([:media_proxy, :base_url]) + + if base_url do + on_exit(fn -> + Pleroma.Config.put([:media_proxy, :base_url], base_url) + end) + end + + Pleroma.Config.put([:media_proxy, :base_url], "https://cache.pleroma.social") + + url = "https://pleroma.soykaf.com/static/logo.png" + encoded = url(url) + + assert String.starts_with?(encoded, Pleroma.Config.get([:media_proxy, :base_url])) + end end describe "when disabled" do diff --git a/test/upload_test.exs b/test/upload_test.exs index 7117373bd..cfd86ddd0 100644 --- a/test/upload_test.exs +++ b/test/upload_test.exs @@ -36,6 +36,24 @@ defmodule Pleroma.UploadTest do assert String.starts_with?(url, Pleroma.Web.base_url() <> "/media/") end + 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{ + content_type: "image/jpg", + path: Path.absname("test/fixtures/image_tmp.jpg"), + filename: "image.jpg" + } + + {:ok, data} = Upload.store(file, base_url: base_url) + + assert %{"url" => [%{"href" => url}]} = data + + assert String.starts_with?(url, base_url <> "/media/") + end + test "copies the file to the configured folder with deduping" do File.cp!("test/fixtures/image.jpg", "test/fixtures/image_tmp.jpg") -- cgit v1.2.3