Handle webfinger JSON data being invalid format
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
0ebb797740
commit
28f5cdd03a
@ -129,6 +129,7 @@ defmodule Mobilizon.Federation.WebFinger do
|
|||||||
| :address_invalid
|
| :address_invalid
|
||||||
| :http_error
|
| :http_error
|
||||||
| :webfinger_information_not_json
|
| :webfinger_information_not_json
|
||||||
|
| :webfinger_information_not_valid
|
||||||
| :no_url_in_webfinger_data
|
| :no_url_in_webfinger_data
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
@ -164,7 +165,9 @@ defmodule Mobilizon.Federation.WebFinger do
|
|||||||
end
|
end
|
||||||
|
|
||||||
@spec fetch_webfinger_data(String.t()) ::
|
@spec fetch_webfinger_data(String.t()) ::
|
||||||
{:ok, map()} | {:error, :webfinger_information_not_json | :http_error}
|
{:ok, map()}
|
||||||
|
| {:error,
|
||||||
|
:webfinger_information_not_json | :webfinger_information_not_valid | :http_error}
|
||||||
defp fetch_webfinger_data(address) do
|
defp fetch_webfinger_data(address) do
|
||||||
Logger.debug("Calling WebfingerClient with #{inspect(address)}")
|
Logger.debug("Calling WebfingerClient with #{inspect(address)}")
|
||||||
|
|
||||||
@ -243,10 +246,15 @@ defmodule Mobilizon.Federation.WebFinger do
|
|||||||
end
|
end
|
||||||
|
|
||||||
@spec webfinger_from_json(map() | String.t()) ::
|
@spec webfinger_from_json(map() | String.t()) ::
|
||||||
{:ok, map()} | {:error, :webfinger_information_not_json}
|
{:ok, map()}
|
||||||
|
| {:error, :webfinger_information_not_json | :webfinger_information_not_valid}
|
||||||
defp webfinger_from_json(doc) when is_map(doc) do
|
defp webfinger_from_json(doc) when is_map(doc) do
|
||||||
|
links = Map.get(doc, "links")
|
||||||
|
subject = Map.get(doc, "subject")
|
||||||
|
|
||||||
|
if !is_nil(links) && !is_nil(subject) do
|
||||||
data =
|
data =
|
||||||
Enum.reduce(doc["links"], %{"subject" => doc["subject"]}, fn link, data ->
|
Enum.reduce(links, %{"subject" => subject}, fn link, data ->
|
||||||
case {link["type"], link["rel"]} do
|
case {link["type"], link["rel"]} do
|
||||||
{"application/activity+json", "self"} ->
|
{"application/activity+json", "self"} ->
|
||||||
Map.put(data, "url", link["href"])
|
Map.put(data, "url", link["href"])
|
||||||
@ -257,7 +265,7 @@ defmodule Mobilizon.Federation.WebFinger do
|
|||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
Logger.debug(fn ->
|
Logger.debug(fn ->
|
||||||
"Unhandled type to finger: #{inspect(link["type"])}"
|
"Unhandled type to finger: #{inspect(link)}"
|
||||||
end)
|
end)
|
||||||
|
|
||||||
data
|
data
|
||||||
@ -265,6 +273,9 @@ defmodule Mobilizon.Federation.WebFinger do
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
{:ok, data}
|
{:ok, data}
|
||||||
|
else
|
||||||
|
{:error, :webfinger_information_not_valid}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp webfinger_from_json(_doc), do: {:error, :webfinger_information_not_json}
|
defp webfinger_from_json(_doc), do: {:error, :webfinger_information_not_json}
|
||||||
|
Loading…
Reference in New Issue
Block a user