1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ActivityPub.PipelineTest do
6 use Pleroma.DataCase, async: true
11 alias Pleroma.ConfigMock
12 alias Pleroma.Web.ActivityPub.ActivityPubMock
13 alias Pleroma.Web.ActivityPub.MRFMock
14 alias Pleroma.Web.ActivityPub.ObjectValidatorMock
15 alias Pleroma.Web.ActivityPub.SideEffectsMock
16 alias Pleroma.Web.FederatorMock
18 setup :verify_on_exit!
20 describe "common_pipeline/2" do
23 |> expect(:validate, fn o, m -> {:ok, o, m} end)
26 |> expect(:pipeline_filter, fn o, m -> {:ok, o, m} end)
29 |> expect(:persist, fn o, m -> {:ok, o, m} end)
32 |> expect(:handle, fn o, m -> {:ok, o, m} end)
33 |> expect(:handle_after_transaction, fn m -> m end)
38 test "when given an `object_data` in meta, Federation will receive a the original activity with the `object` field set to this embedded object" do
39 activity = insert(:note_activity)
40 object = %{"id" => "1", "type" => "Love"}
41 meta = [local: true, object_data: object]
43 activity_with_object = %{activity | data: Map.put(activity.data, "object", object)}
46 |> expect(:publish, fn ^activity_with_object -> :ok end)
49 |> expect(:get, fn [:instance, :federating] -> true end)
51 assert {:ok, ^activity, ^meta} =
52 Pleroma.Web.ActivityPub.Pipeline.common_pipeline(
58 test "it goes through validation, filtering, persisting, side effects and federation for local activities" do
59 activity = insert(:note_activity)
63 |> expect(:publish, fn ^activity -> :ok end)
66 |> expect(:get, fn [:instance, :federating] -> true end)
68 assert {:ok, ^activity, ^meta} =
69 Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity, meta)
72 test "it goes through validation, filtering, persisting, side effects without federation for remote activities" do
73 activity = insert(:note_activity)
77 |> expect(:get, fn [:instance, :federating] -> true end)
79 assert {:ok, ^activity, ^meta} =
80 Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity, meta)
83 test "it goes through validation, filtering, persisting, side effects without federation for local activities if federation is deactivated" do
84 activity = insert(:note_activity)
88 |> expect(:get, fn [:instance, :federating] -> false end)
90 assert {:ok, ^activity, ^meta} =
91 Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity, meta)