Merge branch 'develop' into fix/domain-block-subplan-cost

This commit is contained in:
lain 2026-09-02 10:19:27 +00:00
commit 70d743bff9
20 changed files with 244 additions and 351 deletions

View file

@ -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

View file

@ -65,6 +65,15 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do
}
test_notifications_rendering([notification], recipient, [expected])
grouped =
NotificationView.render("grouped_index.json", %{
notifications: [notification],
for: recipient
})
assert [group] = grouped.notification_groups
assert group.chat_message == expected.chat_message
end
test "Mention notification" do
@ -182,6 +191,16 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do
}
test_notifications_rendering([notification], follower, [expected])
grouped =
NotificationView.render("grouped_index.json", %{
notifications: [notification],
for: follower
})
assert [group] = grouped.notification_groups
assert group.target_id == new_user.id
assert Enum.any?(grouped.accounts, &(&1.id == new_user.id))
end
test "EmojiReact notification" do
@ -210,6 +229,13 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do
}
test_notifications_rendering([notification], user, [expected])
grouped =
NotificationView.render("grouped_index.json", %{notifications: [notification], for: user})
assert [group] = grouped.notification_groups
assert group.emoji == expected.emoji
assert group.emoji_url == expected.emoji_url
end
test "EmojiReact custom emoji notification" do
@ -295,6 +321,15 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do
}
test_notifications_rendering([notification], moderator_user, [expected])
grouped =
NotificationView.render("grouped_index.json", %{
notifications: [notification],
for: moderator_user
})
assert [group] = grouped.notification_groups
assert group.report == expected.report
end
test "Edit notification" do

View file

@ -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

View file

@ -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