mediaproxy: proxy network-path references
Discovered-by: snow Fixes: https://akkoma.dev/AkkomaGang/akkoma/issues/900 (cherry picked from commit bbf974adc82d09a2099fb1234729131929307911)
This commit is contained in:
parent
c2bdfb6a34
commit
5cd6894a66
4 changed files with 63 additions and 1 deletions
|
|
@ -559,6 +559,46 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
assert mention.url == recipient_ap_id
|
||||
end
|
||||
|
||||
test "inlined images are media proxied" do
|
||||
ConfigMock |> stub_with(Pleroma.Test.StaticConfig)
|
||||
clear_config([:media_proxy, :enabled], true)
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, activity} =
|
||||
CommonAPI.post(user, %{
|
||||
content_type: "text/html",
|
||||
status: "hii <img src=\"https://example.org/a.png\" />"
|
||||
})
|
||||
|
||||
activity = Repo.get(Activity, activity.id)
|
||||
status = StatusView.render("show.json", activity: activity)
|
||||
|
||||
assert_schema(status, "Status", Pleroma.Web.ApiSpec.spec())
|
||||
|
||||
assert status[:content] =~
|
||||
~r/^hii <img src="https?:\/\/[^\/]+\/proxy\/[^\/]+\/aHR0cHM6Ly9leGFtcGxlLm9yZy9hLnBuZw\/a.png"/
|
||||
end
|
||||
|
||||
test "inlined images using network-path ref are media proxied" do
|
||||
ConfigMock |> stub_with(Pleroma.Test.StaticConfig)
|
||||
clear_config([:media_proxy, :enabled], true)
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, activity} =
|
||||
CommonAPI.post(user, %{
|
||||
content_type: "text/html",
|
||||
status: "hii <img src=\"//example.org/a.png\" />"
|
||||
})
|
||||
|
||||
activity = Repo.get(Activity, activity.id)
|
||||
status = StatusView.render("show.json", activity: activity)
|
||||
|
||||
assert_schema(status, "Status", Pleroma.Web.ApiSpec.spec())
|
||||
|
||||
assert status[:content] =~
|
||||
~r/^hii <img src="https?:\/\/[^\/]+\/proxy\/[^\/]+\/aHR0cHM6Ly9leGFtcGxlLm9yZy9hLnBuZw\/a.png"/
|
||||
end
|
||||
|
||||
test "create mentions from the 'tag' field" do
|
||||
recipient = insert(:user)
|
||||
cc = insert_pair(:user) |> Enum.map(& &1.ap_id)
|
||||
|
|
|
|||
|
|
@ -59,6 +59,20 @@ defmodule Pleroma.Web.MediaProxyTest do
|
|||
assert decode_result(encoded) == url
|
||||
end
|
||||
|
||||
test "encodes and decodes a network-path reference URL as HTTPS" do
|
||||
url = "//example.org/static/logo.png"
|
||||
encoded = MediaProxy.url(url)
|
||||
|
||||
assert String.starts_with?(
|
||||
encoded,
|
||||
Config.get([:media_proxy, :base_url], Pleroma.Web.Endpoint.url())
|
||||
)
|
||||
|
||||
assert String.ends_with?(encoded, "/logo.png")
|
||||
|
||||
assert decode_result(encoded) == "https:" <> url
|
||||
end
|
||||
|
||||
test "encodes and decodes URL without a path" do
|
||||
url = "https://pleroma.soykaf.com"
|
||||
encoded = MediaProxy.url(url)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue