Compare commits
5 Commits
feature/sa
...
test-speed
Author | SHA1 | Date | |
---|---|---|---|
|
a951f219bc | ||
|
d5a824b463 | ||
|
74596982be | ||
|
8e6a59384e | ||
|
3dd5e11724 |
@ -121,6 +121,14 @@ config :tzdata, :autoupdate, :disabled
|
||||
|
||||
config :pleroma, :mrf, policies: []
|
||||
|
||||
config :pleroma, :pipeline,
|
||||
object_validator: Pleroma.Web.ActivityPub.ObjectValidatorMock,
|
||||
mrf: Pleroma.Web.ActivityPub.MRFMock,
|
||||
activity_pub: Pleroma.Web.ActivityPub.ActivityPubMock,
|
||||
side_effects: Pleroma.Web.ActivityPub.SideEffectsMock,
|
||||
federator: Pleroma.Web.FederatorMock,
|
||||
config: Pleroma.ConfigMock
|
||||
|
||||
if File.exists?("./config/test.secret.exs") do
|
||||
import_config "test.secret.exs"
|
||||
else
|
||||
|
@ -3,14 +3,18 @@
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Config do
|
||||
@behaviour Pleroma.Config.Getting
|
||||
defmodule Error do
|
||||
defexception [:message]
|
||||
end
|
||||
|
||||
@impl true
|
||||
def get(key), do: get(key, nil)
|
||||
|
||||
@impl true
|
||||
def get([key], default), do: get(key, default)
|
||||
|
||||
@impl true
|
||||
def get([_ | _] = path, default) do
|
||||
case fetch(path) do
|
||||
{:ok, value} -> value
|
||||
@ -18,6 +22,7 @@ defmodule Pleroma.Config do
|
||||
end
|
||||
end
|
||||
|
||||
@impl true
|
||||
def get(key, default) do
|
||||
Application.get_env(:pleroma, key, default)
|
||||
end
|
||||
|
8
lib/pleroma/config/getting.ex
Normal file
8
lib/pleroma/config/getting.ex
Normal file
@ -0,0 +1,8 @@
|
||||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Config.Getting do
|
||||
@callback get(any()) :: any()
|
||||
@callback get(any(), any()) :: any()
|
||||
end
|
@ -32,6 +32,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
||||
require Logger
|
||||
require Pleroma.Constants
|
||||
|
||||
@behaviour Pleroma.Web.ActivityPub.ActivityPub.Persisting
|
||||
|
||||
defp get_recipients(%{"type" => "Create"} = data) do
|
||||
to = Map.get(data, "to", [])
|
||||
cc = Map.get(data, "cc", [])
|
||||
@ -85,13 +87,14 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
||||
defp increase_replies_count_if_reply(_create_data), do: :noop
|
||||
|
||||
@object_types ~w[ChatMessage Question Answer Audio Video Event Article]
|
||||
@spec persist(map(), keyword()) :: {:ok, Activity.t() | Object.t()}
|
||||
@impl true
|
||||
def persist(%{"type" => type} = object, meta) when type in @object_types do
|
||||
with {:ok, object} <- Object.create(object) do
|
||||
{:ok, object, meta}
|
||||
end
|
||||
end
|
||||
|
||||
@impl true
|
||||
def persist(object, meta) do
|
||||
with local <- Keyword.fetch!(meta, :local),
|
||||
{recipients, _, _} <- get_recipients(object),
|
||||
|
7
lib/pleroma/web/activity_pub/activity_pub/persisting.ex
Normal file
7
lib/pleroma/web/activity_pub/activity_pub/persisting.ex
Normal file
@ -0,0 +1,7 @@
|
||||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.ActivityPub.Persisting do
|
||||
@callback persist(map(), keyword()) :: {:ok, Activity.t() | Object.t()}
|
||||
end
|
@ -5,6 +5,8 @@
|
||||
defmodule Pleroma.Web.ActivityPub.MRF do
|
||||
require Logger
|
||||
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.PipelineFiltering
|
||||
|
||||
@mrf_config_descriptions [
|
||||
%{
|
||||
group: :pleroma,
|
||||
@ -70,6 +72,7 @@ defmodule Pleroma.Web.ActivityPub.MRF do
|
||||
|
||||
def filter(%{} = object), do: get_policies() |> filter(object)
|
||||
|
||||
@impl true
|
||||
def pipeline_filter(%{} = message, meta) do
|
||||
object = meta[:object_data]
|
||||
ap_id = message["object"]
|
||||
|
7
lib/pleroma/web/activity_pub/mrf/pipeline_filtering.ex
Normal file
7
lib/pleroma/web/activity_pub/mrf/pipeline_filtering.ex
Normal file
@ -0,0 +1,7 @@
|
||||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.MRF.PipelineFiltering do
|
||||
@callback pipeline_filter(map(), keyword()) :: {:ok, map(), keyword()} | {:error, any()}
|
||||
end
|
@ -9,6 +9,8 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidator do
|
||||
the system.
|
||||
"""
|
||||
|
||||
@behaviour Pleroma.Web.ActivityPub.ObjectValidator.Validating
|
||||
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.EctoType.ActivityPub.ObjectValidators
|
||||
alias Pleroma.Object
|
||||
@ -32,7 +34,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidator do
|
||||
alias Pleroma.Web.ActivityPub.ObjectValidators.UndoValidator
|
||||
alias Pleroma.Web.ActivityPub.ObjectValidators.UpdateValidator
|
||||
|
||||
@spec validate(map(), keyword()) :: {:ok, map(), keyword()} | {:error, any()}
|
||||
@impl true
|
||||
def validate(object, meta)
|
||||
|
||||
def validate(%{"type" => type} = object, meta)
|
||||
|
@ -0,0 +1,7 @@
|
||||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.ObjectValidator.Validating do
|
||||
@callback validate(map(), keyword()) :: {:ok, map(), keyword()} | {:error, any()}
|
||||
end
|
@ -14,12 +14,19 @@ defmodule Pleroma.Web.ActivityPub.Pipeline do
|
||||
alias Pleroma.Web.ActivityPub.Visibility
|
||||
alias Pleroma.Web.Federator
|
||||
|
||||
@side_effects Config.get([:pipeline, :side_effects], SideEffects)
|
||||
@federator Config.get([:pipeline, :federator], Federator)
|
||||
@object_validator Config.get([:pipeline, :object_validator], ObjectValidator)
|
||||
@mrf Config.get([:pipeline, :mrf], MRF)
|
||||
@activity_pub Config.get([:pipeline, :activity_pub], ActivityPub)
|
||||
@config Config.get([:pipeline, :config], Config)
|
||||
|
||||
@spec common_pipeline(map(), keyword()) ::
|
||||
{:ok, Activity.t() | Object.t(), keyword()} | {:error, any()}
|
||||
def common_pipeline(object, meta) do
|
||||
case Repo.transaction(fn -> do_common_pipeline(object, meta) end) do
|
||||
{:ok, {:ok, activity, meta}} ->
|
||||
SideEffects.handle_after_transaction(meta)
|
||||
@side_effects.handle_after_transaction(meta)
|
||||
{:ok, activity, meta}
|
||||
|
||||
{:ok, value} ->
|
||||
@ -35,13 +42,13 @@ defmodule Pleroma.Web.ActivityPub.Pipeline do
|
||||
|
||||
def do_common_pipeline(object, meta) do
|
||||
with {_, {:ok, validated_object, meta}} <-
|
||||
{:validate_object, ObjectValidator.validate(object, meta)},
|
||||
{:validate_object, @object_validator.validate(object, meta)},
|
||||
{_, {:ok, mrfd_object, meta}} <-
|
||||
{:mrf_object, MRF.pipeline_filter(validated_object, meta)},
|
||||
{:mrf_object, @mrf.pipeline_filter(validated_object, meta)},
|
||||
{_, {:ok, activity, meta}} <-
|
||||
{:persist_object, ActivityPub.persist(mrfd_object, meta)},
|
||||
{:persist_object, @activity_pub.persist(mrfd_object, meta)},
|
||||
{_, {:ok, activity, meta}} <-
|
||||
{:execute_side_effects, SideEffects.handle(activity, meta)},
|
||||
{:execute_side_effects, @side_effects.handle(activity, meta)},
|
||||
{_, {:ok, _}} <- {:federation, maybe_federate(activity, meta)} do
|
||||
{:ok, activity, meta}
|
||||
else
|
||||
@ -54,7 +61,7 @@ defmodule Pleroma.Web.ActivityPub.Pipeline do
|
||||
|
||||
defp maybe_federate(%Activity{} = activity, meta) do
|
||||
with {:ok, local} <- Keyword.fetch(meta, :local) do
|
||||
do_not_federate = meta[:do_not_federate] || !Config.get([:instance, :federating])
|
||||
do_not_federate = meta[:do_not_federate] || !@config.get([:instance, :federating])
|
||||
|
||||
if !do_not_federate and local and not Visibility.is_local_public?(activity) do
|
||||
activity =
|
||||
@ -64,7 +71,7 @@ defmodule Pleroma.Web.ActivityPub.Pipeline do
|
||||
activity
|
||||
end
|
||||
|
||||
Federator.publish(activity)
|
||||
@federator.publish(activity)
|
||||
{:ok, :federated}
|
||||
else
|
||||
{:ok, :not_federated}
|
||||
|
@ -27,11 +27,15 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
|
||||
|
||||
require Logger
|
||||
|
||||
@behaviour Pleroma.Web.ActivityPub.SideEffects.Handling
|
||||
|
||||
@impl true
|
||||
def handle(object, meta \\ [])
|
||||
|
||||
# Task this handles
|
||||
# - Follows
|
||||
# - Sends a notification
|
||||
@impl true
|
||||
def handle(
|
||||
%{
|
||||
data: %{
|
||||
@ -59,6 +63,7 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
|
||||
# - Rejects all existing follow activities for this person
|
||||
# - Updates the follow state
|
||||
# - Dismisses notification
|
||||
@impl true
|
||||
def handle(
|
||||
%{
|
||||
data: %{
|
||||
@ -85,6 +90,7 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
|
||||
# - Follows if possible
|
||||
# - Sends a notification
|
||||
# - Generates accept or reject if appropriate
|
||||
@impl true
|
||||
def handle(
|
||||
%{
|
||||
data: %{
|
||||
@ -126,6 +132,7 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
|
||||
|
||||
# Tasks this handles:
|
||||
# - Unfollow and block
|
||||
@impl true
|
||||
def handle(
|
||||
%{data: %{"type" => "Block", "object" => blocked_user, "actor" => blocking_user}} =
|
||||
object,
|
||||
@ -144,6 +151,7 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
|
||||
#
|
||||
# For a local user, we also get a changeset with the full information, so we
|
||||
# can update non-federating, non-activitypub settings as well.
|
||||
@impl true
|
||||
def handle(%{data: %{"type" => "Update", "object" => updated_object}} = object, meta) do
|
||||
if changeset = Keyword.get(meta, :user_update_changeset) do
|
||||
changeset
|
||||
@ -162,6 +170,7 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
|
||||
# Tasks this handles:
|
||||
# - Add like to object
|
||||
# - Set up notification
|
||||
@impl true
|
||||
def handle(%{data: %{"type" => "Like"}} = object, meta) do
|
||||
liked_object = Object.get_by_ap_id(object.data["object"])
|
||||
Utils.add_like_to_object(object, liked_object)
|
||||
@ -179,6 +188,7 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
|
||||
# - Increase replies count
|
||||
# - Set up ActivityExpiration
|
||||
# - Set up notifications
|
||||
@impl true
|
||||
def handle(%{data: %{"type" => "Create"}} = activity, meta) do
|
||||
with {:ok, object, meta} <- handle_object_creation(meta[:object_data], meta),
|
||||
%User{} = user <- User.get_cached_by_ap_id(activity.data["actor"]) do
|
||||
@ -207,6 +217,7 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
|
||||
# - Add announce to object
|
||||
# - Set up notification
|
||||
# - Stream out the announce
|
||||
@impl true
|
||||
def handle(%{data: %{"type" => "Announce"}} = object, meta) do
|
||||
announced_object = Object.get_by_ap_id(object.data["object"])
|
||||
user = User.get_cached_by_ap_id(object.data["actor"])
|
||||
@ -224,6 +235,7 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
|
||||
{:ok, object, meta}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle(%{data: %{"type" => "Undo", "object" => undone_object}} = object, meta) do
|
||||
with undone_object <- Activity.get_by_ap_id(undone_object),
|
||||
:ok <- handle_undoing(undone_object) do
|
||||
@ -234,6 +246,7 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
|
||||
# Tasks this handles:
|
||||
# - Add reaction to object
|
||||
# - Set up notification
|
||||
@impl true
|
||||
def handle(%{data: %{"type" => "EmojiReact"}} = object, meta) do
|
||||
reacted_object = Object.get_by_ap_id(object.data["object"])
|
||||
Utils.add_emoji_reaction_to_object(object, reacted_object)
|
||||
@ -250,6 +263,7 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
|
||||
# - Reduce the user note count
|
||||
# - Reduce the reply count
|
||||
# - Stream out the activity
|
||||
@impl true
|
||||
def handle(%{data: %{"type" => "Delete", "object" => deleted_object}} = object, meta) do
|
||||
deleted_object =
|
||||
Object.normalize(deleted_object, false) ||
|
||||
@ -295,6 +309,7 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
|
||||
end
|
||||
|
||||
# Nothing to do
|
||||
@impl true
|
||||
def handle(object, meta) do
|
||||
{:ok, object, meta}
|
||||
end
|
||||
@ -439,6 +454,7 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
|
||||
|> Keyword.put(:notifications, notifications ++ existing)
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_after_transaction(meta) do
|
||||
meta
|
||||
|> send_notifications()
|
||||
|
8
lib/pleroma/web/activity_pub/side_effects/handling.ex
Normal file
8
lib/pleroma/web/activity_pub/side_effects/handling.ex
Normal file
@ -0,0 +1,8 @@
|
||||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.SideEffects.Handling do
|
||||
@callback handle(map(), keyword()) :: {:ok, map(), keyword()} | {:error, any()}
|
||||
@callback handle_after_transaction(map()) :: map()
|
||||
end
|
@ -15,6 +15,8 @@ defmodule Pleroma.Web.Federator do
|
||||
|
||||
require Logger
|
||||
|
||||
@behaviour Pleroma.Web.Federator.Publishing
|
||||
|
||||
@doc """
|
||||
Returns `true` if the distance to target object does not exceed max configured value.
|
||||
Serves to prevent fetching of very long threads, especially useful on smaller instances.
|
||||
@ -39,10 +41,12 @@ defmodule Pleroma.Web.Federator do
|
||||
ReceiverWorker.enqueue("incoming_ap_doc", %{"params" => params})
|
||||
end
|
||||
|
||||
@impl true
|
||||
def publish(%{id: "pleroma:fakeid"} = activity) do
|
||||
perform(:publish, activity)
|
||||
end
|
||||
|
||||
@impl true
|
||||
def publish(activity) do
|
||||
PublisherWorker.enqueue("publish", %{"activity_id" => activity.id})
|
||||
end
|
||||
|
7
lib/pleroma/web/federator/publishing.ex
Normal file
7
lib/pleroma/web/federator/publishing.ex
Normal file
@ -0,0 +1,7 @@
|
||||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.Federator.Publishing do
|
||||
@callback publish(map()) :: any()
|
||||
end
|
2
mix.exs
2
mix.exs
@ -211,7 +211,7 @@ defmodule Pleroma.Mixfile do
|
||||
git: "https://git.pleroma.social/pleroma/elixir-libraries/hackney.git",
|
||||
ref: "7d7119f0651515d6d7669c78393fd90950a3ec6e",
|
||||
override: true},
|
||||
{:mox, "~> 0.5", only: :test},
|
||||
{:mox, "~> 1.0", only: :test},
|
||||
{:websocket_client, git: "https://github.com/jeremyong/websocket_client.git", only: :test}
|
||||
] ++ oauth_deps()
|
||||
end
|
||||
|
2
mix.lock
2
mix.lock
@ -76,7 +76,7 @@
|
||||
"mochiweb": {:hex, :mochiweb, "2.18.0", "eb55f1db3e6e960fac4e6db4e2db9ec3602cc9f30b86cd1481d56545c3145d2e", [:rebar3], [], "hexpm"},
|
||||
"mock": {:hex, :mock, "0.3.5", "feb81f52b8dcf0a0d65001d2fec459f6b6a8c22562d94a965862f6cc066b5431", [:mix], [{:meck, "~> 0.8.13", [hex: :meck, repo: "hexpm", optional: false]}], "hexpm", "6fae404799408300f863550392635d8f7e3da6b71abdd5c393faf41b131c8728"},
|
||||
"mogrify": {:hex, :mogrify, "0.7.4", "9b2496dde44b1ce12676f85d7dc531900939e6367bc537c7243a1b089435b32d", [:mix], [], "hexpm", "50d79e337fba6bc95bfbef918058c90f50b17eed9537771e61d4619488f099c3"},
|
||||
"mox": {:hex, :mox, "0.5.2", "55a0a5ba9ccc671518d068c8dddd20eeb436909ea79d1799e2209df7eaa98b6c", [:mix], [], "hexpm", "df4310628cd628ee181df93f50ddfd07be3e5ecc30232d3b6aadf30bdfe6092b"},
|
||||
"mox": {:hex, :mox, "1.0.0", "4b3c7005173f47ff30641ba044eb0fe67287743eec9bd9545e37f3002b0a9f8b", [:mix], [], "hexpm", "201b0a20b7abdaaab083e9cf97884950f8a30a1350a1da403b3145e213c6f4df"},
|
||||
"myhtmlex": {:git, "https://git.pleroma.social/pleroma/myhtmlex.git", "ad0097e2f61d4953bfef20fb6abddf23b87111e6", [ref: "ad0097e2f61d4953bfef20fb6abddf23b87111e6", submodules: true]},
|
||||
"nimble_parsec": {:hex, :nimble_parsec, "0.6.0", "32111b3bf39137144abd7ba1cce0914533b2d16ef35e8abc5ec8be6122944263", [:mix], [], "hexpm", "27eac315a94909d4dc68bc07a4a83e06c8379237c5ea528a9acff4ca1c873c52"},
|
||||
"nimble_pool": {:hex, :nimble_pool, "0.1.0", "ffa9d5be27eee2b00b0c634eb649aa27f97b39186fec3c493716c2a33e784ec6", [:mix], [], "hexpm", "343a1eaa620ddcf3430a83f39f2af499fe2370390d4f785cd475b4df5acaf3f9"},
|
||||
|
@ -14,6 +14,8 @@ defmodule Mix.Tasks.Pleroma.DatabaseTest do
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
setup_all do
|
||||
Mix.shell(Mix.Shell.Process)
|
||||
|
||||
|
@ -12,6 +12,8 @@ defmodule Mix.Tasks.Pleroma.RelayTest do
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
setup_all do
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
|
||||
|
@ -20,6 +20,8 @@ defmodule Mix.Tasks.Pleroma.UserTest do
|
||||
import Mock
|
||||
import Pleroma.Factory
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
setup_all do
|
||||
Mix.shell(Mix.Shell.Process)
|
||||
|
||||
|
@ -11,6 +11,8 @@ defmodule Pleroma.ActivityTest do
|
||||
alias Pleroma.ThreadMute
|
||||
import Pleroma.Factory
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
setup_all do
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
:ok
|
||||
|
@ -11,6 +11,8 @@ defmodule Pleroma.Chat.MessageReferenceTest do
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
describe "messages" do
|
||||
test "it returns the last message in a chat" do
|
||||
user = insert(:user)
|
||||
|
@ -73,7 +73,8 @@ defmodule Pleroma.ChatTest do
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, chat} = Chat.bump_or_create(user.id, other_user.ap_id)
|
||||
:timer.sleep(1500)
|
||||
{:ok, chat} = time_travel(chat, -2)
|
||||
|
||||
{:ok, chat_two} = Chat.bump_or_create(user.id, other_user.ap_id)
|
||||
|
||||
assert chat.id == chat_two.id
|
||||
|
@ -11,6 +11,8 @@ defmodule Pleroma.Conversation.ParticipationTest do
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
test "getting a participation will also preload things" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
@ -96,12 +98,11 @@ defmodule Pleroma.Conversation.ParticipationTest do
|
||||
{:ok, %Participation{} = participation} =
|
||||
Participation.create_for_user_and_conversation(user, conversation)
|
||||
|
||||
{:ok, participation} = time_travel(participation, -2)
|
||||
|
||||
assert participation.user_id == user.id
|
||||
assert participation.conversation_id == conversation.id
|
||||
|
||||
# Needed because updated_at is accurate down to a second
|
||||
:timer.sleep(1000)
|
||||
|
||||
# Creating again returns the same participation
|
||||
{:ok, %Participation{} = participation_two} =
|
||||
Participation.create_for_user_and_conversation(user, conversation)
|
||||
|
@ -13,6 +13,8 @@ defmodule Pleroma.MigrationHelper.NotificationBackfillTest do
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
describe "fill_in_notification_types" do
|
||||
test "it fills in missing notification types" do
|
||||
user = insert(:user)
|
||||
|
@ -21,6 +21,8 @@ defmodule Pleroma.NotificationTest do
|
||||
alias Pleroma.Web.Push
|
||||
alias Pleroma.Web.Streamer
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
describe "create_notifications" do
|
||||
test "never returns nil" do
|
||||
user = insert(:user)
|
||||
|
@ -13,6 +13,8 @@ defmodule Pleroma.Object.FetcherTest do
|
||||
import Mock
|
||||
import Tesla.Mock
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
setup do
|
||||
mock(fn
|
||||
%{method: :get, url: "https://mastodon.example.org/users/userisgone"} ->
|
||||
|
@ -14,6 +14,8 @@ defmodule Pleroma.ObjectTest do
|
||||
alias Pleroma.Tests.ObanHelpers
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
setup do
|
||||
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
:ok
|
||||
|
@ -10,6 +10,8 @@ defmodule Pleroma.StatsTest do
|
||||
alias Pleroma.Stats
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
describe "user count" do
|
||||
test "it ignores internal users" do
|
||||
_user = insert(:user, local: true)
|
||||
|
@ -16,6 +16,8 @@ defmodule Pleroma.User.BackupTest do
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Workers.BackupWorker
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
setup do
|
||||
clear_config([Pleroma.Upload, :uploader])
|
||||
clear_config([Backup, :limit_days])
|
||||
|
@ -12,6 +12,8 @@ defmodule Pleroma.User.ImportTest do
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
setup_all do
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
:ok
|
||||
|
@ -10,6 +10,8 @@ defmodule Pleroma.User.WelcomeChatMessageTest do
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
setup do: clear_config([:welcome])
|
||||
|
||||
describe "post_message/1" do
|
||||
|
@ -19,6 +19,8 @@ defmodule Pleroma.UserTest do
|
||||
import ExUnit.CaptureLog
|
||||
import Swoosh.TestAssertions
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
setup_all do
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
:ok
|
||||
|
@ -26,6 +26,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
||||
|
||||
require Pleroma.Constants
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
setup_all do
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
:ok
|
||||
|
@ -22,6 +22,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
||||
import Pleroma.Factory
|
||||
import Tesla.Mock
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
setup do
|
||||
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
:ok
|
||||
|
@ -10,6 +10,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicyTest do
|
||||
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
setup do
|
||||
user = insert(:user)
|
||||
|
||||
|
@ -9,6 +9,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
||||
alias Pleroma.Web.ActivityPub.MRF.SimplePolicy
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
setup do:
|
||||
clear_config(:mrf_simple,
|
||||
media_removal: [],
|
||||
|
@ -11,6 +11,8 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.AcceptValidationTest do
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
setup do
|
||||
follower = insert(:user)
|
||||
followed = insert(:user, local: false)
|
||||
|
@ -12,6 +12,8 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.AnnounceValidationTest do
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
describe "announces" do
|
||||
setup do
|
||||
user = insert(:user)
|
||||
|
@ -12,6 +12,8 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ChatValidationTest do
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
describe "chat message create activities" do
|
||||
test "it is invalid if the object already exists" do
|
||||
user = insert(:user)
|
||||
|
@ -11,6 +11,8 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.EmojiReactHandlingTest do
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
describe "EmojiReacts" do
|
||||
setup do
|
||||
user = insert(:user)
|
||||
|
@ -12,6 +12,8 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.LikeValidationTest do
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
describe "likes" do
|
||||
setup do
|
||||
user = insert(:user)
|
||||
|
@ -11,6 +11,8 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.RejectValidationTest do
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
setup do
|
||||
follower = insert(:user)
|
||||
followed = insert(:user, local: false)
|
||||
|
@ -11,6 +11,8 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.UndoHandlingTest do
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
describe "Undos" do
|
||||
setup do
|
||||
user = insert(:user)
|
||||
|
@ -3,14 +3,35 @@
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.PipelineTest do
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
import Mock
|
||||
import Mox
|
||||
import Pleroma.Factory
|
||||
|
||||
alias Pleroma.ConfigMock
|
||||
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!
|
||||
|
||||
describe "common_pipeline/2" do
|
||||
setup do
|
||||
clear_config([:instance, :federating], true)
|
||||
ObjectValidatorMock
|
||||
|> expect(:validate, fn o, m -> {:ok, o, m} end)
|
||||
|
||||
MRFMock
|
||||
|> expect(:pipeline_filter, fn o, m -> {:ok, o, m} end)
|
||||
|
||||
ActivityPubMock
|
||||
|> expect(:persist, 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)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
@ -21,159 +42,53 @@ defmodule Pleroma.Web.ActivityPub.PipelineTest do
|
||||
|
||||
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,
|
||||
[],
|
||||
[pipeline_filter: fn o, m -> {:ok, o, m} end]
|
||||
},
|
||||
{
|
||||
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)
|
||||
FederatorMock
|
||||
|> expect(:publish, fn ^activity_with_object -> :ok end)
|
||||
|
||||
assert_called(Pleroma.Web.ActivityPub.ObjectValidator.validate(activity, meta))
|
||||
assert_called(Pleroma.Web.ActivityPub.MRF.pipeline_filter(activity, meta))
|
||||
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
|
||||
ConfigMock
|
||||
|> expect(:get, fn [:instance, :federating] -> true end)
|
||||
|
||||
assert {:ok, ^activity, ^meta} =
|
||||
Pleroma.Web.ActivityPub.Pipeline.common_pipeline(
|
||||
activity,
|
||||
meta
|
||||
)
|
||||
end
|
||||
|
||||
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,
|
||||
[],
|
||||
[pipeline_filter: fn o, m -> {:ok, o, m} end]
|
||||
},
|
||||
{
|
||||
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)
|
||||
FederatorMock
|
||||
|> expect(:publish, fn ^activity -> :ok end)
|
||||
|
||||
assert_called(Pleroma.Web.ActivityPub.ObjectValidator.validate(activity, meta))
|
||||
assert_called(Pleroma.Web.ActivityPub.MRF.pipeline_filter(activity, meta))
|
||||
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
|
||||
ConfigMock
|
||||
|> expect(:get, fn [:instance, :federating] -> true end)
|
||||
|
||||
assert {:ok, ^activity, ^meta} =
|
||||
Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity, meta)
|
||||
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]},
|
||||
{
|
||||
Pleroma.Web.ActivityPub.MRF,
|
||||
[],
|
||||
[pipeline_filter: fn o, m -> {:ok, o, m} end]
|
||||
},
|
||||
{
|
||||
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,
|
||||
[],
|
||||
[]
|
||||
}
|
||||
]) do
|
||||
assert {:ok, ^activity, ^meta} =
|
||||
Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity, meta)
|
||||
ConfigMock
|
||||
|> expect(:get, fn [:instance, :federating] -> true end)
|
||||
|
||||
assert_called(Pleroma.Web.ActivityPub.ObjectValidator.validate(activity, meta))
|
||||
assert_called(Pleroma.Web.ActivityPub.MRF.pipeline_filter(activity, meta))
|
||||
assert_called(Pleroma.Web.ActivityPub.ActivityPub.persist(activity, meta))
|
||||
assert_called(Pleroma.Web.ActivityPub.SideEffects.handle(activity, meta))
|
||||
end
|
||||
assert {:ok, ^activity, ^meta} =
|
||||
Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity, meta)
|
||||
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]},
|
||||
{
|
||||
Pleroma.Web.ActivityPub.MRF,
|
||||
[],
|
||||
[pipeline_filter: fn o, m -> {:ok, o, m} end]
|
||||
},
|
||||
{
|
||||
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,
|
||||
[],
|
||||
[]
|
||||
}
|
||||
]) do
|
||||
assert {:ok, ^activity, ^meta} =
|
||||
Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity, meta)
|
||||
ConfigMock
|
||||
|> expect(:get, fn [:instance, :federating] -> false end)
|
||||
|
||||
assert_called(Pleroma.Web.ActivityPub.ObjectValidator.validate(activity, meta))
|
||||
assert_called(Pleroma.Web.ActivityPub.MRF.pipeline_filter(activity, meta))
|
||||
assert_called(Pleroma.Web.ActivityPub.ActivityPub.persist(activity, meta))
|
||||
assert_called(Pleroma.Web.ActivityPub.SideEffects.handle(activity, meta))
|
||||
end
|
||||
assert {:ok, ^activity, ^meta} =
|
||||
Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity, meta)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -18,6 +18,8 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
||||
|
||||
@as_public "https://www.w3.org/ns/activitystreams#Public"
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
setup do
|
||||
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
:ok
|
||||
|
@ -14,6 +14,8 @@ defmodule Pleroma.Web.ActivityPub.RelayTest do
|
||||
import Pleroma.Factory
|
||||
import Mock
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
test "gets an actor for the relay" do
|
||||
user = Relay.get_actor()
|
||||
assert user.ap_id == "#{Pleroma.Web.Endpoint.url()}/relay"
|
||||
|
@ -23,6 +23,8 @@ defmodule Pleroma.Web.ActivityPub.SideEffectsTest do
|
||||
import Mock
|
||||
import Pleroma.Factory
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
describe "handle_after_transaction" do
|
||||
test "it streams out notifications and streams" do
|
||||
author = insert(:user, local: true)
|
||||
|
@ -11,6 +11,8 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AcceptHandlingTest do
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
test "it works for incoming accepts which were pre-accepted" do
|
||||
follower = insert(:user)
|
||||
followed = insert(:user)
|
||||
|
@ -12,6 +12,8 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AnnounceHandlingTest do
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
test "it works for incoming honk announces" do
|
||||
user = insert(:user, ap_id: "https://honktest/u/test", local: false)
|
||||
other_user = insert(:user)
|
||||
|
@ -12,6 +12,8 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AnswerHandlingTest do
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
setup_all do
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
:ok
|
||||
|
@ -11,6 +11,8 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.ArticleHandlingTest do
|
||||
alias Pleroma.Object.Fetcher
|
||||
alias Pleroma.Web.ActivityPub.Transmogrifier
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
test "Pterotype (Wordpress Plugin) Article" do
|
||||
Tesla.Mock.mock(fn %{url: "https://wedistribute.org/wp-json/pterotype/v1/actor/-blog"} ->
|
||||
%Tesla.Env{
|
||||
|
@ -12,6 +12,8 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AudioHandlingTest do
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
test "it works for incoming listens" do
|
||||
_user = insert(:user, ap_id: "http://mastodon.example.org/users/admin")
|
||||
|
||||
|
@ -10,6 +10,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.BlockHandlingTest do
|
||||
alias Pleroma.Web.ActivityPub.Transmogrifier
|
||||
|
||||
import Pleroma.Factory
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
test "it works for incoming blocks" do
|
||||
user = insert(:user)
|
||||
|
@ -12,6 +12,8 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.ChatMessageTest do
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.Web.ActivityPub.Transmogrifier
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
describe "handle_incoming" do
|
||||
test "handles chonks with attachment" do
|
||||
data = %{
|
||||
|
@ -14,6 +14,8 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.DeleteHandlingTest do
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
setup_all do
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
:ok
|
||||
|
@ -12,6 +12,8 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.EmojiReactHandlingTest do
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
test "it works for incoming emoji reactions" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user, local: false)
|
||||
|
@ -7,6 +7,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.EventHandlingTest do
|
||||
use Pleroma.DataCase
|
||||
|
||||
alias Pleroma.Object.Fetcher
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
test "Mobilizon Event object" do
|
||||
Tesla.Mock.mock(fn
|
||||
|
@ -15,6 +15,8 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.FollowHandlingTest do
|
||||
import Ecto.Query
|
||||
import Mock
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
setup_all do
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
:ok
|
||||
|
@ -11,6 +11,8 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.LikeHandlingTest do
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
test "it works for incoming likes" do
|
||||
user = insert(:user)
|
||||
|
||||
|
@ -16,6 +16,8 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
|
||||
import Pleroma.Factory
|
||||
import ExUnit.CaptureLog
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
setup_all do
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
:ok
|
||||
|
@ -12,6 +12,8 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.QuestionHandlingTest do
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
setup_all do
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
:ok
|
||||
|
@ -12,6 +12,8 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.RejectHandlingTest do
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
test "it fails for incoming rejects which cannot be correlated" do
|
||||
follower = insert(:user)
|
||||
followed = insert(:user, is_locked: true)
|
||||
|
@ -13,6 +13,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.UndoHandlingTest do
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
test "it works for incoming emoji reaction undos" do
|
||||
user = insert(:user)
|
||||
|
||||
|
@ -11,6 +11,8 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.UserUpdateHandlingTest do
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
test "it works for incoming update activities" do
|
||||
user = insert(:user, local: false)
|
||||
|
||||
|
@ -11,6 +11,8 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.VideoHandlingTest do
|
||||
alias Pleroma.Object.Fetcher
|
||||
alias Pleroma.Web.ActivityPub.Transmogrifier
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
setup_all do
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
:ok
|
||||
|
@ -18,6 +18,8 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
||||
import Pleroma.Factory
|
||||
import ExUnit.CaptureLog
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
setup_all do
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
:ok
|
||||
|
@ -16,6 +16,8 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
|
||||
|
||||
require Pleroma.Constants
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
describe "fetch the latest Follow" do
|
||||
test "fetches the latest Follow activity" do
|
||||
%Activity{data: %{"type" => "Follow"}} = activity = insert(:follow_activity)
|
||||
|
@ -10,6 +10,8 @@ defmodule Pleroma.Web.ActivityPub.ObjectViewTest do
|
||||
alias Pleroma.Web.ActivityPub.ObjectView
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
test "renders a note object" do
|
||||
note = insert(:note)
|
||||
|
||||
|
@ -10,6 +10,8 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
|
||||
alias Pleroma.Web.ActivityPub.UserView
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
test "Renders a user, including the public key" do
|
||||
user = insert(:user)
|
||||
{:ok, user} = User.ensure_keys_present(user)
|
||||
|
@ -18,6 +18,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
setup_all do
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
|
||||
|
@ -14,6 +14,8 @@ defmodule Pleroma.Web.AdminAPI.ChatControllerTest do
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
defp admin_setup do
|
||||
admin = insert(:user, is_admin: true)
|
||||
token = insert(:oauth_admin_token, user: admin)
|
||||
|
@ -11,6 +11,8 @@ defmodule Pleroma.Web.AdminAPI.RelayControllerTest do
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.User
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
setup_all do
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
|
||||
|
@ -13,6 +13,8 @@ defmodule Pleroma.Web.AdminAPI.StatusControllerTest do
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
setup do
|
||||
admin = insert(:user, is_admin: true)
|
||||
token = insert(:oauth_admin_token, user: admin)
|
||||
|
@ -19,6 +19,8 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Web.MediaProxy
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
setup_all do
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
|
||||
|
@ -25,6 +25,8 @@ defmodule Pleroma.Web.CommonAPITest do
|
||||
|
||||
require Pleroma.Constants
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
setup do: clear_config([:instance, :safe_dm_mentions])
|
||||
setup do: clear_config([:instance, :limit])
|
||||
setup do: clear_config([:instance, :max_pinned_statuses])
|
||||
|
@ -15,6 +15,8 @@ defmodule Pleroma.Web.FederatorTest do
|
||||
import Pleroma.Factory
|
||||
import Mock
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
setup_all do
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
|
||||
|
@ -14,6 +14,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
describe "account fetching" do
|
||||
test "works by id" do
|
||||
%User{id: user_id} = insert(:user)
|
||||
|
@ -10,6 +10,8 @@ defmodule Pleroma.Web.MastodonAPI.FollowRequestControllerTest do
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
describe "locked accounts" do
|
||||
setup do
|
||||
user = insert(:user, is_locked: true)
|
||||
|
@ -12,6 +12,8 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
test "does NOT render account/pleroma/relationship by default" do
|
||||
%{user: user, conn: conn} = oauth_access(["read:notifications"])
|
||||
other_user = insert(:user)
|
||||
|
@ -9,6 +9,11 @@ defmodule Pleroma.Web.MastodonAPI.PollControllerTest do
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
import Pleroma.Factory
|
||||
import Mox
|
||||
|
||||
setup :set_mox_from_context
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
describe "GET /api/v1/polls/:id" do
|
||||
setup do: oauth_access(["read:statuses"])
|
||||
@ -65,6 +70,8 @@ defmodule Pleroma.Web.MastodonAPI.PollControllerTest do
|
||||
|
||||
object = Object.normalize(activity)
|
||||
|
||||
# Calling this will run a vote in Cachex.fetch, which doesn't have access
|
||||
# to our mocks unless we run in global mode.
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|
@ -19,6 +19,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
setup do: clear_config([:instance, :federating])
|
||||
setup do: clear_config([:instance, :allow_relay])
|
||||
setup do: clear_config([:rich_media, :enabled])
|
||||
|
@ -11,6 +11,8 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
setup do
|
||||
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
:ok
|
||||
|
@ -13,6 +13,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPITest do
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
describe "follow/3" do
|
||||
test "returns error when followed user is deactivated" do
|
||||
follower = insert(:user)
|
||||
|
@ -11,6 +11,8 @@ defmodule Pleroma.Web.MastodonAPI.UpdateCredentialsTest do
|
||||
import Mock
|
||||
import Pleroma.Factory
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
setup do: clear_config([:instance, :max_account_fields])
|
||||
|
||||
describe "updating credentials" do
|
||||
|
@ -14,6 +14,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
||||
import Pleroma.Factory
|
||||
import Tesla.Mock
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
setup do
|
||||
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
:ok
|
||||
|
@ -22,6 +22,8 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do
|
||||
alias Pleroma.Web.PleromaAPI.Chat.MessageReferenceView
|
||||
import Pleroma.Factory
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
defp test_notifications_rendering(notifications, user, expected_result) do
|
||||
result = NotificationView.render("index.json", %{notifications: notifications, for: user})
|
||||
|
||||
|
@ -12,6 +12,8 @@ defmodule Pleroma.Web.MastodonAPI.PollViewTest do
|
||||
import Pleroma.Factory
|
||||
import Tesla.Mock
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
setup do
|
||||
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
:ok
|
||||
|
@ -22,6 +22,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
||||
import Tesla.Mock
|
||||
import OpenApiSpex.TestAssertions
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
setup do
|
||||
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
:ok
|
||||
|
@ -15,6 +15,8 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
|
||||
|
||||
require Pleroma.Constants
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
setup_all do
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
:ok
|
||||
|
@ -13,6 +13,8 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
|
||||
import Pleroma.Factory
|
||||
import Swoosh.TestAssertions
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
describe "POST /api/v1/pleroma/accounts/confirmation_resend" do
|
||||
setup do
|
||||
{:ok, user} =
|
||||
|
@ -13,6 +13,8 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
describe "POST /api/v1/pleroma/chats/:id/messages/:message_id/read" do
|
||||
setup do: oauth_access(["write:chats"])
|
||||
|
||||
@ -394,11 +396,11 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
|
||||
tridi = insert(:user)
|
||||
|
||||
{:ok, chat_1} = Chat.get_or_create(user.id, har.ap_id)
|
||||
:timer.sleep(1000)
|
||||
{:ok, _chat_2} = Chat.get_or_create(user.id, jafnhar.ap_id)
|
||||
:timer.sleep(1000)
|
||||
{:ok, chat_1} = time_travel(chat_1, -3)
|
||||
{:ok, chat_2} = Chat.get_or_create(user.id, jafnhar.ap_id)
|
||||
{:ok, _chat_2} = time_travel(chat_2, -2)
|
||||
{:ok, chat_3} = Chat.get_or_create(user.id, tridi.ap_id)
|
||||
:timer.sleep(1000)
|
||||
{:ok, chat_3} = time_travel(chat_3, -1)
|
||||
|
||||
# bump the second one
|
||||
{:ok, chat_2} = Chat.bump_or_create(user.id, jafnhar.ap_id)
|
||||
|
@ -3,12 +3,14 @@
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.PleromaAPI.EmojiPackControllerTest do
|
||||
use Pleroma.Web.ConnCase, async: false
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
import Mock
|
||||
import Tesla.Mock
|
||||
import Pleroma.Factory
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
@emoji_path Path.join(
|
||||
Pleroma.Config.get!([:instance, :static_dir]),
|
||||
"emoji"
|
||||
|
@ -13,6 +13,8 @@ defmodule Pleroma.Web.PleromaAPI.EmojiReactionControllerTest do
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
test "PUT /api/v1/pleroma/statuses/:id/reactions/:emoji", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
@ -11,6 +11,8 @@ defmodule Pleroma.Web.PleromaAPI.NotificationControllerTest do
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
describe "POST /api/v1/pleroma/notifications/read" do
|
||||
setup do: oauth_access(["write:notifications"])
|
||||
|
||||
|
@ -11,6 +11,8 @@ defmodule Pleroma.Web.PleromaAPI.UserImportControllerTest do
|
||||
import Pleroma.Factory
|
||||
import Mock
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
setup do
|
||||
Tesla.Mock.mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
:ok
|
||||
|
@ -14,6 +14,8 @@ defmodule Pleroma.Web.PleromaAPI.ChatMessageReferenceViewTest do
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
test "it displays a chat message" do
|
||||
user = insert(:user)
|
||||
recipient = insert(:user)
|
||||
|
@ -16,6 +16,8 @@ defmodule Pleroma.Web.PleromaAPI.ChatViewTest do
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
test "it represents a chat" do
|
||||
user = insert(:user)
|
||||
recipient = insert(:user)
|
||||
|
@ -15,6 +15,8 @@ defmodule Pleroma.Web.Push.ImplTest do
|
||||
alias Pleroma.Web.Push.Impl
|
||||
alias Pleroma.Web.Push.Subscription
|
||||
|
||||
@moduletag stubbed_pipeline: true
|
||||
|
||||
setup do
|
||||
Tesla.Mock.mock(fn
|
||||
%{method: :post, url: "https://example.com/example/1234"} ->
|
||||
|
@ -17,7 +17,7 @@ defmodule Pleroma.Web.StreamerTest do
|
||||
alias Pleroma.Web.Streamer
|
||||
alias Pleroma.Web.StreamerView
|
||||
|
||||
@moduletag needs_streamer: true, capture_log: true
|
||||
@moduletag needs_streamer: true, capture_log: true, stubbed_pipeline: true
|
||||
|
||||
setup do: clear_config([:instance, :skip_thread_containment])
|
||||
|
||||
|
@ -37,8 +37,7 @@ defmodule Pleroma.Web.TwitterAPI.PasswordControllerTest do
|
||||
|
||||
user = insert(:user)
|
||||
{:ok, token} = PasswordResetToken.create_token(user)
|
||||
|
||||
:timer.sleep(2000)
|
||||
{:ok, token} = time_travel(token, -2)
|
||||
|
||||
response =
|
||||
conn
|
||||
@ -55,7 +54,7 @@ defmodule Pleroma.Web.TwitterAPI.PasswordControllerTest do
|
||||
|
||||
user = insert(:user)
|
||||
{:ok, token} = PasswordResetToken.create_token(user)
|
||||
:timer.sleep(2000)
|
||||
{:ok, token} = time_travel(token, -2)
|
||||
{:ok, _access_token} = Token.create(insert(:oauth_app), user, %{})
|
||||
|
||||
params = %{
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user