mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-12-23 09:44:52 +00:00
Bring our adjustments into line with atom-failure
This commit is contained in:
parent
49ed27cd96
commit
33fb74043d
|
@ -68,7 +68,10 @@ defmodule Akkoma.Collections.Fetcher do
|
||||||
items
|
items
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
{:error, {"Object has been deleted", _, _}} ->
|
{:error, :not_found} ->
|
||||||
|
items
|
||||||
|
|
||||||
|
{:error, :forbidden} ->
|
||||||
items
|
items
|
||||||
|
|
||||||
{:error, error} ->
|
{:error, error} ->
|
||||||
|
|
|
@ -122,7 +122,7 @@ defmodule Pleroma.Object.Fetcher do
|
||||||
{:ok, object}
|
{:ok, object}
|
||||||
else
|
else
|
||||||
{:local, true} -> {:ok, object}
|
{:local, true} -> {:ok, object}
|
||||||
{:id, false} -> {:error, "Object id changed on refetch"}
|
{:id, false} -> {:error, :id_mismatch}
|
||||||
e -> {:error, e}
|
e -> {:error, e}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -136,7 +136,7 @@ defmodule Pleroma.Object.Fetcher do
|
||||||
def fetch_object_from_id(id, options \\ []) do
|
def fetch_object_from_id(id, options \\ []) do
|
||||||
with %URI{} = uri <- URI.parse(id),
|
with %URI{} = uri <- URI.parse(id),
|
||||||
# let's check the URI is even vaguely valid first
|
# let's check the URI is even vaguely valid first
|
||||||
{:scheme, true} <- {:scheme, uri.scheme == "http" or uri.scheme == "https"},
|
{:valid_uri_scheme, true} <- {:valid_uri_scheme, uri.scheme == "http" or uri.scheme == "https"},
|
||||||
# If we have instance restrictions, apply them here to prevent fetching from unwanted instances
|
# If we have instance restrictions, apply them here to prevent fetching from unwanted instances
|
||||||
{:ok, nil} <- Pleroma.Web.ActivityPub.MRF.SimplePolicy.check_reject(uri),
|
{:ok, nil} <- Pleroma.Web.ActivityPub.MRF.SimplePolicy.check_reject(uri),
|
||||||
{:ok, _} <- Pleroma.Web.ActivityPub.MRF.SimplePolicy.check_accept(uri),
|
{:ok, _} <- Pleroma.Web.ActivityPub.MRF.SimplePolicy.check_accept(uri),
|
||||||
|
@ -155,8 +155,9 @@ defmodule Pleroma.Object.Fetcher do
|
||||||
log_fetch_error(id, e)
|
log_fetch_error(id, e)
|
||||||
{:error, :allowed_depth}
|
{:error, :allowed_depth}
|
||||||
|
|
||||||
{:scheme, false} ->
|
{:valid_uri_scheme, _} = e ->
|
||||||
{:error, "URI Scheme Invalid"}
|
log_fetch_error(id, e)
|
||||||
|
{:error, :invalid_uri_scheme}
|
||||||
|
|
||||||
{:containment, reason} = e ->
|
{:containment, reason} = e ->
|
||||||
log_fetch_error(id, e)
|
log_fetch_error(id, e)
|
||||||
|
@ -253,7 +254,7 @@ defmodule Pleroma.Object.Fetcher do
|
||||||
def fetch_and_contain_remote_object_from_id(id) when is_binary(id) do
|
def fetch_and_contain_remote_object_from_id(id) when is_binary(id) do
|
||||||
Logger.debug("Fetching object #{id} via AP")
|
Logger.debug("Fetching object #{id} via AP")
|
||||||
|
|
||||||
with {:scheme, true} <- {:scheme, String.starts_with?(id, "http")},
|
with {:valid_uri_scheme, true} <- {:valid_uri_scheme, String.starts_with?(id, "http")},
|
||||||
{_, :ok} <- {:local_fetch, Containment.contain_local_fetch(id)},
|
{_, :ok} <- {:local_fetch, Containment.contain_local_fetch(id)},
|
||||||
{:ok, final_id, body} <- get_object(id),
|
{:ok, final_id, body} <- get_object(id),
|
||||||
{:ok, data} <- safe_json_decode(body),
|
{:ok, data} <- safe_json_decode(body),
|
||||||
|
@ -265,17 +266,21 @@ defmodule Pleroma.Object.Fetcher do
|
||||||
|
|
||||||
{:ok, data}
|
{:ok, data}
|
||||||
else
|
else
|
||||||
{:strict_id, _} ->
|
{:strict_id, _} = e->
|
||||||
{:error, "Object's ActivityPub id/url does not match final fetch URL"}
|
log_fetch_error(id, e)
|
||||||
|
{:error, :id_mismatch}
|
||||||
|
|
||||||
{:scheme, _} ->
|
{:valid_uri_scheme, _} = e ->
|
||||||
{:error, "Unsupported URI scheme"}
|
log_fetch_error(id, e)
|
||||||
|
{:error, :invalid_uri_scheme}
|
||||||
|
|
||||||
{:local_fetch, _} ->
|
{:local_fetch, _} = e ->
|
||||||
{:error, "Trying to fetch local resource"}
|
log_fetch_error(id, e)
|
||||||
|
{:error, :local_resource}
|
||||||
|
|
||||||
{:containment, _} ->
|
{:containment, reason} ->
|
||||||
{:error, "Object containment failed."}
|
log_fetch_error(id, reason)
|
||||||
|
{:error, reason}
|
||||||
|
|
||||||
{:error, e} ->
|
{:error, e} ->
|
||||||
{:error, e}
|
{:error, e}
|
||||||
|
@ -286,7 +291,7 @@ defmodule Pleroma.Object.Fetcher do
|
||||||
end
|
end
|
||||||
|
|
||||||
def fetch_and_contain_remote_object_from_id(_id),
|
def fetch_and_contain_remote_object_from_id(_id),
|
||||||
do: {:error, "id must be a string"}
|
do: {:error, :invalid_id}
|
||||||
|
|
||||||
defp check_crossdomain_redirect(final_host, original_url)
|
defp check_crossdomain_redirect(final_host, original_url)
|
||||||
|
|
||||||
|
|
|
@ -570,7 +570,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
||||||
test "returns nil when cannot normalize object" do
|
test "returns nil when cannot normalize object" do
|
||||||
assert capture_log(fn ->
|
assert capture_log(fn ->
|
||||||
refute Transmogrifier.get_obj_helper("test-obj-id")
|
refute Transmogrifier.get_obj_helper("test-obj-id")
|
||||||
end) =~ "URI Scheme Invalid"
|
end) =~ ":valid_uri_scheme"
|
||||||
end
|
end
|
||||||
|
|
||||||
@tag capture_log: true
|
@tag capture_log: true
|
||||||
|
|
Loading…
Reference in a new issue