Revert "Merge pull request 'MediaProxy: detect images when there's no file extension' (#7933) from mediaproxy-content-type into develop"
A partial revert, keeping the updated @inline_content_types list and cosmetic changes. This reverts commit4fe567064a, reversing changes made to9b8aa2e2ee.
This commit is contained in:
parent
ad7f68b924
commit
f672ab337c
7 changed files with 23 additions and 294 deletions
|
|
@ -579,56 +579,6 @@ defmodule Pleroma.ReverseProxyTest do
|
|||
assert Conn.get_resp_header(conn, "content-type") == ["application/octet-stream"]
|
||||
end
|
||||
|
||||
test "sniffs and preserves an image body with a generic content type", %{conn: conn} do
|
||||
body = File.read!("test/fixtures/image.jpg")
|
||||
|
||||
ClientMock
|
||||
|> expect(:request, fn :get, "/extensionless", headers, _, _ ->
|
||||
assert {"accept-encoding", "identity"} in headers
|
||||
{:ok, 200, [{"content-type", "application/octet-stream"}], %{body: body}}
|
||||
end)
|
||||
|> expect(:stream_body, fn %{body: ^body} = client ->
|
||||
{:ok, body, Map.delete(client, :body)}
|
||||
end)
|
||||
|> expect(:stream_body, fn %{} -> :done end)
|
||||
|
||||
conn =
|
||||
ReverseProxy.call(conn, "/extensionless",
|
||||
sniff_content_type: true,
|
||||
max_read_duration: :infinity,
|
||||
req_headers: [{"accept-encoding", "gzip"}]
|
||||
)
|
||||
|
||||
assert conn.resp_body == body
|
||||
assert Conn.get_resp_header(conn, "content-type") == ["image/jpeg"]
|
||||
|
||||
assert Conn.get_resp_header(conn, "content-disposition") == [
|
||||
"inline; filename=\"inline.jpg\""
|
||||
]
|
||||
end
|
||||
|
||||
test "redirects a content sniffing failure before committing the response", %{conn: conn} do
|
||||
url = "https://example.com/extensionless"
|
||||
|
||||
ClientMock
|
||||
|> expect(:request, fn :get, ^url, _, _, _ ->
|
||||
{:ok, 200, [{"content-type", "application/octet-stream"}], %{url: url}}
|
||||
end)
|
||||
|> expect(:stream_body, fn _ -> {:error, :closed} end)
|
||||
|> expect(:close, fn _ -> :ok end)
|
||||
|
||||
conn =
|
||||
ReverseProxy.call(conn, url,
|
||||
sniff_content_type: true,
|
||||
redirect_on_failure: true
|
||||
)
|
||||
|
||||
assert conn.status == 302
|
||||
assert Conn.get_resp_header(conn, "location") == [url]
|
||||
assert conn.state == :sent
|
||||
assert Cachex.get(:failed_proxy_url_cache, url) == {:ok, true}
|
||||
end
|
||||
|
||||
test "preserves a generic content type for a non-image body", %{conn: conn} do
|
||||
body = "not an image"
|
||||
|
||||
|
|
@ -823,24 +773,6 @@ defmodule Pleroma.ReverseProxyTest do
|
|||
conn = ReverseProxy.call(conn, "/disposition")
|
||||
|
||||
assert {"content-type", "image/gif"} in conn.resp_headers
|
||||
assert {"content-disposition", "inline; filename=\"inline.gif\""} in conn.resp_headers
|
||||
end
|
||||
|
||||
test "forces inline for inline content types overriding upstream attachment", %{
|
||||
conn: conn
|
||||
} do
|
||||
disposition_headers_mock([
|
||||
{"content-type", "image/png"},
|
||||
{"content-disposition", "attachment; filename=\"filename.png\""},
|
||||
{"content-disposition", "attachment; filename=\"duplicate.png\""},
|
||||
{"content-length", "0"}
|
||||
])
|
||||
|
||||
conn = ReverseProxy.call(conn, "/disposition")
|
||||
|
||||
[disposition] = Conn.get_resp_header(conn, "content-disposition")
|
||||
assert String.starts_with?(disposition, "inline")
|
||||
refute String.starts_with?(disposition, "attachment")
|
||||
end
|
||||
|
||||
test "with content-disposition header", %{conn: conn} do
|
||||
|
|
@ -853,50 +785,6 @@ defmodule Pleroma.ReverseProxyTest do
|
|||
|
||||
assert {"content-disposition", "attachment; filename=\"filename.jpg\""} in conn.resp_headers
|
||||
end
|
||||
|
||||
test "with inline_content_types: true leaves upstream headers untouched", %{
|
||||
conn: conn
|
||||
} do
|
||||
# opt == true: the proxy must not synthesise or rewrite content-disposition.
|
||||
disposition_headers_mock([
|
||||
{"content-type", "image/png"},
|
||||
{"content-disposition", "attachment; filename=\"upstream.png\""},
|
||||
{"content-length", "0"}
|
||||
])
|
||||
|
||||
conn = ReverseProxy.call(conn, "/disposition", inline_content_types: true)
|
||||
|
||||
assert {"content-disposition", "attachment; filename=\"upstream.png\""} in conn.resp_headers
|
||||
end
|
||||
|
||||
test "forces bare inline for a whitelisted type with no MIME extension", %{
|
||||
conn: conn
|
||||
} do
|
||||
# image/x-foo-bar has no entry in MIME's database, so inline_filename/1
|
||||
# returns nil and the disposition should be the bare token "inline".
|
||||
disposition_headers_mock([
|
||||
{"content-type", "image/x-foo-bar"},
|
||||
{"content-length", "0"}
|
||||
])
|
||||
|
||||
conn = ReverseProxy.call(conn, "/disposition", inline_content_types: ["image/x-foo-bar"])
|
||||
|
||||
[disposition] = Conn.get_resp_header(conn, "content-disposition")
|
||||
assert disposition == "inline"
|
||||
end
|
||||
|
||||
test "serves modern browser image types inline", %{conn: conn} do
|
||||
disposition_headers_mock([
|
||||
{"content-type", "image/webp"},
|
||||
{"content-length", "0"}
|
||||
])
|
||||
|
||||
conn = ReverseProxy.call(conn, "/disposition")
|
||||
|
||||
assert Conn.get_resp_header(conn, "content-disposition") == [
|
||||
"inline; filename=\"inline.webp\""
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
describe "content-type sanitisation" do
|
||||
|
|
|
|||
|
|
@ -668,23 +668,6 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
assert expected == StatusView.render("attachment.json", %{attachment: object})
|
||||
assert_schema(expected, "Attachment", api_spec)
|
||||
end
|
||||
|
||||
test "uses the ActivityStreams image type when the MIME type is generic" do
|
||||
object = %{
|
||||
"type" => "Image",
|
||||
"url" => [
|
||||
%{
|
||||
"mediaType" => "application/octet-stream",
|
||||
"href" => "https://example.com/extensionless"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
attachment = StatusView.render("attachment.json", %{attachment: object})
|
||||
|
||||
assert attachment.type == "image"
|
||||
assert attachment.pleroma.mime_type == "application/octet-stream"
|
||||
end
|
||||
end
|
||||
|
||||
test "put the url advertised in the Activity in to the url attribute" do
|
||||
|
|
|
|||
|
|
@ -71,10 +71,7 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do
|
|||
|
||||
test "it performs ReverseProxy.call with valid signature", %{conn: conn, url: url} do
|
||||
with_mock Pleroma.ReverseProxy,
|
||||
call: fn _conn, _url, opts ->
|
||||
assert opts[:sniff_content_type]
|
||||
%Conn{status: :success}
|
||||
end do
|
||||
call: fn _conn, _url, _opts -> %Conn{status: :success} end do
|
||||
assert %Conn{status: :success} = get(conn, url)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue