test/steal_emoji: consolidate configuration setup
This commit is contained in:
parent
d1ce5fd911
commit
6d003e1acd
1 changed files with 9 additions and 19 deletions
|
@ -44,6 +44,11 @@ defmacro mock_tesla(
|
||||||
end
|
end
|
||||||
|
|
||||||
setup do
|
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_path = [:instance, :static_dir] |> Config.get() |> Path.join("emoji/stolen")
|
||||||
|
|
||||||
Emoji.reload()
|
Emoji.reload()
|
||||||
|
@ -66,6 +71,7 @@ defmacro mock_tesla(
|
||||||
test "does nothing by default", %{message: message} do
|
test "does nothing by default", %{message: message} do
|
||||||
refute "firedfox" in installed()
|
refute "firedfox" in installed()
|
||||||
|
|
||||||
|
clear_config(:mrf_steal_emoji, [])
|
||||||
assert {:ok, _message} = StealEmojiPolicy.filter(message)
|
assert {:ok, _message} = StealEmojiPolicy.filter(message)
|
||||||
|
|
||||||
refute "firedfox" in installed()
|
refute "firedfox" in installed()
|
||||||
|
@ -79,8 +85,6 @@ test "Steals emoji on unknown shortcode from allowed remote host", %{
|
||||||
|
|
||||||
mock_tesla()
|
mock_tesla()
|
||||||
|
|
||||||
clear_config(:mrf_steal_emoji, hosts: ["example.org"], size_limit: 284_468)
|
|
||||||
|
|
||||||
assert {:ok, _message} = StealEmojiPolicy.filter(message)
|
assert {:ok, _message} = StealEmojiPolicy.filter(message)
|
||||||
|
|
||||||
assert "firedfox" in installed()
|
assert "firedfox" in installed()
|
||||||
|
@ -100,8 +104,6 @@ test "rejects invalid shortcodes" do
|
||||||
|
|
||||||
mock_tesla()
|
mock_tesla()
|
||||||
|
|
||||||
clear_config(:mrf_steal_emoji, hosts: ["example.org"], size_limit: 284_468)
|
|
||||||
|
|
||||||
refute "firedfox" in installed()
|
refute "firedfox" in installed()
|
||||||
refute has_pack?()
|
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"}])
|
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 {:ok, _message} = StealEmojiPolicy.filter(message)
|
||||||
|
|
||||||
assert "firedfox" in installed()
|
assert "firedfox" in installed()
|
||||||
|
@ -133,11 +133,7 @@ test "prefers content-type header for extension" do
|
||||||
test "reject regex shortcode", %{message: message} do
|
test "reject regex shortcode", %{message: message} do
|
||||||
refute "firedfox" in installed()
|
refute "firedfox" in installed()
|
||||||
|
|
||||||
clear_config(:mrf_steal_emoji,
|
clear_config([:mrf_steal_emoji, :rejected_shortcodes], [~r/firedfox/])
|
||||||
hosts: ["example.org"],
|
|
||||||
size_limit: 284_468,
|
|
||||||
rejected_shortcodes: [~r/firedfox/]
|
|
||||||
)
|
|
||||||
|
|
||||||
assert {:ok, _message} = StealEmojiPolicy.filter(message)
|
assert {:ok, _message} = StealEmojiPolicy.filter(message)
|
||||||
|
|
||||||
|
@ -147,11 +143,7 @@ test "reject regex shortcode", %{message: message} do
|
||||||
test "reject string shortcode", %{message: message} do
|
test "reject string shortcode", %{message: message} do
|
||||||
refute "firedfox" in installed()
|
refute "firedfox" in installed()
|
||||||
|
|
||||||
clear_config(:mrf_steal_emoji,
|
clear_config([:mrf_steal_emoji, :rejected_shortcodes], ["firedfox"])
|
||||||
hosts: ["example.org"],
|
|
||||||
size_limit: 284_468,
|
|
||||||
rejected_shortcodes: ["firedfox"]
|
|
||||||
)
|
|
||||||
|
|
||||||
assert {:ok, _message} = StealEmojiPolicy.filter(message)
|
assert {:ok, _message} = StealEmojiPolicy.filter(message)
|
||||||
|
|
||||||
|
@ -163,7 +155,7 @@ test "reject if size is above the limit", %{message: message} do
|
||||||
|
|
||||||
mock_tesla()
|
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)
|
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")
|
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 ->
|
ExUnit.CaptureLog.capture_log(fn ->
|
||||||
assert {:ok, _message} = StealEmojiPolicy.filter(message)
|
assert {:ok, _message} = StealEmojiPolicy.filter(message)
|
||||||
end) =~ "MRF.StealEmojiPolicy: Failed to fetch https://example.org/emoji/firedfox.png"
|
end) =~ "MRF.StealEmojiPolicy: Failed to fetch https://example.org/emoji/firedfox.png"
|
||||||
|
|
Loading…
Reference in a new issue