From 6d003e1acdf4d92cbf02ccba7b627d1fb8f3db6f Mon Sep 17 00:00:00 2001 From: Oneric Date: Sun, 10 Mar 2024 01:14:51 +0100 Subject: [PATCH] test/steal_emoji: consolidate configuration setup --- .../mrf/steal_emoji_policy_test.exs | 28 ++++++------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/test/pleroma/web/activity_pub/mrf/steal_emoji_policy_test.exs b/test/pleroma/web/activity_pub/mrf/steal_emoji_policy_test.exs index b34269aa5..2103e8539 100644 --- a/test/pleroma/web/activity_pub/mrf/steal_emoji_policy_test.exs +++ b/test/pleroma/web/activity_pub/mrf/steal_emoji_policy_test.exs @@ -44,6 +44,11 @@ defmacro mock_tesla( end setup do + clear_config(:mrf_steal_emoji, + hosts: ["example.org"], + size_limit: 284_468 + ) + emoji_path = [:instance, :static_dir] |> Config.get() |> Path.join("emoji/stolen") Emoji.reload() @@ -66,6 +71,7 @@ defmacro mock_tesla( test "does nothing by default", %{message: message} do refute "firedfox" in installed() + clear_config(:mrf_steal_emoji, []) assert {:ok, _message} = StealEmojiPolicy.filter(message) refute "firedfox" in installed() @@ -79,8 +85,6 @@ test "Steals emoji on unknown shortcode from allowed remote host", %{ mock_tesla() - clear_config(:mrf_steal_emoji, hosts: ["example.org"], size_limit: 284_468) - assert {:ok, _message} = StealEmojiPolicy.filter(message) assert "firedfox" in installed() @@ -100,8 +104,6 @@ test "rejects invalid shortcodes" do mock_tesla() - clear_config(:mrf_steal_emoji, hosts: ["example.org"], size_limit: 284_468) - refute "firedfox" in installed() refute has_pack?() @@ -122,8 +124,6 @@ test "prefers content-type header for extension" do mock_tesla("https://example.org/emoji/firedfox.fud", 200, [{"content-type", "image/gif"}]) - clear_config(:mrf_steal_emoji, hosts: ["example.org"], size_limit: 284_468) - assert {:ok, _message} = StealEmojiPolicy.filter(message) assert "firedfox" in installed() @@ -133,11 +133,7 @@ test "prefers content-type header for extension" do test "reject regex shortcode", %{message: message} do refute "firedfox" in installed() - clear_config(:mrf_steal_emoji, - hosts: ["example.org"], - size_limit: 284_468, - rejected_shortcodes: [~r/firedfox/] - ) + clear_config([:mrf_steal_emoji, :rejected_shortcodes], [~r/firedfox/]) assert {:ok, _message} = StealEmojiPolicy.filter(message) @@ -147,11 +143,7 @@ test "reject regex shortcode", %{message: message} do test "reject string shortcode", %{message: message} do refute "firedfox" in installed() - clear_config(:mrf_steal_emoji, - hosts: ["example.org"], - size_limit: 284_468, - rejected_shortcodes: ["firedfox"] - ) + clear_config([:mrf_steal_emoji, :rejected_shortcodes], ["firedfox"]) assert {:ok, _message} = StealEmojiPolicy.filter(message) @@ -163,7 +155,7 @@ test "reject if size is above the limit", %{message: message} do mock_tesla() - clear_config(:mrf_steal_emoji, hosts: ["example.org"], size_limit: 50_000) + clear_config([:mrf_steal_emoji, :size_limit], 50_000) assert {:ok, _message} = StealEmojiPolicy.filter(message) @@ -175,8 +167,6 @@ test "reject if host returns error", %{message: message} do mock_tesla("https://example.org/emoji/firedfox.png", 404, [], "Not found") - clear_config(:mrf_steal_emoji, hosts: ["example.org"], size_limit: 284_468) - ExUnit.CaptureLog.capture_log(fn -> assert {:ok, _message} = StealEmojiPolicy.filter(message) end) =~ "MRF.StealEmojiPolicy: Failed to fetch https://example.org/emoji/firedfox.png"