summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorfeld <feld@feld.me>2024-07-24 20:58:31 +0000
committerfeld <feld@feld.me>2024-07-24 20:58:31 +0000
commit700c1066801ba1400a32c819fb0e608aa834aa51 (patch)
treed3b034ccdde9bb3b03738380e5c1ccd49e3c0450 /test
parentf32a837afa694999426d644d00ddbe0c521d0bb3 (diff)
parent659891921371fd3a8788089fbc96a9158f07f289 (diff)
downloadpleroma-700c1066801ba1400a32c819fb0e608aa834aa51.tar.gz
pleroma-700c1066801ba1400a32c819fb0e608aa834aa51.zip
Merge branch 'oban/rich-media-hardening' into 'develop'
Harden Rich Media parsing against very slow or malicious URLs See merge request pleroma/pleroma!4192
Diffstat (limited to 'test')
-rw-r--r--test/pleroma/web/rich_media/backfill_test.exs26
1 files changed, 26 insertions, 0 deletions
diff --git a/test/pleroma/web/rich_media/backfill_test.exs b/test/pleroma/web/rich_media/backfill_test.exs
new file mode 100644
index 000000000..6d221fcf5
--- /dev/null
+++ b/test/pleroma/web/rich_media/backfill_test.exs
@@ -0,0 +1,26 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.RichMedia.BackfillTest do
+ use Pleroma.DataCase
+
+ alias Pleroma.Web.RichMedia.Backfill
+ alias Pleroma.Web.RichMedia.Card
+
+ import Mox
+
+ setup_all do: clear_config([:rich_media, :enabled], true)
+
+ test "sets a negative cache entry for an error" do
+ url = "https://bad.example.com/"
+ url_hash = Card.url_to_hash(url)
+
+ Tesla.Mock.mock(fn %{url: ^url} -> :error end)
+
+ Pleroma.CachexMock
+ |> expect(:put, fn :rich_media_cache, ^url_hash, :error, ttl: _ -> {:ok, true} end)
+
+ Backfill.run(%{"url" => url})
+ end
+end