Transmogrifier: Don't fetch actor that's guaranteed to be there.

This commit is contained in:
lain 2020-05-03 12:51:28 +02:00
parent f20a1a27ef
commit 4dfc617cdf
2 changed files with 7 additions and 26 deletions

View File

@ -733,8 +733,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
%{"type" => "Delete"} = data, %{"type" => "Delete"} = data,
_options _options
) do ) do
with {:ok, %User{}} <- ObjectValidator.fetch_actor(data), with {:ok, activity, _} <- Pipeline.common_pipeline(data, local: false) do
{:ok, activity, _} <- Pipeline.common_pipeline(data, local: false) do
{:ok, activity} {:ok, activity}
end end
end end

View File

@ -13,7 +13,6 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.DeleteHandlingTest do
alias Pleroma.Web.ActivityPub.Transmogrifier alias Pleroma.Web.ActivityPub.Transmogrifier
import Pleroma.Factory import Pleroma.Factory
import ExUnit.CaptureLog
setup_all do setup_all do
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end) Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
@ -27,22 +26,15 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.DeleteHandlingTest do
data = data =
File.read!("test/fixtures/mastodon-delete.json") File.read!("test/fixtures/mastodon-delete.json")
|> Poison.decode!() |> Poison.decode!()
object =
data["object"]
|> Map.put("id", activity.data["object"])
data =
data
|> Map.put("object", object)
|> Map.put("actor", deleting_user.ap_id) |> Map.put("actor", deleting_user.ap_id)
|> put_in(["object", "id"], activity.data["object"])
{:ok, %Activity{actor: actor, local: false, data: %{"id" => id}}} = {:ok, %Activity{actor: actor, local: false, data: %{"id" => id}}} =
Transmogrifier.handle_incoming(data) Transmogrifier.handle_incoming(data)
assert id == data["id"] assert id == data["id"]
# We delete the Create activity because base our timelines on it. # We delete the Create activity because we base our timelines on it.
# This should be changed after we unify objects and activities # This should be changed after we unify objects and activities
refute Activity.get_by_id(activity.id) refute Activity.get_by_id(activity.id)
assert actor == deleting_user.ap_id assert actor == deleting_user.ap_id
@ -54,25 +46,15 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.DeleteHandlingTest do
test "it fails for incoming deletes with spoofed origin" do test "it fails for incoming deletes with spoofed origin" do
activity = insert(:note_activity) activity = insert(:note_activity)
%{ap_id: ap_id} = insert(:user, ap_id: "https://gensokyo.2hu/users/raymoo")
data = data =
File.read!("test/fixtures/mastodon-delete.json") File.read!("test/fixtures/mastodon-delete.json")
|> Poison.decode!() |> Poison.decode!()
|> Map.put("actor", ap_id)
|> put_in(["object", "id"], activity.data["object"])
object = assert match?({:error, _}, Transmogrifier.handle_incoming(data))
data["object"]
|> Map.put("id", activity.data["object"])
data =
data
|> Map.put("object", object)
assert capture_log(fn ->
{:error, _} = Transmogrifier.handle_incoming(data)
end) =~
"[error] Could not decode user at fetch http://mastodon.example.org/users/gargron, {:error, :nxdomain}"
assert Activity.get_by_id(activity.id)
end end
@tag capture_log: true @tag capture_log: true