Federator: Return proper values for jobs
This commit is contained in:
parent
f719a5b23a
commit
923513b641
|
@ -72,19 +72,24 @@ def perform(:incoming_ap_doc, params) do
|
||||||
# actor shouldn't be acting on objects outside their own AP server.
|
# actor shouldn't be acting on objects outside their own AP server.
|
||||||
with {:ok, _user} <- ap_enabled_actor(params["actor"]),
|
with {:ok, _user} <- ap_enabled_actor(params["actor"]),
|
||||||
nil <- Activity.normalize(params["id"]),
|
nil <- Activity.normalize(params["id"]),
|
||||||
:ok <- Containment.contain_origin_from_id(params["actor"], params),
|
{_, :ok} <-
|
||||||
|
{:correct_origin?, Containment.contain_origin_from_id(params["actor"], params)},
|
||||||
{:ok, activity} <- Transmogrifier.handle_incoming(params) do
|
{:ok, activity} <- Transmogrifier.handle_incoming(params) do
|
||||||
{:ok, activity}
|
{:ok, activity}
|
||||||
else
|
else
|
||||||
|
{:correct_origin?, _} ->
|
||||||
|
Logger.debug("Origin containment failure for #{params["id"]}")
|
||||||
|
{:error, :origin_containment_failed}
|
||||||
|
|
||||||
%Activity{} ->
|
%Activity{} ->
|
||||||
Logger.debug("Already had #{params["id"]}")
|
Logger.debug("Already had #{params["id"]}")
|
||||||
:error
|
{:error, :already_present}
|
||||||
|
|
||||||
_e ->
|
e ->
|
||||||
# Just drop those for now
|
# Just drop those for now
|
||||||
Logger.debug("Unhandled activity")
|
Logger.debug("Unhandled activity")
|
||||||
Logger.debug(Jason.encode!(params, pretty: true))
|
Logger.debug(Jason.encode!(params, pretty: true))
|
||||||
:error
|
{:error, e}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -130,6 +130,9 @@ test "successfully processes incoming AP docs with correct origin" do
|
||||||
|
|
||||||
assert {:ok, job} = Federator.incoming_ap_doc(params)
|
assert {:ok, job} = Federator.incoming_ap_doc(params)
|
||||||
assert {:ok, _activity} = ObanHelpers.perform(job)
|
assert {:ok, _activity} = ObanHelpers.perform(job)
|
||||||
|
|
||||||
|
assert {:ok, job} = Federator.incoming_ap_doc(params)
|
||||||
|
assert {:error, :already_present} = ObanHelpers.perform(job)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "rejects incoming AP docs with incorrect origin" do
|
test "rejects incoming AP docs with incorrect origin" do
|
||||||
|
@ -148,7 +151,7 @@ test "rejects incoming AP docs with incorrect origin" do
|
||||||
}
|
}
|
||||||
|
|
||||||
assert {:ok, job} = Federator.incoming_ap_doc(params)
|
assert {:ok, job} = Federator.incoming_ap_doc(params)
|
||||||
assert :error = ObanHelpers.perform(job)
|
assert {:error, :origin_containment_failed} = ObanHelpers.perform(job)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it does not crash if MRF rejects the post" do
|
test "it does not crash if MRF rejects the post" do
|
||||||
|
@ -164,7 +167,7 @@ test "it does not crash if MRF rejects the post" do
|
||||||
|> Poison.decode!()
|
|> Poison.decode!()
|
||||||
|
|
||||||
assert {:ok, job} = Federator.incoming_ap_doc(params)
|
assert {:ok, job} = Federator.incoming_ap_doc(params)
|
||||||
assert :error = ObanHelpers.perform(job)
|
assert {:error, _} = ObanHelpers.perform(job)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue