mirror of
https://git.youjo.love/youjo/youjo-be.git
synced 2024-11-20 13:59:55 +01:00
helpers: use AutoLinker to validate URIs as well as the other tests
This commit is contained in:
parent
d7a278a733
commit
9f3cb38012
2 changed files with 24 additions and 1 deletions
|
@ -12,7 +12,10 @@ defmodule Pleroma.Web.RichMedia.Helpers do
|
||||||
defp validate_page_url(%URI{authority: nil}), do: :error
|
defp validate_page_url(%URI{authority: nil}), do: :error
|
||||||
defp validate_page_url(%URI{scheme: nil}), do: :error
|
defp validate_page_url(%URI{scheme: nil}), do: :error
|
||||||
defp validate_page_url(%URI{}), do: :ok
|
defp validate_page_url(%URI{}), do: :ok
|
||||||
defp validate_page_url(page_url), do: URI.parse(page_url) |> validate_page_url
|
|
||||||
|
defp validate_page_url(page_url) do
|
||||||
|
AutoLinker.Parser.is_url?(page_url, true) && URI.parse(page_url) |> validate_page_url
|
||||||
|
end
|
||||||
|
|
||||||
def fetch_data_for_activity(%Activity{} = activity) do
|
def fetch_data_for_activity(%Activity{} = activity) do
|
||||||
with true <- Pleroma.Config.get([:rich_media, :enabled]),
|
with true <- Pleroma.Config.get([:rich_media, :enabled]),
|
||||||
|
|
|
@ -20,7 +20,27 @@ defmodule Pleroma.Web.RichMedia.HelpersTest do
|
||||||
"content_type" => "text/markdown"
|
"content_type" => "text/markdown"
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Pleroma.Config.put([:rich_media, :enabled], true)
|
||||||
|
|
||||||
assert %{} == Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
|
assert %{} == Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
|
||||||
|
|
||||||
|
Pleroma.Config.put([:rich_media, :enabled], false)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "refuses to crawl malformed URLs" do
|
||||||
|
user = insert(:user)
|
||||||
|
|
||||||
|
{:ok, activity} =
|
||||||
|
CommonAPI.post(user, %{
|
||||||
|
"status" => "[test](example.com[]/ogp)",
|
||||||
|
"content_type" => "text/markdown"
|
||||||
|
})
|
||||||
|
|
||||||
|
Pleroma.Config.put([:rich_media, :enabled], true)
|
||||||
|
|
||||||
|
assert %{} == Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
|
||||||
|
|
||||||
|
Pleroma.Config.put([:rich_media, :enabled], false)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "crawls valid, complete URLs" do
|
test "crawls valid, complete URLs" do
|
||||||
|
|
Loading…
Reference in a new issue