mrf/steal_emoji: fix size limit check
Headers are strings, but this expected to already get an int
thus always failing the comparison if the header was set.
Fixes mistake in d6d838cbe8
This commit is contained in:
parent
68fe0a9633
commit
be5440c5e8
2 changed files with 12 additions and 3 deletions
|
@ -101,10 +101,19 @@ defmodule Pleroma.Web.ActivityPub.MRF.StealEmojiPolicy do
|
|||
end
|
||||
end
|
||||
|
||||
defp get_int_header(headers, header_name, default \\ nil) do
|
||||
with rawval when rawval != :undefined <- :proplists.get_value(header_name, headers),
|
||||
{int, ""} <- Integer.parse(rawval) do
|
||||
int
|
||||
else
|
||||
_ -> default
|
||||
end
|
||||
end
|
||||
|
||||
defp is_remote_size_within_limit?(url) do
|
||||
with {:ok, %{status: status, headers: headers} = _response} when status in 200..299 <-
|
||||
Pleroma.HTTP.request(:head, url, nil, [], []) do
|
||||
content_length = :proplists.get_value("content-length", headers, nil)
|
||||
content_length = get_int_header(headers, "content-length")
|
||||
size_limit = Config.get([:mrf_steal_emoji, :size_limit], @size_limit)
|
||||
|
||||
accept_unknown =
|
||||
|
|
|
@ -202,7 +202,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.StealEmojiPolicyTest do
|
|||
|
||||
test "reject too large content-size before download", %{message: message} do
|
||||
clear_config([:mrf_steal_emoji, :download_unknown_size], false)
|
||||
mock_tesla("https://example.org/emoji/firedfox.png", 200, [{"content-length", 2 ** 30}])
|
||||
mock_tesla("https://example.org/emoji/firedfox.png", 200, [{"content-length", "#{2 ** 30}"}])
|
||||
|
||||
refute "firedfox" in installed()
|
||||
|
||||
|
@ -216,7 +216,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.StealEmojiPolicyTest do
|
|||
|
||||
test "accepts content-size below limit", %{message: message} do
|
||||
clear_config([:mrf_steal_emoji, :download_unknown_size], false)
|
||||
mock_tesla("https://example.org/emoji/firedfox.png", 200, [{"content-length", 2}])
|
||||
mock_tesla("https://example.org/emoji/firedfox.png", 200, [{"content-length", "2"}])
|
||||
|
||||
refute "firedfox" in installed()
|
||||
|
||||
|
|
Loading…
Reference in a new issue