logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

steal_emoji_policy_test.exs (1952B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Web.ActivityPub.MRF.StealEmojiPolicyTest do
  5. use Pleroma.DataCase
  6. alias Pleroma.Config
  7. alias Pleroma.Web.ActivityPub.MRF.StealEmojiPolicy
  8. setup_all do
  9. Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
  10. :ok
  11. end
  12. setup do
  13. emoji_path = Path.join(Config.get([:instance, :static_dir]), "emoji/stolen")
  14. File.rm_rf!(emoji_path)
  15. File.mkdir!(emoji_path)
  16. Pleroma.Emoji.reload()
  17. on_exit(fn ->
  18. File.rm_rf!(emoji_path)
  19. end)
  20. :ok
  21. end
  22. test "does nothing by default" do
  23. installed_emoji = Pleroma.Emoji.get_all() |> Enum.map(fn {k, _} -> k end)
  24. refute "firedfox" in installed_emoji
  25. message = %{
  26. "type" => "Create",
  27. "object" => %{
  28. "emoji" => [{"firedfox", "https://example.org/emoji/firedfox.png"}],
  29. "actor" => "https://example.org/users/admin"
  30. }
  31. }
  32. assert {:ok, message} == StealEmojiPolicy.filter(message)
  33. installed_emoji = Pleroma.Emoji.get_all() |> Enum.map(fn {k, _} -> k end)
  34. refute "firedfox" in installed_emoji
  35. end
  36. test "Steals emoji on unknown shortcode from allowed remote host" do
  37. installed_emoji = Pleroma.Emoji.get_all() |> Enum.map(fn {k, _} -> k end)
  38. refute "firedfox" in installed_emoji
  39. message = %{
  40. "type" => "Create",
  41. "object" => %{
  42. "emoji" => [{"firedfox", "https://example.org/emoji/firedfox.png"}],
  43. "actor" => "https://example.org/users/admin"
  44. }
  45. }
  46. clear_config([:mrf_steal_emoji, :hosts], ["example.org"])
  47. clear_config([:mrf_steal_emoji, :size_limit], 284_468)
  48. assert {:ok, message} == StealEmojiPolicy.filter(message)
  49. installed_emoji = Pleroma.Emoji.get_all() |> Enum.map(fn {k, _} -> k end)
  50. assert "firedfox" in installed_emoji
  51. end
  52. end