Don't crash when email settings are invalid
[akkoma] / test / pleroma / web / activity_pub / pipeline_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.ActivityPub.PipelineTest do
6 use Pleroma.DataCase, async: true
7
8 import Mox
9 import Pleroma.Factory
10
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
17
18 setup :verify_on_exit!
19
20 describe "common_pipeline/2" do
21 setup do
22 ObjectValidatorMock
23 |> expect(:validate, fn o, m -> {:ok, o, m} end)
24
25 MRFMock
26 |> expect(:pipeline_filter, fn o, m -> {:ok, o, m} end)
27
28 ActivityPubMock
29 |> expect(:persist, fn o, m -> {:ok, o, m} end)
30
31 SideEffectsMock
32 |> expect(:handle, fn o, m -> {:ok, o, m} end)
33 |> expect(:handle_after_transaction, fn m -> m end)
34
35 :ok
36 end
37
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]
42
43 activity_with_object = %{activity | data: Map.put(activity.data, "object", object)}
44
45 FederatorMock
46 |> expect(:publish, fn ^activity_with_object -> :ok end)
47
48 ConfigMock
49 |> expect(:get, fn [:instance, :federating] -> true end)
50
51 assert {:ok, ^activity, ^meta} =
52 Pleroma.Web.ActivityPub.Pipeline.common_pipeline(
53 activity,
54 meta
55 )
56 end
57
58 test "it goes through validation, filtering, persisting, side effects and federation for local activities" do
59 activity = insert(:note_activity)
60 meta = [local: true]
61
62 FederatorMock
63 |> expect(:publish, fn ^activity -> :ok end)
64
65 ConfigMock
66 |> expect(:get, fn [:instance, :federating] -> true end)
67
68 assert {:ok, ^activity, ^meta} =
69 Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity, meta)
70 end
71
72 test "it goes through validation, filtering, persisting, side effects without federation for remote activities" do
73 activity = insert(:note_activity)
74 meta = [local: false]
75
76 ConfigMock
77 |> expect(:get, fn [:instance, :federating] -> true end)
78
79 assert {:ok, ^activity, ^meta} =
80 Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity, meta)
81 end
82
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)
85 meta = [local: true]
86
87 ConfigMock
88 |> expect(:get, fn [:instance, :federating] -> false end)
89
90 assert {:ok, ^activity, ^meta} =
91 Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity, meta)
92 end
93 end
94 end