2019-10-23 05:52:27 -04:00
|
|
|
# Pleroma: A lightweight social networking server
|
2020-03-26 10:37:42 -04:00
|
|
|
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
2019-10-23 05:52:27 -04:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.ActivityPub.PipelineTest do
|
|
|
|
use Pleroma.DataCase
|
|
|
|
|
|
|
|
import Mock
|
|
|
|
import Pleroma.Factory
|
|
|
|
|
|
|
|
describe "common_pipeline/2" do
|
2020-05-20 10:36:55 -04:00
|
|
|
setup do
|
|
|
|
clear_config([:instance, :federating], true)
|
|
|
|
:ok
|
|
|
|
end
|
|
|
|
|
2020-07-27 10:39:50 -04:00
|
|
|
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
|
2020-07-24 08:06:41 -04:00
|
|
|
activity = insert(:note_activity)
|
|
|
|
object = %{"id" => "1", "type" => "Love"}
|
2020-07-27 10:39:50 -04:00
|
|
|
meta = [local: true, object_data: object]
|
2020-07-24 08:06:41 -04:00
|
|
|
|
|
|
|
activity_with_object = %{activity | data: Map.put(activity.data, "object", object)}
|
|
|
|
|
|
|
|
with_mocks([
|
|
|
|
{Pleroma.Web.ActivityPub.ObjectValidator, [], [validate: fn o, m -> {:ok, o, m} end]},
|
|
|
|
{
|
|
|
|
Pleroma.Web.ActivityPub.MRF,
|
|
|
|
[],
|
2020-09-17 08:13:36 -04:00
|
|
|
[pipeline_filter: fn o, m -> {:ok, o, m} end]
|
2020-07-24 08:06:41 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Pleroma.Web.ActivityPub.ActivityPub,
|
|
|
|
[],
|
|
|
|
[persist: fn o, m -> {:ok, o, m} end]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Pleroma.Web.ActivityPub.SideEffects,
|
|
|
|
[],
|
|
|
|
[
|
|
|
|
handle: fn o, m -> {:ok, o, m} end,
|
|
|
|
handle_after_transaction: fn m -> m end
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Pleroma.Web.Federator,
|
|
|
|
[],
|
|
|
|
[publish: fn _o -> :ok end]
|
|
|
|
}
|
|
|
|
]) do
|
|
|
|
assert {:ok, ^activity, ^meta} =
|
|
|
|
Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity, meta)
|
|
|
|
|
|
|
|
assert_called(Pleroma.Web.ActivityPub.ObjectValidator.validate(activity, meta))
|
2020-09-17 08:13:36 -04:00
|
|
|
assert_called(Pleroma.Web.ActivityPub.MRF.pipeline_filter(activity, meta))
|
2020-07-24 08:06:41 -04:00
|
|
|
assert_called(Pleroma.Web.ActivityPub.ActivityPub.persist(activity, meta))
|
|
|
|
assert_called(Pleroma.Web.ActivityPub.SideEffects.handle(activity, meta))
|
|
|
|
refute called(Pleroma.Web.Federator.publish(activity))
|
|
|
|
assert_called(Pleroma.Web.Federator.publish(activity_with_object))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-10-23 05:52:27 -04:00
|
|
|
test "it goes through validation, filtering, persisting, side effects and federation for local activities" do
|
|
|
|
activity = insert(:note_activity)
|
|
|
|
meta = [local: true]
|
|
|
|
|
|
|
|
with_mocks([
|
|
|
|
{Pleroma.Web.ActivityPub.ObjectValidator, [], [validate: fn o, m -> {:ok, o, m} end]},
|
|
|
|
{
|
|
|
|
Pleroma.Web.ActivityPub.MRF,
|
|
|
|
[],
|
2020-09-17 08:13:36 -04:00
|
|
|
[pipeline_filter: fn o, m -> {:ok, o, m} end]
|
2019-10-23 05:52:27 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Pleroma.Web.ActivityPub.ActivityPub,
|
|
|
|
[],
|
|
|
|
[persist: fn o, m -> {:ok, o, m} end]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Pleroma.Web.ActivityPub.SideEffects,
|
|
|
|
[],
|
2020-06-05 10:47:02 -04:00
|
|
|
[
|
|
|
|
handle: fn o, m -> {:ok, o, m} end,
|
|
|
|
handle_after_transaction: fn m -> m end
|
|
|
|
]
|
2019-10-23 05:52:27 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Pleroma.Web.Federator,
|
|
|
|
[],
|
|
|
|
[publish: fn _o -> :ok end]
|
|
|
|
}
|
|
|
|
]) do
|
|
|
|
assert {:ok, ^activity, ^meta} =
|
|
|
|
Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity, meta)
|
|
|
|
|
|
|
|
assert_called(Pleroma.Web.ActivityPub.ObjectValidator.validate(activity, meta))
|
2020-09-17 08:13:36 -04:00
|
|
|
assert_called(Pleroma.Web.ActivityPub.MRF.pipeline_filter(activity, meta))
|
2019-10-23 05:52:27 -04:00
|
|
|
assert_called(Pleroma.Web.ActivityPub.ActivityPub.persist(activity, meta))
|
|
|
|
assert_called(Pleroma.Web.ActivityPub.SideEffects.handle(activity, meta))
|
|
|
|
assert_called(Pleroma.Web.Federator.publish(activity))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it goes through validation, filtering, persisting, side effects without federation for remote activities" do
|
|
|
|
activity = insert(:note_activity)
|
|
|
|
meta = [local: false]
|
|
|
|
|
|
|
|
with_mocks([
|
|
|
|
{Pleroma.Web.ActivityPub.ObjectValidator, [], [validate: fn o, m -> {:ok, o, m} end]},
|
2020-05-20 10:36:55 -04:00
|
|
|
{
|
|
|
|
Pleroma.Web.ActivityPub.MRF,
|
|
|
|
[],
|
2020-09-17 08:13:36 -04:00
|
|
|
[pipeline_filter: fn o, m -> {:ok, o, m} end]
|
2020-05-20 10:36:55 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Pleroma.Web.ActivityPub.ActivityPub,
|
|
|
|
[],
|
|
|
|
[persist: fn o, m -> {:ok, o, m} end]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Pleroma.Web.ActivityPub.SideEffects,
|
|
|
|
[],
|
2020-06-05 10:47:02 -04:00
|
|
|
[handle: fn o, m -> {:ok, o, m} end, handle_after_transaction: fn m -> m end]
|
2020-05-20 10:36:55 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Pleroma.Web.Federator,
|
|
|
|
[],
|
|
|
|
[]
|
|
|
|
}
|
|
|
|
]) do
|
|
|
|
assert {:ok, ^activity, ^meta} =
|
|
|
|
Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity, meta)
|
|
|
|
|
|
|
|
assert_called(Pleroma.Web.ActivityPub.ObjectValidator.validate(activity, meta))
|
2020-09-17 08:13:36 -04:00
|
|
|
assert_called(Pleroma.Web.ActivityPub.MRF.pipeline_filter(activity, meta))
|
2020-05-20 10:36:55 -04:00
|
|
|
assert_called(Pleroma.Web.ActivityPub.ActivityPub.persist(activity, meta))
|
|
|
|
assert_called(Pleroma.Web.ActivityPub.SideEffects.handle(activity, meta))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it goes through validation, filtering, persisting, side effects without federation for local activities if federation is deactivated" do
|
|
|
|
clear_config([:instance, :federating], false)
|
|
|
|
|
|
|
|
activity = insert(:note_activity)
|
|
|
|
meta = [local: true]
|
|
|
|
|
|
|
|
with_mocks([
|
|
|
|
{Pleroma.Web.ActivityPub.ObjectValidator, [], [validate: fn o, m -> {:ok, o, m} end]},
|
2019-10-23 05:52:27 -04:00
|
|
|
{
|
|
|
|
Pleroma.Web.ActivityPub.MRF,
|
|
|
|
[],
|
2020-09-17 08:13:36 -04:00
|
|
|
[pipeline_filter: fn o, m -> {:ok, o, m} end]
|
2019-10-23 05:52:27 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Pleroma.Web.ActivityPub.ActivityPub,
|
|
|
|
[],
|
|
|
|
[persist: fn o, m -> {:ok, o, m} end]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Pleroma.Web.ActivityPub.SideEffects,
|
|
|
|
[],
|
2020-06-05 10:47:02 -04:00
|
|
|
[handle: fn o, m -> {:ok, o, m} end, handle_after_transaction: fn m -> m end]
|
2019-10-23 05:52:27 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Pleroma.Web.Federator,
|
|
|
|
[],
|
|
|
|
[]
|
|
|
|
}
|
|
|
|
]) do
|
|
|
|
assert {:ok, ^activity, ^meta} =
|
|
|
|
Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity, meta)
|
|
|
|
|
|
|
|
assert_called(Pleroma.Web.ActivityPub.ObjectValidator.validate(activity, meta))
|
2020-09-17 08:13:36 -04:00
|
|
|
assert_called(Pleroma.Web.ActivityPub.MRF.pipeline_filter(activity, meta))
|
2019-10-23 05:52:27 -04:00
|
|
|
assert_called(Pleroma.Web.ActivityPub.ActivityPub.persist(activity, meta))
|
|
|
|
assert_called(Pleroma.Web.ActivityPub.SideEffects.handle(activity, meta))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|