summaryrefslogtreecommitdiff
path: root/test/web/rich_media/parser_test.exs
diff options
context:
space:
mode:
authorrinpatch <rinpatch@sdf.org>2020-09-14 14:45:58 +0300
committerrinpatch <rinpatch@sdf.org>2020-09-14 14:45:58 +0300
commitf70335002df9b2b3f47f0ccaed6aaeebfb14435f (patch)
tree16c15bdcdf5c5260e58fae9947075aca7d80687a /test/web/rich_media/parser_test.exs
parentf66a15c4a51e1c8f614b4c1609b2385a29762931 (diff)
downloadpleroma-f70335002df9b2b3f47f0ccaed6aaeebfb14435f.tar.gz
pleroma-f70335002df9b2b3f47f0ccaed6aaeebfb14435f.zip
RichMedia: Do a HEAD request to check content type/length
This shouldn't be too expensive, since the connections are pooled, but it should save us some bandwidth since we won't fetch non-html files and files that are too large for us to process (especially since you can't cancel a request without closing the connection with HTTP1).
Diffstat (limited to 'test/web/rich_media/parser_test.exs')
-rw-r--r--test/web/rich_media/parser_test.exs29
1 files changed, 29 insertions, 0 deletions
diff --git a/test/web/rich_media/parser_test.exs b/test/web/rich_media/parser_test.exs
index 21ae35f8b..d65a63121 100644
--- a/test/web/rich_media/parser_test.exs
+++ b/test/web/rich_media/parser_test.exs
@@ -56,6 +56,27 @@ defmodule Pleroma.Web.RichMedia.ParserTest do
%{method: :get, url: "http://example.com/error"} ->
{:error, :overload}
+
+ %{
+ method: :head,
+ url: "http://example.com/huge-page"
+ } ->
+ %Tesla.Env{
+ status: 200,
+ headers: [{"content-length", "2000001"}, {"content-type", "text/html"}]
+ }
+
+ %{
+ method: :head,
+ url: "http://example.com/pdf-file"
+ } ->
+ %Tesla.Env{
+ status: 200,
+ headers: [{"content-length", "1000000"}, {"content-type", "application/pdf"}]
+ }
+
+ %{method: :head} ->
+ %Tesla.Env{status: 404, body: "", headers: []}
end)
:ok
@@ -144,4 +165,12 @@ defmodule Pleroma.Web.RichMedia.ParserTest do
test "returns error if getting page was not successful" do
assert {:error, :overload} = Parser.parse("http://example.com/error")
end
+
+ test "does a HEAD request to check if the body is too large" do
+ assert {:error, body_too_large} = Parser.parse("http://example.com/huge-page")
+ end
+
+ test "does a HEAD request to check if the body is html" do
+ assert {:error, {:content_type, _}} = Parser.parse("http://example.com/pdf-file")
+ end
end