Merge branch 'worker-messages' into 'develop'

Worker messages

Closes #1705

See merge request pleroma/pleroma!2410
This commit is contained in:
Haelwenn 2020-04-22 15:09:10 +00:00
commit 2e73c19edc
4 changed files with 18 additions and 9 deletions

View file

@ -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

View file

@ -55,11 +55,12 @@ def perform(
|> Jason.encode!() |> Jason.encode!()
|> push_message(build_sub(subscription), gcm_api_key, subscription) |> push_message(build_sub(subscription), gcm_api_key, subscription)
end end
|> (&{:ok, &1}).()
end end
def perform(_) do def perform(_) do
Logger.warn("Unknown notification type") Logger.warn("Unknown notification type")
:error {:error, :unknown_type}
end end
@doc "Push message to web" @doc "Push message to web"

View file

@ -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

View file

@ -63,12 +63,12 @@ test "performs sending notifications" do
activity: activity activity: activity
) )
assert Impl.perform(notif) == [:ok, :ok] assert Impl.perform(notif) == {:ok, [:ok, :ok]}
end end
@tag capture_log: true @tag capture_log: true
test "returns error if notif does not match " do test "returns error if notif does not match " do
assert Impl.perform(%{}) == :error assert Impl.perform(%{}) == {:error, :unknown_type}
end end
test "successful message sending" do test "successful message sending" do