2019-10-23 03:52:27 -06:00
|
|
|
# Pleroma: A lightweight social networking server
|
2023-01-01 04:11:47 -07:00
|
|
|
# Copyright © 2017-2023 Pleroma Authors <https://pleroma.social/>
|
2019-10-23 03:52:27 -06:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.ActivityPub.PipelineTest do
|
2020-12-16 09:51:48 -07:00
|
|
|
use Pleroma.DataCase, async: true
|
2019-10-23 03:52:27 -06:00
|
|
|
|
2020-12-16 09:51:48 -07:00
|
|
|
import Mox
|
2019-10-23 03:52:27 -06:00
|
|
|
import Pleroma.Factory
|
|
|
|
|
2020-12-16 12:41:35 -07:00
|
|
|
alias Pleroma.ConfigMock
|
2020-12-16 09:51:48 -07:00
|
|
|
alias Pleroma.Web.ActivityPub.ActivityPubMock
|
|
|
|
alias Pleroma.Web.ActivityPub.MRFMock
|
|
|
|
alias Pleroma.Web.ActivityPub.ObjectValidatorMock
|
|
|
|
alias Pleroma.Web.ActivityPub.SideEffectsMock
|
|
|
|
alias Pleroma.Web.FederatorMock
|
|
|
|
|
|
|
|
setup :verify_on_exit!
|
|
|
|
|
2019-10-23 03:52:27 -06:00
|
|
|
describe "common_pipeline/2" do
|
2020-05-20 08:36:55 -06:00
|
|
|
setup do
|
2020-12-16 09:51:48 -07:00
|
|
|
ObjectValidatorMock
|
|
|
|
|> expect(:validate, fn o, m -> {:ok, o, m} end)
|
|
|
|
|
|
|
|
MRFMock
|
|
|
|
|> expect(:pipeline_filter, fn o, m -> {:ok, o, m} end)
|
|
|
|
|
|
|
|
SideEffectsMock
|
|
|
|
|> expect(:handle, fn o, m -> {:ok, o, m} end)
|
|
|
|
|> expect(:handle_after_transaction, fn m -> m end)
|
|
|
|
|
2020-05-20 08:36:55 -06:00
|
|
|
:ok
|
|
|
|
end
|
|
|
|
|
2020-07-27 08:39:50 -06: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 06:06:41 -06:00
|
|
|
activity = insert(:note_activity)
|
|
|
|
object = %{"id" => "1", "type" => "Love"}
|
2020-07-27 08:39:50 -06:00
|
|
|
meta = [local: true, object_data: object]
|
2020-07-24 06:06:41 -06:00
|
|
|
|
|
|
|
activity_with_object = %{activity | data: Map.put(activity.data, "object", object)}
|
|
|
|
|
2021-01-12 06:11:29 -07:00
|
|
|
ActivityPubMock
|
|
|
|
|> expect(:persist, fn _, m -> {:ok, activity, m} end)
|
|
|
|
|
2020-12-16 09:51:48 -07:00
|
|
|
FederatorMock
|
|
|
|
|> expect(:publish, fn ^activity_with_object -> :ok end)
|
|
|
|
|
|
|
|
ConfigMock
|
|
|
|
|> expect(:get, fn [:instance, :federating] -> true end)
|
|
|
|
|
|
|
|
assert {:ok, ^activity, ^meta} =
|
|
|
|
Pleroma.Web.ActivityPub.Pipeline.common_pipeline(
|
2021-01-12 06:11:29 -07:00
|
|
|
activity.data,
|
2020-12-16 09:51:48 -07:00
|
|
|
meta
|
|
|
|
)
|
2020-07-24 06:06:41 -06:00
|
|
|
end
|
|
|
|
|
2019-10-23 03:52:27 -06:00
|
|
|
test "it goes through validation, filtering, persisting, side effects and federation for local activities" do
|
|
|
|
activity = insert(:note_activity)
|
|
|
|
meta = [local: true]
|
|
|
|
|
2021-01-12 06:11:29 -07:00
|
|
|
ActivityPubMock
|
|
|
|
|> expect(:persist, fn _, m -> {:ok, activity, m} end)
|
|
|
|
|
2020-12-16 09:51:48 -07:00
|
|
|
FederatorMock
|
|
|
|
|> expect(:publish, fn ^activity -> :ok end)
|
|
|
|
|
|
|
|
ConfigMock
|
|
|
|
|> expect(:get, fn [:instance, :federating] -> true end)
|
|
|
|
|
|
|
|
assert {:ok, ^activity, ^meta} =
|
2021-01-12 06:11:29 -07:00
|
|
|
Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity.data, meta)
|
2019-10-23 03:52:27 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
test "it goes through validation, filtering, persisting, side effects without federation for remote activities" do
|
|
|
|
activity = insert(:note_activity)
|
|
|
|
meta = [local: false]
|
|
|
|
|
2021-01-12 06:11:29 -07:00
|
|
|
ActivityPubMock
|
|
|
|
|> expect(:persist, fn _, m -> {:ok, activity, m} end)
|
|
|
|
|
2020-12-16 09:51:48 -07:00
|
|
|
ConfigMock
|
|
|
|
|> expect(:get, fn [:instance, :federating] -> true end)
|
|
|
|
|
|
|
|
assert {:ok, ^activity, ^meta} =
|
2021-01-12 06:11:29 -07:00
|
|
|
Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity.data, meta)
|
2020-05-20 08:36:55 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
test "it goes through validation, filtering, persisting, side effects without federation for local activities if federation is deactivated" do
|
|
|
|
activity = insert(:note_activity)
|
|
|
|
meta = [local: true]
|
|
|
|
|
2021-01-12 06:11:29 -07:00
|
|
|
ActivityPubMock
|
|
|
|
|> expect(:persist, fn _, m -> {:ok, activity, m} end)
|
|
|
|
|
2020-12-16 09:51:48 -07:00
|
|
|
ConfigMock
|
|
|
|
|> expect(:get, fn [:instance, :federating] -> false end)
|
|
|
|
|
|
|
|
assert {:ok, ^activity, ^meta} =
|
2021-01-12 06:11:29 -07:00
|
|
|
Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity.data, meta)
|
2019-10-23 03:52:27 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|