2020-04-14 12:59:04 -04:00
|
|
|
# Pleroma: A lightweight social networking server
|
|
|
|
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.ActivityPub.MRF.StealEmojiPolicyTest do
|
|
|
|
use Pleroma.DataCase
|
|
|
|
|
|
|
|
alias Pleroma.Config
|
|
|
|
alias Pleroma.Web.ActivityPub.MRF.StealEmojiPolicy
|
|
|
|
|
|
|
|
setup_all do
|
|
|
|
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
|
|
|
:ok
|
|
|
|
end
|
|
|
|
|
|
|
|
setup do
|
|
|
|
emoji_path = Path.join(Config.get([:instance, :static_dir]), "emoji/stolen")
|
|
|
|
File.rm_rf!(emoji_path)
|
|
|
|
File.mkdir!(emoji_path)
|
|
|
|
|
|
|
|
Pleroma.Emoji.reload()
|
2020-05-25 08:00:18 -04:00
|
|
|
|
|
|
|
on_exit(fn ->
|
|
|
|
File.rm_rf!(emoji_path)
|
|
|
|
end)
|
|
|
|
|
|
|
|
:ok
|
2020-04-14 12:59:04 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
test "does nothing by default" do
|
|
|
|
installed_emoji = Pleroma.Emoji.get_all() |> Enum.map(fn {k, _} -> k end)
|
|
|
|
refute "firedfox" in installed_emoji
|
|
|
|
|
|
|
|
message = %{
|
|
|
|
"type" => "Create",
|
|
|
|
"object" => %{
|
|
|
|
"emoji" => [{"firedfox", "https://example.org/emoji/firedfox.png"}],
|
|
|
|
"actor" => "https://example.org/users/admin"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert {:ok, message} == StealEmojiPolicy.filter(message)
|
|
|
|
|
|
|
|
installed_emoji = Pleroma.Emoji.get_all() |> Enum.map(fn {k, _} -> k end)
|
|
|
|
refute "firedfox" in installed_emoji
|
|
|
|
end
|
|
|
|
|
|
|
|
test "Steals emoji on unknown shortcode from allowed remote host" do
|
|
|
|
installed_emoji = Pleroma.Emoji.get_all() |> Enum.map(fn {k, _} -> k end)
|
|
|
|
refute "firedfox" in installed_emoji
|
|
|
|
|
|
|
|
message = %{
|
|
|
|
"type" => "Create",
|
|
|
|
"object" => %{
|
|
|
|
"emoji" => [{"firedfox", "https://example.org/emoji/firedfox.png"}],
|
|
|
|
"actor" => "https://example.org/users/admin"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-25 07:48:47 -04:00
|
|
|
clear_config([:mrf_steal_emoji, :hosts], ["example.org"])
|
|
|
|
clear_config([:mrf_steal_emoji, :size_limit], 284_468)
|
2020-04-14 12:59:04 -04:00
|
|
|
|
|
|
|
assert {:ok, message} == StealEmojiPolicy.filter(message)
|
|
|
|
|
|
|
|
installed_emoji = Pleroma.Emoji.get_all() |> Enum.map(fn {k, _} -> k end)
|
|
|
|
assert "firedfox" in installed_emoji
|
|
|
|
end
|
|
|
|
end
|