MRF.StealEmojiPolicy: Properly add fallback extension to filenames missing one
This commit is contained in:
parent
67a5542a73
commit
4ca65c6182
1
changelog.d/mrf-steal-emoji-extname.fix
Normal file
1
changelog.d/mrf-steal-emoji-extname.fix
Normal file
@ -0,0 +1 @@
|
|||||||
|
MRF.StealEmojiPolicy: Properly add fallback extension to filenames missing one
|
@ -34,7 +34,9 @@ defmodule Pleroma.Web.ActivityPub.MRF.StealEmojiPolicy do
|
|||||||
|> Path.basename()
|
|> Path.basename()
|
||||||
|> Path.extname()
|
|> Path.extname()
|
||||||
|
|
||||||
file_path = Path.join(emoji_dir_path, shortcode <> (extension || ".png"))
|
extension = if extension == "", do: ".png", else: extension
|
||||||
|
|
||||||
|
file_path = Path.join(emoji_dir_path, shortcode <> extension)
|
||||||
|
|
||||||
case File.write(file_path, response.body) do
|
case File.write(file_path, response.body) do
|
||||||
:ok ->
|
:ok ->
|
||||||
|
@ -60,6 +60,33 @@ defmodule Pleroma.Web.ActivityPub.MRF.StealEmojiPolicyTest do
|
|||||||
|> File.exists?()
|
|> File.exists?()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "works with unknown extension", %{path: path} do
|
||||||
|
message = %{
|
||||||
|
"type" => "Create",
|
||||||
|
"object" => %{
|
||||||
|
"emoji" => [{"firedfox", "https://example.org/emoji/firedfox"}],
|
||||||
|
"actor" => "https://example.org/users/admin"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fullpath = Path.join(path, "firedfox.png")
|
||||||
|
|
||||||
|
Tesla.Mock.mock(fn %{method: :get, url: "https://example.org/emoji/firedfox"} ->
|
||||||
|
%Tesla.Env{status: 200, body: File.read!("test/fixtures/image.jpg")}
|
||||||
|
end)
|
||||||
|
|
||||||
|
clear_config(:mrf_steal_emoji, hosts: ["example.org"], size_limit: 284_468)
|
||||||
|
|
||||||
|
refute "firedfox" in installed()
|
||||||
|
refute File.exists?(path)
|
||||||
|
|
||||||
|
assert {:ok, _message} = StealEmojiPolicy.filter(message)
|
||||||
|
|
||||||
|
assert "firedfox" in installed()
|
||||||
|
assert File.exists?(path)
|
||||||
|
assert File.exists?(fullpath)
|
||||||
|
end
|
||||||
|
|
||||||
test "reject regex shortcode", %{message: message} do
|
test "reject regex shortcode", %{message: message} do
|
||||||
refute "firedfox" in installed()
|
refute "firedfox" in installed()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user