pipeline_test: Fix usage of %Activity{}

This commit is contained in:
Haelwenn (lanodan) Monnier 2021-01-12 14:11:29 +01:00
parent 9015df2229
commit 5ae27c8451
No known key found for this signature in database
GPG key ID: D5B7A8E43C997DEE
3 changed files with 19 additions and 8 deletions

View file

@ -169,7 +169,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidator do
def cast_and_apply(o), do: {:error, {:validator_not_set, o}} def cast_and_apply(o), do: {:error, {:validator_not_set, o}}
# is_struct/1 isn't present in Elixir 1.8.x # is_struct/1 appears in Elixir 1.11
def stringify_keys(%{__struct__: _} = object) do def stringify_keys(%{__struct__: _} = object) do
object object
|> Map.from_struct() |> Map.from_struct()

View file

@ -40,6 +40,8 @@ defmodule Pleroma.Web.ActivityPub.Pipeline do
end end
end end
def do_common_pipeline(%{__struct__: _}, _meta), do: {:error, :is_struct}
def do_common_pipeline(object, meta) do def do_common_pipeline(object, meta) do
with {_, {:ok, validated_object, meta}} <- with {_, {:ok, validated_object, meta}} <-
{:validate_object, @object_validator.validate(object, meta)}, {:validate_object, @object_validator.validate(object, meta)},

View file

@ -25,9 +25,6 @@ defmodule Pleroma.Web.ActivityPub.PipelineTest do
MRFMock MRFMock
|> expect(:pipeline_filter, fn o, m -> {:ok, o, m} end) |> expect(:pipeline_filter, fn o, m -> {:ok, o, m} end)
ActivityPubMock
|> expect(:persist, fn o, m -> {:ok, o, m} end)
SideEffectsMock SideEffectsMock
|> expect(:handle, fn o, m -> {:ok, o, m} end) |> expect(:handle, fn o, m -> {:ok, o, m} end)
|> expect(:handle_after_transaction, fn m -> m end) |> expect(:handle_after_transaction, fn m -> m end)
@ -42,6 +39,9 @@ defmodule Pleroma.Web.ActivityPub.PipelineTest do
activity_with_object = %{activity | data: Map.put(activity.data, "object", object)} activity_with_object = %{activity | data: Map.put(activity.data, "object", object)}
ActivityPubMock
|> expect(:persist, fn _, m -> {:ok, activity, m} end)
FederatorMock FederatorMock
|> expect(:publish, fn ^activity_with_object -> :ok end) |> expect(:publish, fn ^activity_with_object -> :ok end)
@ -50,7 +50,7 @@ defmodule Pleroma.Web.ActivityPub.PipelineTest do
assert {:ok, ^activity, ^meta} = assert {:ok, ^activity, ^meta} =
Pleroma.Web.ActivityPub.Pipeline.common_pipeline( Pleroma.Web.ActivityPub.Pipeline.common_pipeline(
activity, activity.data,
meta meta
) )
end end
@ -59,6 +59,9 @@ defmodule Pleroma.Web.ActivityPub.PipelineTest do
activity = insert(:note_activity) activity = insert(:note_activity)
meta = [local: true] meta = [local: true]
ActivityPubMock
|> expect(:persist, fn _, m -> {:ok, activity, m} end)
FederatorMock FederatorMock
|> expect(:publish, fn ^activity -> :ok end) |> expect(:publish, fn ^activity -> :ok end)
@ -66,29 +69,35 @@ defmodule Pleroma.Web.ActivityPub.PipelineTest do
|> expect(:get, fn [:instance, :federating] -> true end) |> expect(:get, fn [:instance, :federating] -> true end)
assert {:ok, ^activity, ^meta} = assert {:ok, ^activity, ^meta} =
Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity, meta) Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity.data, meta)
end end
test "it goes through validation, filtering, persisting, side effects without federation for remote activities" do test "it goes through validation, filtering, persisting, side effects without federation for remote activities" do
activity = insert(:note_activity) activity = insert(:note_activity)
meta = [local: false] meta = [local: false]
ActivityPubMock
|> expect(:persist, fn _, m -> {:ok, activity, m} end)
ConfigMock ConfigMock
|> expect(:get, fn [:instance, :federating] -> true end) |> expect(:get, fn [:instance, :federating] -> true end)
assert {:ok, ^activity, ^meta} = assert {:ok, ^activity, ^meta} =
Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity, meta) Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity.data, meta)
end end
test "it goes through validation, filtering, persisting, side effects without federation for local activities if federation is deactivated" do test "it goes through validation, filtering, persisting, side effects without federation for local activities if federation is deactivated" do
activity = insert(:note_activity) activity = insert(:note_activity)
meta = [local: true] meta = [local: true]
ActivityPubMock
|> expect(:persist, fn _, m -> {:ok, activity, m} end)
ConfigMock ConfigMock
|> expect(:get, fn [:instance, :federating] -> false end) |> expect(:get, fn [:instance, :federating] -> false end)
assert {:ok, ^activity, ^meta} = assert {:ok, ^activity, ^meta} =
Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity, meta) Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity.data, meta)
end end
end end
end end