mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2024-12-31 12:28:43 +00:00
Cancel ReceiverWorker jobs if the user account has been disabled / deactivated
This commit is contained in:
parent
bb2f4a76b3
commit
6ae629cfe0
2 changed files with 29 additions and 1 deletions
|
@ -33,7 +33,8 @@ defmodule Pleroma.Workers.ReceiverWorker do
|
|||
query_string: query_string
|
||||
}
|
||||
|
||||
with {:ok, %User{} = _actor} <- User.get_or_fetch_by_ap_id(conn_data.params["actor"]),
|
||||
with {:ok, %User{} = actor} <- User.get_or_fetch_by_ap_id(conn_data.params["actor"]),
|
||||
{:user_active, true} <- {:user_active, match?(true, actor.is_active)},
|
||||
{:ok, _public_key} <- Signature.refetch_public_key(conn_data),
|
||||
{:signature, true} <- {:signature, Signature.validate_signature(conn_data)},
|
||||
{:ok, res} <- Federator.perform(:incoming_ap_doc, params) do
|
||||
|
@ -70,6 +71,7 @@ defmodule Pleroma.Workers.ReceiverWorker do
|
|||
{:error, {:side_effects, {:error, :no_object_actor}} = reason} -> {:cancel, reason}
|
||||
{:error, :not_found} = reason -> {:cancel, reason}
|
||||
{:error, :forbidden} = reason -> {:cancel, reason}
|
||||
{:user_active, false} = reason -> {:cancel, reason}
|
||||
{:error, _} = e -> e
|
||||
e -> {:error, e}
|
||||
end
|
||||
|
|
|
@ -9,6 +9,7 @@ defmodule Pleroma.Workers.ReceiverWorkerTest do
|
|||
import Mock
|
||||
import Pleroma.Factory
|
||||
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.Federator
|
||||
alias Pleroma.Workers.ReceiverWorker
|
||||
|
||||
|
@ -124,6 +125,31 @@ defmodule Pleroma.Workers.ReceiverWorkerTest do
|
|||
|
||||
assert {:cancel, {:error, :not_found}} = ReceiverWorker.perform(oban_job)
|
||||
end
|
||||
|
||||
test "when user account is disabled" do
|
||||
user = insert(:user)
|
||||
|
||||
fake_activity = URI.parse(user.ap_id) |> Map.put(:path, "/fake-activity") |> to_string
|
||||
|
||||
params =
|
||||
insert(:note_activity, user: user).data
|
||||
|> Map.put("id", fake_activity)
|
||||
|
||||
{:ok, %User{}} = User.set_activation(user, false)
|
||||
|
||||
{:ok, oban_job} =
|
||||
ReceiverWorker.new(%{
|
||||
"op" => "incoming_ap_doc",
|
||||
"method" => "POST",
|
||||
"req_headers" => [],
|
||||
"request_path" => "/inbox",
|
||||
"params" => params,
|
||||
"query_string" => ""
|
||||
})
|
||||
|> Oban.insert()
|
||||
|
||||
assert {:cancel, {:user_active, false}} = ReceiverWorker.perform(oban_job)
|
||||
end
|
||||
end
|
||||
|
||||
test "it can validate the signature" do
|
||||
|
|
Loading…
Reference in a new issue