2022-08-06 04:31:36 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2023-01-02 20:38:50 +00:00
|
|
|
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
2022-08-06 04:31:36 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Workers.ReceiverWorkerTest do
|
|
|
|
use Pleroma.DataCase, async: true
|
|
|
|
use Oban.Testing, repo: Pleroma.Repo
|
|
|
|
|
|
|
|
import Mock
|
|
|
|
import Pleroma.Factory
|
|
|
|
|
|
|
|
alias Pleroma.Workers.ReceiverWorker
|
|
|
|
|
|
|
|
test "it ignores MRF reject" do
|
|
|
|
params = insert(:note).data
|
|
|
|
|
|
|
|
with_mock Pleroma.Web.ActivityPub.Transmogrifier,
|
|
|
|
handle_incoming: fn _ -> {:reject, "MRF"} end do
|
|
|
|
assert {:cancel, "MRF"} =
|
|
|
|
ReceiverWorker.perform(%Oban.Job{
|
|
|
|
args: %{"op" => "incoming_ap_doc", "params" => params}
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
2023-03-01 05:40:44 +00:00
|
|
|
|
|
|
|
test "it ignores ObjectValidator reject" do
|
|
|
|
params =
|
|
|
|
insert(:note_activity).data
|
|
|
|
|> Map.put("id", Pleroma.Web.ActivityPub.Utils.generate_activity_id())
|
|
|
|
|> Map.put("object", %{
|
|
|
|
"type" => "Note",
|
|
|
|
"id" => Pleroma.Web.ActivityPub.Utils.generate_object_id()
|
|
|
|
})
|
|
|
|
|
|
|
|
with_mock Pleroma.Web.ActivityPub.ObjectValidator, [:passthrough],
|
|
|
|
validate: fn _, _ -> {:error, %Ecto.Changeset{}} end do
|
|
|
|
assert {:cancel, {:error, %Ecto.Changeset{}}} =
|
|
|
|
ReceiverWorker.perform(%Oban.Job{
|
|
|
|
args: %{"op" => "incoming_ap_doc", "params" => params}
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it ignores duplicates" do
|
|
|
|
params = insert(:note_activity).data
|
|
|
|
|
|
|
|
assert {:cancel, :already_present} =
|
|
|
|
ReceiverWorker.perform(%Oban.Job{
|
|
|
|
args: %{"op" => "incoming_ap_doc", "params" => params}
|
|
|
|
})
|
|
|
|
end
|
2022-08-06 04:31:36 +00:00
|
|
|
end
|