|
|
@ -99,35 +99,54 @@ defmodule Pleroma.Instances.InstanceTest do
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
test "Scrapes favicon URLs" do
|
|
|
|
describe "get_or_update_favicon/1" do
|
|
|
|
Tesla.Mock.mock(fn %{url: "https://favicon.example.org/"} ->
|
|
|
|
test "Scrapes favicon URLs" do
|
|
|
|
%Tesla.Env{
|
|
|
|
Tesla.Mock.mock(fn %{url: "https://favicon.example.org/"} ->
|
|
|
|
status: 200,
|
|
|
|
%Tesla.Env{
|
|
|
|
body: ~s[<html><head><link rel="icon" href="/favicon.png"></head></html>]
|
|
|
|
status: 200,
|
|
|
|
}
|
|
|
|
body: ~s[<html><head><link rel="icon" href="/favicon.png"></head></html>]
|
|
|
|
end)
|
|
|
|
}
|
|
|
|
|
|
|
|
end)
|
|
|
|
assert "https://favicon.example.org/favicon.png" ==
|
|
|
|
|
|
|
|
Instance.get_or_update_favicon(URI.parse("https://favicon.example.org/"))
|
|
|
|
assert "https://favicon.example.org/favicon.png" ==
|
|
|
|
end
|
|
|
|
Instance.get_or_update_favicon(URI.parse("https://favicon.example.org/"))
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
test "Returns nil on too long favicon URLs" do
|
|
|
|
test "Returns nil on too long favicon URLs" do
|
|
|
|
long_favicon_url =
|
|
|
|
long_favicon_url =
|
|
|
|
"https://Lorem.ipsum.dolor.sit.amet/consecteturadipiscingelit/Praesentpharetrapurusutaliquamtempus/Mauriseulaoreetarcu/atfacilisisorci/Nullamporttitor/nequesedfeugiatmollis/dolormagnaefficiturlorem/nonpretiumsapienorcieurisus/Nullamveleratsem/Maecenassedaccumsanexnam/favicon.png"
|
|
|
|
"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.Mock.mock(fn %{url: "https://long-favicon.example.org/"} ->
|
|
|
|
%Tesla.Env{
|
|
|
|
%Tesla.Env{
|
|
|
|
status: 200,
|
|
|
|
status: 200,
|
|
|
|
body: ~s[<html><head><link rel="icon" href="] <> long_favicon_url <> ~s["></head></html>]
|
|
|
|
body:
|
|
|
|
}
|
|
|
|
~s[<html><head><link rel="icon" href="] <> long_favicon_url <> ~s["></head></html>]
|
|
|
|
end)
|
|
|
|
}
|
|
|
|
|
|
|
|
end)
|
|
|
|
assert capture_log(fn ->
|
|
|
|
|
|
|
|
assert nil ==
|
|
|
|
assert capture_log(fn ->
|
|
|
|
Instance.get_or_update_favicon(
|
|
|
|
assert nil ==
|
|
|
|
URI.parse("https://long-favicon.example.org/")
|
|
|
|
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) =~
|
|
|
|
|
|
|
|
"Instance.get_or_update_favicon(\"long-favicon.example.org\") error: %Postgrex.Error{"
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test "Handles not getting a favicon URL properly" do
|
|
|
|
|
|
|
|
Tesla.Mock.mock(fn %{url: "https://no-favicon.example.org/"} ->
|
|
|
|
|
|
|
|
%Tesla.Env{
|
|
|
|
|
|
|
|
status: 200,
|
|
|
|
|
|
|
|
body: ~s[<html><head><h1>I wil look down and whisper "GNO.."</h1></head></html>]
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
refute capture_log(fn ->
|
|
|
|
|
|
|
|
assert nil ==
|
|
|
|
|
|
|
|
Instance.get_or_update_favicon(
|
|
|
|
|
|
|
|
URI.parse("https://no-favicon.example.org/")
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
end) =~ "Instance.scrape_favicon(\"https://no-favicon.example.org/\") error: "
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|