Merge branch 'develop' into match-file-name
authorSachin Joshi <satchin.joshi@gmail.com>
Mon, 15 Jul 2019 15:45:56 +0000 (21:30 +0545)
committerSachin Joshi <satchin.joshi@gmail.com>
Mon, 15 Jul 2019 15:45:56 +0000 (21:30 +0545)
# Conflicts:
# lib/pleroma/web/media_proxy/media_proxy_controller.ex

1  2 
lib/pleroma/web/media_proxy/media_proxy_controller.ex
test/web/media_proxy/media_proxy_test.exs

index a711b54e944633c4032a10c6bd5dc6d1abf777e3,1e9520d462c36fc29da22698e87fc533db0f237b..8403850ff1ca9b7c2f9ee9c56ffe93bab3f666a5
@@@ -27,18 -27,15 +27,20 @@@ defmodule Pleroma.Web.MediaProxy.MediaP
      end
    end
  
-   def filename_matches(has_filename, path, url) do
-     filename = url |> MediaProxy.filename()
+   def filename_matches(%{"filename" => _} = _, path, url) do
+     filename = MediaProxy.filename(url)
  
-     if has_filename && filename && does_not_match(path, filename) do
 -    if filename && Path.basename(path) != filename do
++    if filename && does_not_match(path, filename) do
        {:wrong_filename, filename}
      else
        :ok
      end
    end
  
+   def filename_matches(_, _, _), do: :ok
++
 +  defp does_not_match(path, filename) do
 +    basename = Path.basename(path)
 +    basename != filename and URI.decode(basename) != filename and URI.encode(basename) != filename
 +  end
  end
index 176b099148889dd707171b73135632e0c3cd797e,cb4807e0be841e54971e5dbd080e7a3b15903f33..edbbf9b667aa5dbfdf2c8a1a592e7f25a7db5cfd
@@@ -106,19 -106,14 +106,25 @@@ defmodule Pleroma.Web.MediaProxyTest d
                 "/my%2Flong%2Furl%2F2019%2F07%2FS.jpg",
                 "http://pleroma.social/my%2Flong%2Furl%2F2019%2F07%2FS.jpg"
               ) == :ok
+       assert MediaProxyController.filename_matches(
+                %{"filename" => "/my%2Flong%2Furl%2F2019%2F07%2FS.jp"},
+                "/my%2Flong%2Furl%2F2019%2F07%2FS.jp",
+                "http://pleroma.social/my%2Flong%2Furl%2F2019%2F07%2FS.jpg"
+              ) == {:wrong_filename, "my%2Flong%2Furl%2F2019%2F07%2FS.jpg"}
      end
  
 +    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"
 +
 +      assert MediaProxyController.filename_matches(
 +               true,
 +               request_path,
 +               "https://mydomain.com/uploads/2019/07/ANALYSE-DAI-_-LE-STABLECOIN-100-DÉCENTRALISÉ-BQ.jpg"
 +             ) == :ok
 +    end
 +
      test "uses the configured base_url" do
        base_url = Pleroma.Config.get([:media_proxy, :base_url])