aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/html_test.exs14
-rw-r--r--test/web/instances/instance_test.exs33
-rw-r--r--test/web/mastodon_api/controllers/status_controller_test.exs38
-rw-r--r--test/web/rich_media/parser_test.exs4
4 files changed, 78 insertions, 11 deletions
diff --git a/test/html_test.exs b/test/html_test.exs
index f8907c8b4..7d3756884 100644
--- a/test/html_test.exs
+++ b/test/html_test.exs
@@ -165,7 +165,7 @@ defmodule Pleroma.HTMLTest do
end
end
- describe "extract_first_external_url" do
+ describe "extract_first_external_url_from_object" do
test "extracts the url" do
user = insert(:user)
@@ -176,7 +176,7 @@ defmodule Pleroma.HTMLTest do
})
object = Object.normalize(activity)
- {:ok, url} = HTML.extract_first_external_url(object, object.data["content"])
+ {:ok, url} = HTML.extract_first_external_url_from_object(object)
assert url == "https://github.com/komeiji-satori/Dress"
end
@@ -191,7 +191,7 @@ defmodule Pleroma.HTMLTest do
})
object = Object.normalize(activity)
- {:ok, url} = HTML.extract_first_external_url(object, object.data["content"])
+ {:ok, url} = HTML.extract_first_external_url_from_object(object)
assert url == "https://github.com/syuilo/misskey/blob/develop/docs/setup.en.md"
@@ -207,7 +207,7 @@ defmodule Pleroma.HTMLTest do
})
object = Object.normalize(activity)
- {:ok, url} = HTML.extract_first_external_url(object, object.data["content"])
+ {:ok, url} = HTML.extract_first_external_url_from_object(object)
assert url == "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=72255140"
end
@@ -223,7 +223,7 @@ defmodule Pleroma.HTMLTest do
})
object = Object.normalize(activity)
- {:ok, url} = HTML.extract_first_external_url(object, object.data["content"])
+ {:ok, url} = HTML.extract_first_external_url_from_object(object)
assert url == "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=72255140"
end
@@ -235,7 +235,7 @@ defmodule Pleroma.HTMLTest do
object = Object.normalize(activity)
- assert {:ok, nil} = HTML.extract_first_external_url(object, object.data["content"])
+ assert {:ok, nil} = HTML.extract_first_external_url_from_object(object)
end
test "skips attachment links" do
@@ -249,7 +249,7 @@ defmodule Pleroma.HTMLTest do
object = Object.normalize(activity)
- assert {:ok, nil} = HTML.extract_first_external_url(object, object.data["content"])
+ assert {:ok, nil} = HTML.extract_first_external_url_from_object(object)
end
end
end
diff --git a/test/web/instances/instance_test.exs b/test/web/instances/instance_test.exs
index e463200ca..dc6ace843 100644
--- a/test/web/instances/instance_test.exs
+++ b/test/web/instances/instance_test.exs
@@ -8,6 +8,7 @@ defmodule Pleroma.Instances.InstanceTest do
use Pleroma.DataCase
+ import ExUnit.CaptureLog
import Pleroma.Factory
setup_all do: clear_config([:instance, :federation_reachability_timeout_days], 1)
@@ -97,4 +98,36 @@ defmodule Pleroma.Instances.InstanceTest do
assert initial_value == instance.unreachable_since
end
end
+
+ test "Scrapes favicon URLs" do
+ Tesla.Mock.mock(fn %{url: "https://favicon.example.org/"} ->
+ %Tesla.Env{
+ status: 200,
+ body: ~s[<html><head><link rel="icon" href="/favicon.png"></head></html>]
+ }
+ end)
+
+ assert "https://favicon.example.org/favicon.png" ==
+ Instance.get_or_update_favicon(URI.parse("https://favicon.example.org/"))
+ end
+
+ test "Returns nil on too long favicon URLs" do
+ long_favicon_url =
+ "https://Lorem.ipsum.dolor.sit.amet/consecteturadipiscingelit/Praesentpharetrapurusutaliquamtempus/Mauriseulaoreetarcu/atfacilisisorci/Nullamporttitor/nequesedfeugiatmollis/dolormagnaefficiturlorem/nonpretiumsapienorcieurisus/Nullamveleratsem/Maecenassedaccumsanexnam/favicon.png"
+
+ Tesla.Mock.mock(fn %{url: "https://long-favicon.example.org/"} ->
+ %Tesla.Env{
+ status: 200,
+ body: ~s[<html><head><link rel="icon" href="] <> long_favicon_url <> ~s["></head></html>]
+ }
+ end)
+
+ assert capture_log(fn ->
+ assert nil ==
+ Instance.get_or_update_favicon(
+ URI.parse("https://long-favicon.example.org/")
+ )
+ end) =~
+ "Instance.get_or_update_favicon(\"long-favicon.example.org\") error: %Postgrex.Error{"
+ end
end
diff --git a/test/web/mastodon_api/controllers/status_controller_test.exs b/test/web/mastodon_api/controllers/status_controller_test.exs
index 5955d8334..f221884e7 100644
--- a/test/web/mastodon_api/controllers/status_controller_test.exs
+++ b/test/web/mastodon_api/controllers/status_controller_test.exs
@@ -296,9 +296,45 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
assert real_status == fake_status
end
+ test "fake statuses' preview card is not cached", %{conn: conn} do
+ clear_config([:rich_media, :enabled], true)
+
+ Tesla.Mock.mock(fn
+ %{
+ method: :get,
+ url: "https://example.com/twitter-card"
+ } ->
+ %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/twitter_card.html")}
+
+ env ->
+ apply(HttpRequestMock, :request, [env])
+ end)
+
+ conn1 =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/statuses", %{
+ "status" => "https://example.com/ogp",
+ "preview" => true
+ })
+
+ conn2 =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/statuses", %{
+ "status" => "https://example.com/twitter-card",
+ "preview" => true
+ })
+
+ assert %{"card" => %{"title" => "The Rock"}} = json_response_and_validate_schema(conn1, 200)
+
+ assert %{"card" => %{"title" => "Small Island Developing States Photo Submission"}} =
+ json_response_and_validate_schema(conn2, 200)
+ end
+
test "posting a status with OGP link preview", %{conn: conn} do
Tesla.Mock.mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
- Config.put([:rich_media, :enabled], true)
+ clear_config([:rich_media, :enabled], true)
conn =
conn
diff --git a/test/web/rich_media/parser_test.exs b/test/web/rich_media/parser_test.exs
index 1e09cbf84..21ae35f8b 100644
--- a/test/web/rich_media/parser_test.exs
+++ b/test/web/rich_media/parser_test.exs
@@ -66,9 +66,7 @@ defmodule Pleroma.Web.RichMedia.ParserTest do
end
test "doesn't just add a title" do
- assert Parser.parse("http://example.com/non-ogp") ==
- {:error,
- "Found metadata was invalid or incomplete: %{\"url\" => \"http://example.com/non-ogp\"}"}
+ assert {:error, {:invalid_metadata, _}} = Parser.parse("http://example.com/non-ogp")
end
test "parses ogp" do