X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;ds=sidebyside;f=test%2Fweb%2Fmedia_proxy%2Fmedia_proxy_test.exs;h=69d2a71a68d2e3a727a9b0e90c58dadb108c75be;hb=396bc69aeef951f163c0c20474ce4653df1dd667;hp=cb4807e0be841e54971e5dbd080e7a3b15903f33;hpb=fa17879c204980c6fb0025b2e51a978669c441da;p=akkoma
diff --git a/test/web/media_proxy/media_proxy_test.exs b/test/web/media_proxy/media_proxy_test.exs
index cb4807e0b..69d2a71a6 100644
--- a/test/web/media_proxy/media_proxy_test.exs
+++ b/test/web/media_proxy/media_proxy_test.exs
@@ -1,17 +1,15 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2020 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MediaProxyTest do
use ExUnit.Case
+ use Pleroma.Tests.Helpers
import Pleroma.Web.MediaProxy
alias Pleroma.Web.MediaProxy.MediaProxyController
- setup do
- enabled = Pleroma.Config.get([:media_proxy, :enabled])
- on_exit(fn -> Pleroma.Config.put([:media_proxy, :enabled], enabled) end)
- :ok
- end
+ setup do: clear_config([:media_proxy, :enabled])
+ setup do: clear_config(Pleroma.Upload)
describe "when enabled" do
setup do
@@ -114,16 +112,19 @@ defmodule Pleroma.Web.MediaProxyTest do
) == {:wrong_filename, "my%2Flong%2Furl%2F2019%2F07%2FS.jpg"}
end
- test "uses the configured base_url" do
- base_url = Pleroma.Config.get([:media_proxy, :base_url])
+ test "encoded url are tried to match for proxy as `conn.request_path` encodes the url" do
+ # conn.request_path will return encoded url
+ request_path = "/ANALYSE-DAI-_-LE-STABLECOIN-100-D%C3%89CENTRALIS%C3%89-BQ.jpg"
- if base_url do
- on_exit(fn ->
- Pleroma.Config.put([:media_proxy, :base_url], base_url)
- end)
- end
+ assert MediaProxyController.filename_matches(
+ true,
+ request_path,
+ "https://mydomain.com/uploads/2019/07/ANALYSE-DAI-_-LE-STABLECOIN-100-DÃCENTRALISÃ-BQ.jpg"
+ ) == :ok
+ end
- Pleroma.Config.put([:media_proxy, :base_url], "https://cache.pleroma.social")
+ test "uses the configured base_url" do
+ clear_config([:media_proxy, :base_url], "https://cache.pleroma.social")
url = "https://pleroma.soykaf.com/static/logo.png"
encoded = url(url)
@@ -160,21 +161,6 @@ defmodule Pleroma.Web.MediaProxyTest do
encoded = url(url)
assert decode_result(encoded) == url
end
-
- test "does not change whitelisted urls" do
- upload_config = Pleroma.Config.get([Pleroma.Upload])
- media_url = "https://media.pleroma.social"
- Pleroma.Config.put([Pleroma.Upload, :base_url], media_url)
- Pleroma.Config.put([:media_proxy, :whitelist], ["media.pleroma.social"])
- Pleroma.Config.put([:media_proxy, :base_url], "https://cache.pleroma.social")
-
- url = "#{media_url}/static/logo.png"
- encoded = url(url)
-
- assert String.starts_with?(encoded, media_url)
-
- Pleroma.Config.put([Pleroma.Upload], upload_config)
- end
end
describe "when disabled" do
@@ -204,12 +190,40 @@ defmodule Pleroma.Web.MediaProxyTest do
decoded
end
- test "mediaproxy whitelist" do
- Pleroma.Config.put([:media_proxy, :enabled], true)
- Pleroma.Config.put([:media_proxy, :whitelist], ["google.com", "feld.me"])
- url = "https://feld.me/foo.png"
+ describe "whitelist" do
+ setup do
+ Pleroma.Config.put([:media_proxy, :enabled], true)
+ :ok
+ end
+
+ test "mediaproxy whitelist" do
+ Pleroma.Config.put([:media_proxy, :whitelist], ["google.com", "feld.me"])
+ url = "https://feld.me/foo.png"
+
+ unencoded = url(url)
+ assert unencoded == url
+ end
+
+ test "does not change whitelisted urls" do
+ clear_config([:media_proxy, :whitelist], ["mycdn.akamai.com"])
+ clear_config([:media_proxy, :base_url], "https://cache.pleroma.social")
+
+ media_url = "https://mycdn.akamai.com"
+
+ url = "#{media_url}/static/logo.png"
+ encoded = url(url)
+
+ assert String.starts_with?(encoded, media_url)
+ end
+
+ test "ensure Pleroma.Upload base_url is always whitelisted" do
+ media_url = "https://media.pleroma.social"
+ Pleroma.Config.put([Pleroma.Upload, :base_url], media_url)
- unencoded = url(url)
- assert unencoded == url
+ url = "#{media_url}/static/logo.png"
+ encoded = url(url)
+
+ assert String.starts_with?(encoded, media_url)
+ end
end
end