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(:handle, fn o, m -> {:ok, o, m} end)
30 |> expect(:handle_after_transaction, fn m -> m end)
35 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
36 activity = insert(:note_activity)
37 object = %{"id" => "1", "type" => "Love"}
38 meta = [local: true, object_data: object]
40 activity_with_object = %{activity | data: Map.put(activity.data, "object", object)}
43 |> expect(:persist, fn _, m -> {:ok, activity, m} end)
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(:persist, fn _, m -> {:ok, activity, m} end)
66 |> expect(:publish, fn ^activity -> :ok end)
69 |> expect(:get, fn [:instance, :federating] -> true end)
71 assert {:ok, ^activity, ^meta} =
72 Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity.data, meta)
75 test "it goes through validation, filtering, persisting, side effects without federation for remote activities" do
76 activity = insert(:note_activity)
80 |> expect(:persist, fn _, m -> {:ok, activity, m} end)
83 |> expect(:get, fn [:instance, :federating] -> true end)
85 assert {:ok, ^activity, ^meta} =
86 Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity.data, meta)
89 test "it goes through validation, filtering, persisting, side effects without federation for local activities if federation is deactivated" do
90 activity = insert(:note_activity)
94 |> expect(:persist, fn _, m -> {:ok, activity, m} end)
97 |> expect(:get, fn [:instance, :federating] -> false end)
99 assert {:ok, ^activity, ^meta} =
100 Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity.data, meta)