Merge branch 'libmagic' into 'develop'
[akkoma] / test / pleroma / web / activity_pub / mrf / steal_emoji_policy_test.exs
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
5 defmodule Pleroma.Web.ActivityPub.MRF.StealEmojiPolicyTest do
6 use Pleroma.DataCase
7
8 alias Pleroma.Config
9 alias Pleroma.Web.ActivityPub.MRF.StealEmojiPolicy
10
11 setup_all do
12 Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
13 :ok
14 end
15
16 setup do
17 emoji_path = Path.join(Config.get([:instance, :static_dir]), "emoji/stolen")
18 File.rm_rf!(emoji_path)
19 File.mkdir!(emoji_path)
20
21 Pleroma.Emoji.reload()
22
23 on_exit(fn ->
24 File.rm_rf!(emoji_path)
25 end)
26
27 :ok
28 end
29
30 test "does nothing by default" do
31 installed_emoji = Pleroma.Emoji.get_all() |> Enum.map(fn {k, _} -> k end)
32 refute "firedfox" in installed_emoji
33
34 message = %{
35 "type" => "Create",
36 "object" => %{
37 "emoji" => [{"firedfox", "https://example.org/emoji/firedfox.png"}],
38 "actor" => "https://example.org/users/admin"
39 }
40 }
41
42 assert {:ok, message} == StealEmojiPolicy.filter(message)
43
44 installed_emoji = Pleroma.Emoji.get_all() |> Enum.map(fn {k, _} -> k end)
45 refute "firedfox" in installed_emoji
46 end
47
48 test "Steals emoji on unknown shortcode from allowed remote host" do
49 installed_emoji = Pleroma.Emoji.get_all() |> Enum.map(fn {k, _} -> k end)
50 refute "firedfox" in installed_emoji
51
52 message = %{
53 "type" => "Create",
54 "object" => %{
55 "emoji" => [{"firedfox", "https://example.org/emoji/firedfox.png"}],
56 "actor" => "https://example.org/users/admin"
57 }
58 }
59
60 clear_config([:mrf_steal_emoji, :hosts], ["example.org"])
61 clear_config([:mrf_steal_emoji, :size_limit], 284_468)
62
63 assert {:ok, message} == StealEmojiPolicy.filter(message)
64
65 installed_emoji = Pleroma.Emoji.get_all() |> Enum.map(fn {k, _} -> k end)
66 assert "firedfox" in installed_emoji
67 end
68 end