1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ActivityPub.PipelineTest do
11 describe "common_pipeline/2" do
13 clear_config([:instance, :federating], true)
17 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
18 activity = insert(:note_activity)
19 object = %{"id" => "1", "type" => "Love"}
20 meta = [local: true, object_data: object]
22 activity_with_object = %{activity | data: Map.put(activity.data, "object", object)}
25 {Pleroma.Web.ActivityPub.ObjectValidator, [], [validate: fn o, m -> {:ok, o, m} end]},
27 Pleroma.Web.ActivityPub.MRF,
29 [filter: fn o -> {:ok, o} end]
32 Pleroma.Web.ActivityPub.ActivityPub,
34 [persist: fn o, m -> {:ok, o, m} end]
37 Pleroma.Web.ActivityPub.SideEffects,
40 handle: fn o, m -> {:ok, o, m} end,
41 handle_after_transaction: fn m -> m end
45 Pleroma.Web.Federator,
47 [publish: fn _o -> :ok end]
50 assert {:ok, ^activity, ^meta} =
51 Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity, meta)
53 assert_called(Pleroma.Web.ActivityPub.ObjectValidator.validate(activity, meta))
54 assert_called(Pleroma.Web.ActivityPub.MRF.filter(activity))
55 assert_called(Pleroma.Web.ActivityPub.ActivityPub.persist(activity, meta))
56 assert_called(Pleroma.Web.ActivityPub.SideEffects.handle(activity, meta))
57 refute called(Pleroma.Web.Federator.publish(activity))
58 assert_called(Pleroma.Web.Federator.publish(activity_with_object))
62 test "it goes through validation, filtering, persisting, side effects and federation for local activities" do
63 activity = insert(:note_activity)
67 {Pleroma.Web.ActivityPub.ObjectValidator, [], [validate: fn o, m -> {:ok, o, m} end]},
69 Pleroma.Web.ActivityPub.MRF,
71 [filter: fn o -> {:ok, o} end]
74 Pleroma.Web.ActivityPub.ActivityPub,
76 [persist: fn o, m -> {:ok, o, m} end]
79 Pleroma.Web.ActivityPub.SideEffects,
82 handle: fn o, m -> {:ok, o, m} end,
83 handle_after_transaction: fn m -> m end
87 Pleroma.Web.Federator,
89 [publish: fn _o -> :ok end]
92 assert {:ok, ^activity, ^meta} =
93 Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity, meta)
95 assert_called(Pleroma.Web.ActivityPub.ObjectValidator.validate(activity, meta))
96 assert_called(Pleroma.Web.ActivityPub.MRF.filter(activity))
97 assert_called(Pleroma.Web.ActivityPub.ActivityPub.persist(activity, meta))
98 assert_called(Pleroma.Web.ActivityPub.SideEffects.handle(activity, meta))
99 assert_called(Pleroma.Web.Federator.publish(activity))
103 test "it goes through validation, filtering, persisting, side effects without federation for remote activities" do
104 activity = insert(:note_activity)
105 meta = [local: false]
108 {Pleroma.Web.ActivityPub.ObjectValidator, [], [validate: fn o, m -> {:ok, o, m} end]},
110 Pleroma.Web.ActivityPub.MRF,
112 [filter: fn o -> {:ok, o} end]
115 Pleroma.Web.ActivityPub.ActivityPub,
117 [persist: fn o, m -> {:ok, o, m} end]
120 Pleroma.Web.ActivityPub.SideEffects,
122 [handle: fn o, m -> {:ok, o, m} end, handle_after_transaction: fn m -> m end]
125 Pleroma.Web.Federator,
130 assert {:ok, ^activity, ^meta} =
131 Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity, meta)
133 assert_called(Pleroma.Web.ActivityPub.ObjectValidator.validate(activity, meta))
134 assert_called(Pleroma.Web.ActivityPub.MRF.filter(activity))
135 assert_called(Pleroma.Web.ActivityPub.ActivityPub.persist(activity, meta))
136 assert_called(Pleroma.Web.ActivityPub.SideEffects.handle(activity, meta))
140 test "it goes through validation, filtering, persisting, side effects without federation for local activities if federation is deactivated" do
141 clear_config([:instance, :federating], false)
143 activity = insert(:note_activity)
147 {Pleroma.Web.ActivityPub.ObjectValidator, [], [validate: fn o, m -> {:ok, o, m} end]},
149 Pleroma.Web.ActivityPub.MRF,
151 [filter: fn o -> {:ok, o} end]
154 Pleroma.Web.ActivityPub.ActivityPub,
156 [persist: fn o, m -> {:ok, o, m} end]
159 Pleroma.Web.ActivityPub.SideEffects,
161 [handle: fn o, m -> {:ok, o, m} end, handle_after_transaction: fn m -> m end]
164 Pleroma.Web.Federator,
169 assert {:ok, ^activity, ^meta} =
170 Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity, meta)
172 assert_called(Pleroma.Web.ActivityPub.ObjectValidator.validate(activity, meta))
173 assert_called(Pleroma.Web.ActivityPub.MRF.filter(activity))
174 assert_called(Pleroma.Web.ActivityPub.ActivityPub.persist(activity, meta))
175 assert_called(Pleroma.Web.ActivityPub.SideEffects.handle(activity, meta))