mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-11-17 18:49:15 +00:00
test/steal_emoji: consolidate configuration setup
This commit is contained in:
parent
d1ce5fd911
commit
6d003e1acd
|
@ -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"
|
||||
|
|
Loading…
Reference in a new issue