Merge remote-tracking branch 'remotes/origin/develop' into feature/object-hashtags...
authorIvan Tashkinov <ivantashkinov@gmail.com>
Sat, 26 Dec 2020 19:23:05 +0000 (22:23 +0300)
committerIvan Tashkinov <ivantashkinov@gmail.com>
Sat, 26 Dec 2020 19:23:05 +0000 (22:23 +0300)
205 files changed:
.gitignore
CHANGELOG.md
config/config.exs
config/test.exs
lib/pleroma/activity.ex
lib/pleroma/caching.ex [new file with mode: 0644]
lib/pleroma/captcha.ex
lib/pleroma/config.ex
lib/pleroma/config/getting.ex [new file with mode: 0644]
lib/pleroma/emoji/pack.ex
lib/pleroma/html.ex
lib/pleroma/object.ex
lib/pleroma/reverse_proxy.ex
lib/pleroma/user.ex
lib/pleroma/web/activity_pub/activity_pub.ex
lib/pleroma/web/activity_pub/activity_pub/persisting.ex [new file with mode: 0644]
lib/pleroma/web/activity_pub/mrf.ex
lib/pleroma/web/activity_pub/mrf/pipeline_filtering.ex [new file with mode: 0644]
lib/pleroma/web/activity_pub/object_validator.ex
lib/pleroma/web/activity_pub/object_validator/validating.ex [new file with mode: 0644]
lib/pleroma/web/activity_pub/pipeline.ex
lib/pleroma/web/activity_pub/side_effects.ex
lib/pleroma/web/activity_pub/side_effects/handling.ex [new file with mode: 0644]
lib/pleroma/web/admin_api/controllers/media_proxy_cache_controller.ex
lib/pleroma/web/federator.ex
lib/pleroma/web/federator/publishing.ex [moved from lib/jason_types.ex with 59% similarity]
lib/pleroma/web/mastodon_api/controllers/poll_controller.ex
lib/pleroma/web/media_proxy.ex
lib/pleroma/web/pleroma_api/views/chat/message_reference_view.ex
lib/pleroma/web/plugs/cache.ex
lib/pleroma/web/plugs/idempotency_plug.ex
lib/pleroma/web/plugs/rate_limiter.ex
lib/pleroma/web/rel_me.ex
lib/pleroma/web/rich_media/parser.ex
mix.exs
mix.lock
priv/templates/sample_config.eex
test/mix/tasks/pleroma/count_statuses_test.exs
test/mix/tasks/pleroma/database_test.exs
test/mix/tasks/pleroma/ecto/migrate_test.exs
test/mix/tasks/pleroma/ecto/rollback_test.exs
test/mix/tasks/pleroma/instance_test.exs
test/mix/tasks/pleroma/refresh_counter_cache_test.exs
test/mix/tasks/pleroma/relay_test.exs
test/pleroma/activity/ir/topics_test.exs
test/pleroma/activity/search_test.exs
test/pleroma/application_requirements_test.exs
test/pleroma/bbs/handler_test.exs
test/pleroma/bookmark_test.exs
test/pleroma/captcha_test.exs
test/pleroma/chat_test.exs
test/pleroma/config_test.exs
test/pleroma/conversation/participation_test.exs
test/pleroma/earmark_renderer_test.exs
test/pleroma/ecto_type/activity_pub/object_validators/date_time_test.exs
test/pleroma/ecto_type/activity_pub/object_validators/object_id_test.exs
test/pleroma/ecto_type/activity_pub/object_validators/recipients_test.exs
test/pleroma/ecto_type/activity_pub/object_validators/safe_text_test.exs
test/pleroma/emails/admin_email_test.exs
test/pleroma/emails/user_email_test.exs
test/pleroma/emoji/formatter_test.exs
test/pleroma/emoji/pack_test.exs
test/pleroma/emoji_test.exs
test/pleroma/filter_test.exs
test/pleroma/following_relationship_test.exs
test/pleroma/healthcheck_test.exs
test/pleroma/html_test.exs
test/pleroma/http/adapter_helper/gun_test.exs
test/pleroma/integration/mastodon_websocket_test.exs
test/pleroma/keys_test.exs
test/pleroma/list_test.exs
test/pleroma/marker_test.exs
test/pleroma/mfa/backup_codes_test.exs
test/pleroma/mfa/totp_test.exs
test/pleroma/mfa_test.exs
test/pleroma/migration_helper/notification_backfill_test.exs
test/pleroma/moderation_log_test.exs
test/pleroma/pagination_test.exs
test/pleroma/registration_test.exs
test/pleroma/repo/migrations/fix_legacy_tags_test.exs
test/pleroma/repo/migrations/move_welcome_settings_test.exs
test/pleroma/repo_test.exs
test/pleroma/report_note_test.exs
test/pleroma/reverse_proxy_test.exs
test/pleroma/safe_jsonb_set_test.exs
test/pleroma/stats_test.exs
test/pleroma/upload/filter/dedupe_test.exs
test/pleroma/upload/filter/exiftool_test.exs
test/pleroma/uploaders/local_test.exs
test/pleroma/user/notification_setting_test.exs
test/pleroma/user_relationship_test.exs
test/pleroma/web/activity_pub/mrf/anti_followbot_policy_test.exs
test/pleroma/web/activity_pub/mrf/ensure_re_prepended_test.exs
test/pleroma/web/activity_pub/mrf/force_bot_unlisted_policy_test.exs
test/pleroma/web/activity_pub/mrf/no_placeholder_text_policy_test.exs
test/pleroma/web/activity_pub/mrf/normalize_markup_test.exs
test/pleroma/web/activity_pub/mrf/tag_policy_test.exs
test/pleroma/web/activity_pub/object_validators/accept_validation_test.exs
test/pleroma/web/activity_pub/object_validators/announce_validation_test.exs
test/pleroma/web/activity_pub/object_validators/article_note_validator_test.exs
test/pleroma/web/activity_pub/object_validators/attachment_validator_test.exs
test/pleroma/web/activity_pub/object_validators/block_validation_test.exs
test/pleroma/web/activity_pub/object_validators/delete_validation_test.exs
test/pleroma/web/activity_pub/object_validators/emoji_react_handling_test.exs
test/pleroma/web/activity_pub/object_validators/follow_validation_test.exs
test/pleroma/web/activity_pub/object_validators/like_validation_test.exs
test/pleroma/web/activity_pub/object_validators/reject_validation_test.exs
test/pleroma/web/activity_pub/object_validators/undo_handling_test.exs
test/pleroma/web/activity_pub/object_validators/update_handling_test.exs
test/pleroma/web/activity_pub/pipeline_test.exs
test/pleroma/web/activity_pub/relay_test.exs
test/pleroma/web/activity_pub/transmogrifier/accept_handling_test.exs
test/pleroma/web/activity_pub/transmogrifier/block_handling_test.exs
test/pleroma/web/activity_pub/transmogrifier/delete_handling_test.exs
test/pleroma/web/activity_pub/transmogrifier/emoji_react_handling_test.exs
test/pleroma/web/activity_pub/transmogrifier/like_handling_test.exs
test/pleroma/web/activity_pub/transmogrifier/reject_handling_test.exs
test/pleroma/web/activity_pub/transmogrifier/undo_handling_test.exs
test/pleroma/web/activity_pub/transmogrifier/user_update_handling_test.exs
test/pleroma/web/activity_pub/utils_test.exs
test/pleroma/web/activity_pub/views/user_view_test.exs
test/pleroma/web/activity_pub/visibility_test.exs
test/pleroma/web/admin_api/controllers/chat_controller_test.exs
test/pleroma/web/admin_api/controllers/config_controller_test.exs
test/pleroma/web/admin_api/controllers/media_proxy_cache_controller_test.exs
test/pleroma/web/admin_api/controllers/report_controller_test.exs
test/pleroma/web/admin_api/controllers/status_controller_test.exs
test/pleroma/web/admin_api/search_test.exs
test/pleroma/web/admin_api/views/moderation_log_view_test.exs
test/pleroma/web/admin_api/views/report_view_test.exs
test/pleroma/web/auth/authenticator_test.exs
test/pleroma/web/auth/basic_auth_test.exs
test/pleroma/web/auth/pleroma_authenticator_test.exs
test/pleroma/web/auth/totp_authenticator_test.exs
test/pleroma/web/endpoint/metrics_exporter_test.exs
test/pleroma/web/mastodon_api/controllers/account_controller_test.exs
test/pleroma/web/mastodon_api/controllers/auth_controller_test.exs
test/pleroma/web/mastodon_api/controllers/conversation_controller_test.exs
test/pleroma/web/mastodon_api/controllers/domain_block_controller_test.exs
test/pleroma/web/mastodon_api/controllers/filter_controller_test.exs
test/pleroma/web/mastodon_api/controllers/follow_request_controller_test.exs
test/pleroma/web/mastodon_api/controllers/instance_controller_test.exs
test/pleroma/web/mastodon_api/controllers/list_controller_test.exs
test/pleroma/web/mastodon_api/controllers/marker_controller_test.exs
test/pleroma/web/mastodon_api/controllers/poll_controller_test.exs
test/pleroma/web/mastodon_api/controllers/report_controller_test.exs
test/pleroma/web/mastodon_api/controllers/status_controller_test.exs
test/pleroma/web/mastodon_api/controllers/subscription_controller_test.exs
test/pleroma/web/mastodon_api/controllers/suggestion_controller_test.exs
test/pleroma/web/mastodon_api/mastodon_api_controller_test.exs
test/pleroma/web/mastodon_api/mastodon_api_test.exs
test/pleroma/web/mastodon_api/update_credentials_test.exs
test/pleroma/web/mastodon_api/views/conversation_view_test.exs
test/pleroma/web/mastodon_api/views/list_view_test.exs
test/pleroma/web/mastodon_api/views/marker_view_test.exs
test/pleroma/web/mastodon_api/views/scheduled_activity_view_test.exs
test/pleroma/web/mastodon_api/views/status_view_test.exs
test/pleroma/web/mastodon_api/views/subscription_view_test.exs
test/pleroma/web/media_proxy/invalidation/http_test.exs
test/pleroma/web/media_proxy/invalidation/script_test.exs
test/pleroma/web/media_proxy/invalidation_test.exs
test/pleroma/web/media_proxy/media_proxy_controller_test.exs
test/pleroma/web/metadata/player_view_test.exs
test/pleroma/web/metadata/providers/feed_test.exs
test/pleroma/web/metadata/providers/rel_me_test.exs
test/pleroma/web/metadata/utils_test.exs
test/pleroma/web/mongoose_im_controller_test.exs
test/pleroma/web/o_auth/app_test.exs
test/pleroma/web/o_auth/authorization_test.exs
test/pleroma/web/o_auth/mfa_controller_test.exs
test/pleroma/web/o_auth/token/utils_test.exs
test/pleroma/web/o_auth/token_test.exs
test/pleroma/web/pleroma_api/controllers/chat_controller_test.exs
test/pleroma/web/pleroma_api/controllers/conversation_controller_test.exs
test/pleroma/web/pleroma_api/controllers/mascot_controller_test.exs
test/pleroma/web/pleroma_api/controllers/notification_controller_test.exs
test/pleroma/web/pleroma_api/controllers/scrobble_controller_test.exs
test/pleroma/web/pleroma_api/controllers/two_factor_authentication_controller_test.exs
test/pleroma/web/pleroma_api/views/chat_view_test.exs
test/pleroma/web/pleroma_api/views/scrobble_view_test.exs
test/pleroma/web/plugs/cache_control_test.exs
test/pleroma/web/plugs/cache_test.exs
test/pleroma/web/plugs/ensure_public_or_authenticated_plug_test.exs
test/pleroma/web/plugs/idempotency_plug_test.exs
test/pleroma/web/plugs/uploaded_media_plug_test.exs
test/pleroma/web/plugs/user_enabled_plug_test.exs
test/pleroma/web/preload/providers/user_test.exs
test/pleroma/web/push/impl_test.exs
test/pleroma/web/rel_me_test.exs
test/pleroma/web/rich_media/parser/ttl/aws_signed_url_test.exs
test/pleroma/web/twitter_api/controller_test.exs
test/pleroma/web/twitter_api/password_controller_test.exs
test/pleroma/web/twitter_api/remote_follow_controller_test.exs
test/pleroma/web/twitter_api/twitter_api_test.exs
test/pleroma/web/uploader_controller_test.exs
test/pleroma/web/web_finger_test.exs
test/pleroma/workers/cron/new_users_digest_worker_test.exs
test/pleroma/xml_builder_test.exs
test/support/cachex_proxy.ex [new file with mode: 0644]
test/support/channel_case.ex
test/support/conn_case.ex
test/support/data_case.ex
test/support/helpers.ex
test/support/mocks.ex [new file with mode: 0644]
test/support/null_cache.ex [new file with mode: 0644]

index 6ae21e9144f410f289fc0734b714bfcbd7226aac..62ca61bce780d92f3ffdbb71093d76a40488b025 100644 (file)
@@ -3,6 +3,7 @@
 /db
 /deps
 /*.ez
+/test/instance
 /test/uploads
 /.elixir_ls
 /test/fixtures/DSCN0010_tmp.jpg
index c6bf38ee02fdb2e3a1f75f16cb4577ea7e302c11..e1604ab3a9e1888999738c442b8d2199961efdd8 100644 (file)
@@ -44,6 +44,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
 
 - Users with `is_discoverable` field set to false (default value) will appear in in-service search results but be hidden from external services (search bots etc.).
 - Streaming API: Posts and notifications are not dropped, when CLI task is executing.
+- Creating incorrect IPv4 address-style HTTP links when encountering certain numbers.
 
 <details>
   <summary>API Changes</summary>
@@ -53,24 +54,34 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
 
 ## Unreleased (Patch)
 
+### Fixed
+
+- Fix ability to update Pleroma Chat push notifications with PUT /api/v1/push/subscription and alert type pleroma:chat_mention
+- Emoji Reaction activity filtering from blocked and muted accounts.
+
+## [2.2.1] - 2020-12-22
+
 ### Changed
+- Updated Pleroma FE
 
 ### Fixed
 
 - Config generation: rename `Pleroma.Upload.Filter.ExifTool` to `Pleroma.Upload.Filter.Exiftool`.
-- Search: RUM index search speed has been fixed.
 - S3 Uploads with Elixir 1.11.
-- Emoji Reaction activity filtering from blocked and muted accounts.
 - Mix task pleroma.user delete_activities for source installations.
-- Fix ability to update Pleroma Chat push notifications with PUT /api/v1/push/subscription and alert type pleroma:chat_mention
-- Forwarded reports duplication from Pleroma instances.
+- Search: RUM index search speed has been fixed.
 - Rich Media Previews sometimes showed the wrong preview due to a bug following redirects.
+- Fixes for the autolinker.
+- Forwarded reports duplication from Pleroma instances.
 
-<details>
-  <summary>API</summary>
-- Statuses were not displayed for Mastodon forwarded reports.
+- <details>
+    <summary>API</summary>
+  - Statuses were not displayed for Mastodon forwarded reports.
+  </details>
 
-</details>
+### Upgrade notes
+
+1. Restart Pleroma
 
 ## [2.2.0] - 2020-11-12
 
index 3ccb6a3f5bdadf04a5661a7416a8892ce5a4e317..d6d116314e3f9a8a965e121b19af7b19bfaccefa 100644 (file)
@@ -47,7 +47,6 @@ use Mix.Config
 config :pleroma, ecto_repos: [Pleroma.Repo]
 
 config :pleroma, Pleroma.Repo,
-  types: Pleroma.PostgresTypes,
   telemetry_event: [Pleroma.Repo.Instrumenter],
   migration_lock: nil
 
index 2a20a03e720c785ac4678137250242d615f187d7..a858815921f65c81dcc60b5de679cb3182803dc5 100644 (file)
@@ -47,7 +47,10 @@ config :pleroma, Pleroma.Repo,
   password: "postgres",
   database: "pleroma_test",
   hostname: System.get_env("DB_HOST") || "localhost",
-  pool: Ecto.Adapters.SQL.Sandbox
+  pool: Ecto.Adapters.SQL.Sandbox,
+  pool_size: 50
+
+config :pleroma, :dangerzone, override_repo_pool_size: true
 
 # Reduce hash rounds for testing
 config :pbkdf2_elixir, rounds: 1
@@ -121,6 +124,16 @@ 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
+
+config :pleroma, :cachex, provider: Pleroma.CachexMock
+
 if File.exists?("./config/test.secret.exs") do
   import_config "test.secret.exs"
 else
index 07982331257d5c27ae22b324a6af9d9b07342812..9d970a80838fa29c27f1f98e0073f22713aba84c 100644 (file)
@@ -24,6 +24,8 @@ defmodule Pleroma.Activity do
 
   @primary_key {:id, FlakeId.Ecto.CompatType, autogenerate: true}
 
+  @cachex Pleroma.Config.get([:cachex, :provider], Cachex)
+
   schema "activities" do
     field(:data, :map)
     field(:local, :boolean, default: true)
@@ -298,7 +300,7 @@ defmodule Pleroma.Activity do
 
   defp purge_web_resp_cache(%Activity{} = activity) do
     %{path: path} = URI.parse(activity.data["id"])
-    Cachex.del(:web_resp_cache, path)
+    @cachex.del(:web_resp_cache, path)
     activity
   end
 
diff --git a/lib/pleroma/caching.ex b/lib/pleroma/caching.ex
new file mode 100644 (file)
index 0000000..766d12d
--- /dev/null
@@ -0,0 +1,19 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Caching do
+  @callback get!(Cachex.cache(), any()) :: any()
+  @callback get(Cachex.cache(), any()) :: {atom(), any()}
+  @callback put(Cachex.cache(), any(), any(), Keyword.t()) :: {Cachex.status(), boolean()}
+  @callback put(Cachex.cache(), any(), any()) :: {Cachex.status(), boolean()}
+  @callback fetch!(Cachex.cache(), any(), function() | nil) :: any()
+  # @callback del(Cachex.cache(), any(), Keyword.t()) :: {Cachex.status(), boolean()}
+  @callback del(Cachex.cache(), any()) :: {Cachex.status(), boolean()}
+  @callback stream!(Cachex.cache(), any()) :: Enumerable.t()
+  @callback expire_at(Cachex.cache(), binary(), number()) :: {Cachex.status(), boolean()}
+  @callback exists?(Cachex.cache(), any()) :: {Cachex.status(), boolean()}
+  @callback execute!(Cachex.cache(), function()) :: any()
+  @callback get_and_update(Cachex.cache(), any(), function()) ::
+              {:commit | :ignore, any()}
+end
index 6ab754b6f1dc333930471555b5c09c5e593144a0..990003dcdde3bd055a6b69d78c4c2d958392e71a 100644 (file)
@@ -7,6 +7,8 @@ defmodule Pleroma.Captcha do
   alias Plug.Crypto.KeyGenerator
   alias Plug.Crypto.MessageEncryptor
 
+  @cachex Pleroma.Config.get([:cachex, :provider], Cachex)
+
   @doc """
   Ask the configured captcha service for a new captcha
   """
@@ -86,7 +88,7 @@ defmodule Pleroma.Captcha do
   end
 
   defp validate_usage(token) do
-    if is_nil(Cachex.get!(:used_captcha_cache, token)) do
+    if is_nil(@cachex.get!(:used_captcha_cache, token)) do
       :ok
     else
       {:error, :already_used}
@@ -95,7 +97,7 @@ defmodule Pleroma.Captcha do
 
   defp mark_captcha_as_used(token) do
     ttl = seconds_valid() |> :timer.seconds()
-    Cachex.put(:used_captcha_cache, token, true, ttl: ttl)
+    @cachex.put(:used_captcha_cache, token, true, ttl: ttl)
   end
 
   defp method, do: Pleroma.Config.get!([__MODULE__, :method])
index 97f87759554f325192b315222444a5f8fc6840bb..86d4f6b72969f235168513decc8d80ae219d6b13 100644 (file)
@@ -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
diff --git a/lib/pleroma/config/getting.ex b/lib/pleroma/config/getting.ex
new file mode 100644 (file)
index 0000000..cc55767
--- /dev/null
@@ -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
index f768af19f7891a8b5be8c9520cf832eb9a66338a..ec97aa6529e4280a7836d6824f83af9e4f7cc63b 100644 (file)
@@ -20,6 +20,8 @@ defmodule Pleroma.Emoji.Pack do
           name: String.t()
         }
 
+  @cachex Pleroma.Config.get([:cachex, :provider], Cachex)
+
   alias Pleroma.Emoji
   alias Pleroma.Emoji.Pack
   alias Pleroma.Utils
@@ -415,7 +417,7 @@ defmodule Pleroma.Emoji.Pack do
     ttl_per_file = Pleroma.Config.get!([:emoji, :shared_pack_cache_seconds_per_file])
     overall_ttl = :timer.seconds(ttl_per_file * Enum.count(files))
 
-    Cachex.put!(
+    @cachex.put(
       :emoji_packs_cache,
       pack.name,
       # if pack.json MD5 changes, the cache is not valid anymore
@@ -618,7 +620,7 @@ defmodule Pleroma.Emoji.Pack do
   defp fetch_archive(pack) do
     hash = :crypto.hash(:md5, File.read!(pack.pack_file))
 
-    case Cachex.get!(:emoji_packs_cache, pack.name) do
+    case @cachex.get!(:emoji_packs_cache, pack.name) do
       %{hash: ^hash, pack_data: archive} -> archive
       _ -> create_archive_and_cache(pack, hash)
     end
index 43e9145be6503f9cd85fbd879303b4e8b32112ca..c848c782c3c79e731d70553e04009bf23992d3d6 100644 (file)
@@ -6,6 +6,8 @@ defmodule Pleroma.HTML do
   # Scrubbers are compiled on boot so they can be configured in OTP releases
   #  @on_load :compile_scrubbers
 
+  @cachex Pleroma.Config.get([:cachex, :provider], Cachex)
+
   def compile_scrubbers do
     dir = Path.join(:code.priv_dir(:pleroma), "scrubbers")
 
@@ -56,7 +58,7 @@ defmodule Pleroma.HTML do
       ) do
     key = "#{key}#{generate_scrubber_signature(scrubbers)}|#{activity.id}"
 
-    Cachex.fetch!(:scrubber_cache, key, fn _key ->
+    @cachex.fetch!(:scrubber_cache, key, fn _key ->
       object = Pleroma.Object.normalize(activity)
       ensure_scrubbed_html(content, scrubbers, object.data["fake"] || false, callback)
     end)
@@ -105,7 +107,7 @@ defmodule Pleroma.HTML do
     unless object.data["fake"] do
       key = "URL|#{object.id}"
 
-      Cachex.fetch!(:scrubber_cache, key, fn _key ->
+      @cachex.fetch!(:scrubber_cache, key, fn _key ->
         {:commit, {:ok, extract_first_external_url(content)}}
       end)
     else
index 357a3b504777f653219d3a130c073e1abb52fdde..1d756bcd1743af73eb413999cddcfd120f15f62e 100644 (file)
@@ -24,6 +24,8 @@ defmodule Pleroma.Object do
 
   @derive {Jason.Encoder, only: [:data]}
 
+  @cachex Pleroma.Config.get([:cachex, :provider], Cachex)
+
   schema "objects" do
     field(:data, :map)
 
@@ -189,9 +191,9 @@ defmodule Pleroma.Object do
   def get_cached_by_ap_id(ap_id) do
     key = "object:#{ap_id}"
 
-    with {:ok, nil} <- Cachex.get(:object_cache, key),
+    with {:ok, nil} <- @cachex.get(:object_cache, key),
          object when not is_nil(object) <- get_by_ap_id(ap_id),
-         {:ok, true} <- Cachex.put(:object_cache, key, object) do
+         {:ok, true} <- @cachex.put(:object_cache, key, object) do
       object
     else
       {:ok, object} -> object
@@ -249,13 +251,13 @@ defmodule Pleroma.Object do
   end
 
   def invalid_object_cache(%Object{data: %{"id" => id}}) do
-    with {:ok, true} <- Cachex.del(:object_cache, "object:#{id}") do
-      Cachex.del(:web_resp_cache, URI.parse(id).path)
+    with {:ok, true} <- @cachex.del(:object_cache, "object:#{id}") do
+      @cachex.del(:web_resp_cache, URI.parse(id).path)
     end
   end
 
   def set_cache(%Object{data: %{"id" => ap_id}} = object) do
-    Cachex.put(:object_cache, "object:#{ap_id}", object)
+    @cachex.put(:object_cache, "object:#{ap_id}", object)
     {:ok, object}
   end
 
index 8ae1157df1630f41e90c647de7028c6bcc27ad7a..3ea897c95968f5b3c12b4a3daf85cac80087465f 100644 (file)
@@ -17,6 +17,8 @@ defmodule Pleroma.ReverseProxy do
   @failed_request_ttl :timer.seconds(60)
   @methods ~w(GET HEAD)
 
+  @cachex Pleroma.Config.get([:cachex, :provider], Cachex)
+
   def max_read_duration_default, do: @max_read_duration
   def default_cache_control_header, do: @default_cache_control_header
 
@@ -107,7 +109,7 @@ defmodule Pleroma.ReverseProxy do
         opts
       end
 
-    with {:ok, nil} <- Cachex.get(:failed_proxy_url_cache, url),
+    with {:ok, nil} <- @cachex.get(:failed_proxy_url_cache, url),
          {:ok, code, headers, client} <- request(method, url, req_headers, client_opts),
          :ok <-
            header_length_constraint(
@@ -427,6 +429,6 @@ defmodule Pleroma.ReverseProxy do
         nil
       end
 
-    Cachex.put(:failed_proxy_url_cache, url, true, ttl: ttl)
+    @cachex.put(:failed_proxy_url_cache, url, true, ttl: ttl)
   end
 end
index 5a7704ddb7ec9b479b3355d65eff49d1ba052b37..bd4801058b45243eecd0551125d5b71b90303465 100644 (file)
@@ -81,6 +81,8 @@ defmodule Pleroma.User do
     ]
   ]
 
+  @cachex Pleroma.Config.get([:cachex, :provider], Cachex)
+
   schema "users" do
     field(:bio, :string, default: "")
     field(:raw_bio, :string)
@@ -246,13 +248,13 @@ defmodule Pleroma.User do
   end
 
   def cached_blocked_users_ap_ids(user) do
-    Cachex.fetch!(:user_cache, "blocked_users_ap_ids:#{user.ap_id}", fn _ ->
+    @cachex.fetch!(:user_cache, "blocked_users_ap_ids:#{user.ap_id}", fn _ ->
       blocked_users_ap_ids(user)
     end)
   end
 
   def cached_muted_users_ap_ids(user) do
-    Cachex.fetch!(:user_cache, "muted_users_ap_ids:#{user.ap_id}", fn _ ->
+    @cachex.fetch!(:user_cache, "muted_users_ap_ids:#{user.ap_id}", fn _ ->
       muted_users_ap_ids(user)
     end)
   end
@@ -1048,9 +1050,9 @@ defmodule Pleroma.User do
   def set_cache({:error, err}), do: {:error, err}
 
   def set_cache(%User{} = user) do
-    Cachex.put(:user_cache, "ap_id:#{user.ap_id}", user)
-    Cachex.put(:user_cache, "nickname:#{user.nickname}", user)
-    Cachex.put(:user_cache, "friends_ap_ids:#{user.nickname}", get_user_friends_ap_ids(user))
+    @cachex.put(:user_cache, "ap_id:#{user.ap_id}", user)
+    @cachex.put(:user_cache, "nickname:#{user.nickname}", user)
+    @cachex.put(:user_cache, "friends_ap_ids:#{user.nickname}", get_user_friends_ap_ids(user))
     {:ok, user}
   end
 
@@ -1073,26 +1075,26 @@ defmodule Pleroma.User do
 
   @spec get_cached_user_friends_ap_ids(User.t()) :: [String.t()]
   def get_cached_user_friends_ap_ids(user) do
-    Cachex.fetch!(:user_cache, "friends_ap_ids:#{user.ap_id}", fn _ ->
+    @cachex.fetch!(:user_cache, "friends_ap_ids:#{user.ap_id}", fn _ ->
       get_user_friends_ap_ids(user)
     end)
   end
 
   def invalidate_cache(user) do
-    Cachex.del(:user_cache, "ap_id:#{user.ap_id}")
-    Cachex.del(:user_cache, "nickname:#{user.nickname}")
-    Cachex.del(:user_cache, "friends_ap_ids:#{user.ap_id}")
-    Cachex.del(:user_cache, "blocked_users_ap_ids:#{user.ap_id}")
-    Cachex.del(:user_cache, "muted_users_ap_ids:#{user.ap_id}")
+    @cachex.del(:user_cache, "ap_id:#{user.ap_id}")
+    @cachex.del(:user_cache, "nickname:#{user.nickname}")
+    @cachex.del(:user_cache, "friends_ap_ids:#{user.ap_id}")
+    @cachex.del(:user_cache, "blocked_users_ap_ids:#{user.ap_id}")
+    @cachex.del(:user_cache, "muted_users_ap_ids:#{user.ap_id}")
   end
 
   @spec get_cached_by_ap_id(String.t()) :: User.t() | nil
   def get_cached_by_ap_id(ap_id) do
     key = "ap_id:#{ap_id}"
 
-    with {:ok, nil} <- Cachex.get(:user_cache, key),
+    with {:ok, nil} <- @cachex.get(:user_cache, key),
          user when not is_nil(user) <- get_by_ap_id(ap_id),
-         {:ok, true} <- Cachex.put(:user_cache, key, user) do
+         {:ok, true} <- @cachex.put(:user_cache, key, user) do
       user
     else
       {:ok, user} -> user
@@ -1104,11 +1106,11 @@ defmodule Pleroma.User do
     key = "id:#{id}"
 
     ap_id =
-      Cachex.fetch!(:user_cache, key, fn _ ->
+      @cachex.fetch!(:user_cache, key, fn _ ->
         user = get_by_id(id)
 
         if user do
-          Cachex.put(:user_cache, "ap_id:#{user.ap_id}", user)
+          @cachex.put(:user_cache, "ap_id:#{user.ap_id}", user)
           {:commit, user.ap_id}
         else
           {:ignore, ""}
@@ -1121,7 +1123,7 @@ defmodule Pleroma.User do
   def get_cached_by_nickname(nickname) do
     key = "nickname:#{nickname}"
 
-    Cachex.fetch!(:user_cache, key, fn ->
+    @cachex.fetch!(:user_cache, key, fn _ ->
       case get_or_fetch_by_nickname(nickname) do
         {:ok, user} -> {:commit, user}
         {:error, _error} -> {:ignore, nil}
@@ -1390,7 +1392,7 @@ defmodule Pleroma.User do
         )
       end
 
-      Cachex.del(:user_cache, "muted_users_ap_ids:#{muter.ap_id}")
+      @cachex.del(:user_cache, "muted_users_ap_ids:#{muter.ap_id}")
 
       {:ok, Enum.filter([user_mute, user_notification_mute], & &1)}
     end
@@ -1400,7 +1402,7 @@ defmodule Pleroma.User do
     with {:ok, user_mute} <- UserRelationship.delete_mute(muter, mutee),
          {:ok, user_notification_mute} <-
            UserRelationship.delete_notification_mute(muter, mutee) do
-      Cachex.del(:user_cache, "muted_users_ap_ids:#{muter.ap_id}")
+      @cachex.del(:user_cache, "muted_users_ap_ids:#{muter.ap_id}")
       {:ok, [user_mute, user_notification_mute]}
     end
   end
@@ -2408,7 +2410,7 @@ defmodule Pleroma.User do
           {:ok, UserRelationship.t()} | {:error, Ecto.Changeset.t()}
   defp add_to_block(%User{} = user, %User{} = blocked) do
     with {:ok, relationship} <- UserRelationship.create_block(user, blocked) do
-      Cachex.del(:user_cache, "blocked_users_ap_ids:#{user.ap_id}")
+      @cachex.del(:user_cache, "blocked_users_ap_ids:#{user.ap_id}")
       {:ok, relationship}
     end
   end
@@ -2417,7 +2419,7 @@ defmodule Pleroma.User do
           {:ok, UserRelationship.t()} | {:ok, nil} | {:error, Ecto.Changeset.t()}
   defp remove_from_block(%User{} = user, %User{} = blocked) do
     with {:ok, relationship} <- UserRelationship.delete_block(user, blocked) do
-      Cachex.del(:user_cache, "blocked_users_ap_ids:#{user.ap_id}")
+      @cachex.del(:user_cache, "blocked_users_ap_ids:#{user.ap_id}")
       {:ok, relationship}
     end
   end
index 2e25412c6ba7cd4e723da8ca0eeae94bc588b425..54d1a2350ea670c12cd37752150f09f869d49401 100644 (file)
@@ -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),
diff --git a/lib/pleroma/web/activity_pub/activity_pub/persisting.ex b/lib/pleroma/web/activity_pub/activity_pub/persisting.ex
new file mode 100644 (file)
index 0000000..3894f48
--- /dev/null
@@ -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
index 6e73b2f22f7e685d1ba12d1b89f2240df6c421d4..02fdee5fc4915bbd75b77cc89ebcdb3e9f10ccfd 100644 (file)
@@ -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"]
diff --git a/lib/pleroma/web/activity_pub/mrf/pipeline_filtering.ex b/lib/pleroma/web/activity_pub/mrf/pipeline_filtering.ex
new file mode 100644 (file)
index 0000000..8e0069b
--- /dev/null
@@ -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
index bd0a2a8dc09e2e8e8e5d869bf6c1967d5aa2d794..ce8e7341b782e86b7de2535d4156e192ca1a341a 100644 (file)
@@ -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)
diff --git a/lib/pleroma/web/activity_pub/object_validator/validating.ex b/lib/pleroma/web/activity_pub/object_validator/validating.ex
new file mode 100644 (file)
index 0000000..64c0c30
--- /dev/null
@@ -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
index 98c32a42b87bd6545263fb1dfd24f0ca99e8ca8d..2715b94d4ca54d5357e44006816eaa7cc6a560fa 100644 (file)
@@ -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}
index 8556fca1db8cc5121efcb6f97f5942842970767c..55c99ad0cabf3da38ae35494fb192ba8b035f9a6 100644 (file)
@@ -27,11 +27,17 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
 
   require Logger
 
+  @cachex Pleroma.Config.get([:cachex, :provider], Cachex)
+
+  @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 +65,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 +92,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 +134,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 +153,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 +172,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 +190,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 +219,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 +237,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 +248,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 +265,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 +311,7 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
   end
 
   # Nothing to do
+  @impl true
   def handle(object, meta) do
     {:ok, object, meta}
   end
@@ -312,7 +329,7 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
             {:ok, chat} = Chat.bump_or_create(user.id, other_user.ap_id)
             {:ok, cm_ref} = MessageReference.create(chat, object, user.ap_id != actor.ap_id)
 
-            Cachex.put(
+            @cachex.put(
               :chat_message_id_idempotency_key_cache,
               cm_ref.id,
               meta[:idempotency_key]
@@ -439,6 +456,7 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
     |> Keyword.put(:notifications, notifications ++ existing)
   end
 
+  @impl true
   def handle_after_transaction(meta) do
     meta
     |> send_notifications()
diff --git a/lib/pleroma/web/activity_pub/side_effects/handling.ex b/lib/pleroma/web/activity_pub/side_effects/handling.ex
new file mode 100644 (file)
index 0000000..9d64c0e
--- /dev/null
@@ -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
index 6d92e9f7ffdc376e82cd8b1450de3a361d84a1c2..2f712fb8cc44f27e7a3ba562aba9e404eb6ed519 100644 (file)
@@ -9,6 +9,8 @@ defmodule Pleroma.Web.AdminAPI.MediaProxyCacheController do
   alias Pleroma.Web.MediaProxy
   alias Pleroma.Web.Plugs.OAuthScopesPlug
 
+  @cachex Pleroma.Config.get([:cachex, :provider], Cachex)
+
   plug(Pleroma.Web.ApiSpec.CastAndValidate)
 
   plug(
@@ -38,7 +40,7 @@ defmodule Pleroma.Web.AdminAPI.MediaProxyCacheController do
 
   defp fetch_entries(params) do
     MediaProxy.cache_table()
-    |> Cachex.stream!(Cachex.Query.create(true, :key))
+    |> @cachex.stream!(Cachex.Query.create(true, :key))
     |> filter_entries(params[:query])
   end
 
index 13065414545829c8bf4696bbfff83246433ea551..658d20954ccbb86edf4f4e189453b8e71d54534e 100644 (file)
@@ -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
similarity index 59%
rename from lib/jason_types.ex
rename to lib/pleroma/web/federator/publishing.ex
index f1fdc96f44abf16903a808bafc5886ed7d0d3019..d6fba8f24653f536e0d49a91a588d272ffec9ac2 100644 (file)
@@ -2,8 +2,6 @@
 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
 # SPDX-License-Identifier: AGPL-3.0-only
 
-Postgrex.Types.define(
-  Pleroma.PostgresTypes,
-  [] ++ Ecto.Adapters.Postgres.extensions(),
-  json: Jason
-)
+defmodule Pleroma.Web.Federator.Publishing do
+  @callback publish(map()) :: any()
+end
index 3dcd1c44f284425594bd6088463badf19595108f..e26ec7136d6f49a95f111f6d370061049be1ce4f 100644 (file)
@@ -26,6 +26,8 @@ defmodule Pleroma.Web.MastodonAPI.PollController do
 
   defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.PollOperation
 
+  @cachex Pleroma.Config.get([:cachex, :provider], Cachex)
+
   @doc "GET /api/v1/polls/:id"
   def show(%{assigns: %{user: user}} = conn, %{id: id}) do
     with %Object{} = object <- Object.get_by_id_and_maybe_refetch(id, interval: 60),
@@ -55,7 +57,7 @@ defmodule Pleroma.Web.MastodonAPI.PollController do
   defp get_cached_vote_or_vote(user, object, choices) do
     idempotency_key = "polls:#{user.id}:#{object.data["id"]}"
 
-    Cachex.fetch!(:idempotency_cache, idempotency_key, fn ->
+    @cachex.fetch!(:idempotency_cache, idempotency_key, fn _ ->
       case CommonAPI.vote(user, object, choices) do
         {:error, _message} = res -> {:ignore, res}
         res -> {:commit, res}
index 8656b8cad31eb12910d10556ee58f741c34f48a8..2793cabc1d405ed3bbe00730168f566a37e9b744 100644 (file)
@@ -12,29 +12,31 @@ defmodule Pleroma.Web.MediaProxy do
   @base64_opts [padding: false]
   @cache_table :banned_urls_cache
 
+  @cachex Pleroma.Config.get([:cachex, :provider], Cachex)
+
   def cache_table, do: @cache_table
 
   @spec in_banned_urls(String.t()) :: boolean()
-  def in_banned_urls(url), do: elem(Cachex.exists?(@cache_table, url(url)), 1)
+  def in_banned_urls(url), do: elem(@cachex.exists?(@cache_table, url(url)), 1)
 
   def remove_from_banned_urls(urls) when is_list(urls) do
-    Cachex.execute!(@cache_table, fn cache ->
-      Enum.each(Invalidation.prepare_urls(urls), &Cachex.del(cache, &1))
+    @cachex.execute!(@cache_table, fn cache ->
+      Enum.each(Invalidation.prepare_urls(urls), &@cachex.del(cache, &1))
     end)
   end
 
   def remove_from_banned_urls(url) when is_binary(url) do
-    Cachex.del(@cache_table, url(url))
+    @cachex.del(@cache_table, url(url))
   end
 
   def put_in_banned_urls(urls) when is_list(urls) do
-    Cachex.execute!(@cache_table, fn cache ->
-      Enum.each(Invalidation.prepare_urls(urls), &Cachex.put(cache, &1, true))
+    @cachex.execute!(@cache_table, fn cache ->
+      Enum.each(Invalidation.prepare_urls(urls), &@cachex.put(cache, &1, true))
     end)
   end
 
   def put_in_banned_urls(url) when is_binary(url) do
-    Cachex.put(@cache_table, url(url), true)
+    @cachex.put(@cache_table, url(url), true)
   end
 
   def url(url) when is_nil(url) or url == "", do: nil
index c058fb340eebf6ab2f3956ee541a883fae7328d1..df48044e3c175828c7da6cd5e106c4b96f83b3b9 100644 (file)
@@ -10,6 +10,8 @@ defmodule Pleroma.Web.PleromaAPI.Chat.MessageReferenceView do
   alias Pleroma.Web.CommonAPI.Utils
   alias Pleroma.Web.MastodonAPI.StatusView
 
+  @cachex Pleroma.Config.get([:cachex, :provider], Cachex)
+
   def render(
         "show.json",
         %{
@@ -51,7 +53,7 @@ defmodule Pleroma.Web.PleromaAPI.Chat.MessageReferenceView do
   end
 
   defp put_idempotency_key(data) do
-    with {:ok, idempotency_key} <- Cachex.get(:chat_message_id_idempotency_key_cache, data.id) do
+    with {:ok, idempotency_key} <- @cachex.get(:chat_message_id_idempotency_key_cache, data.id) do
       data
       |> Maps.put_if_present(:idempotency_key, idempotency_key)
     else
index 6de01804afd71623ee6b1e8dbd8f603ee1d39f93..18880716a0966487b3783eef4abeb9588651022b 100644 (file)
@@ -41,6 +41,8 @@ defmodule Pleroma.Web.Plugs.Cache do
 
   @defaults %{ttl: nil, query_params: true}
 
+  @cachex Pleroma.Config.get([:cachex, :provider], Cachex)
+
   @impl true
   def init([]), do: @defaults
 
@@ -53,7 +55,7 @@ defmodule Pleroma.Web.Plugs.Cache do
   def call(%{method: "GET"} = conn, opts) do
     key = cache_key(conn, opts)
 
-    case Cachex.get(:web_resp_cache, key) do
+    case @cachex.get(:web_resp_cache, key) do
       {:ok, nil} ->
         cache_resp(conn, opts)
 
@@ -97,11 +99,11 @@ defmodule Pleroma.Web.Plugs.Cache do
 
         conn =
           unless opts[:tracking_fun] do
-            Cachex.put(:web_resp_cache, key, {content_type, body}, ttl: ttl)
+            @cachex.put(:web_resp_cache, key, {content_type, body}, ttl: ttl)
             conn
           else
             tracking_fun_data = Map.get(conn.assigns, :tracking_fun_data, nil)
-            Cachex.put(:web_resp_cache, key, {content_type, body, tracking_fun_data}, ttl: ttl)
+            @cachex.put(:web_resp_cache, key, {content_type, body, tracking_fun_data}, ttl: ttl)
 
             opts.tracking_fun.(conn, tracking_fun_data)
           end
index 254a790b0b6d17d53a7fa0f635b62bcccdfb2056..4f908779c1fd1e421de204fbf040b95bf23a8efb 100644 (file)
@@ -8,6 +8,8 @@ defmodule Pleroma.Web.Plugs.IdempotencyPlug do
 
   @behaviour Plug
 
+  @cachex Pleroma.Config.get([:cachex, :provider], Cachex)
+
   @impl true
   def init(opts), do: opts
 
@@ -25,7 +27,7 @@ defmodule Pleroma.Web.Plugs.IdempotencyPlug do
   def call(conn, _), do: conn
 
   def process_request(conn, key) do
-    case Cachex.get(:idempotency_cache, key) do
+    case @cachex.get(:idempotency_cache, key) do
       {:ok, nil} ->
         cache_resposnse(conn, key)
 
@@ -43,7 +45,7 @@ defmodule Pleroma.Web.Plugs.IdempotencyPlug do
       content_type = get_content_type(conn)
 
       record = {request_id, content_type, conn.status, conn.resp_body}
-      {:ok, _} = Cachex.put(:idempotency_cache, key, record)
+      {:ok, _} = @cachex.put(:idempotency_cache, key, record)
 
       conn
       |> put_resp_header("idempotency-key", key)
index a589610d1997824a4ef11501e2f7afdf8e10cb79..034a5bbe242731ecd47696feccc52af9debdd16a 100644 (file)
@@ -72,6 +72,8 @@ defmodule Pleroma.Web.Plugs.RateLimiter do
 
   require Logger
 
+  @cachex Pleroma.Config.get([:cachex, :provider], Cachex)
+
   @doc false
   def init(plug_opts) do
     plug_opts
@@ -124,7 +126,7 @@ defmodule Pleroma.Web.Plugs.RateLimiter do
       key_name = make_key_name(action_settings)
       limit = get_limits(action_settings)
 
-      case Cachex.get(bucket_name, key_name) do
+      case @cachex.get(bucket_name, key_name) do
         {:error, :no_cache} ->
           @inspect_bucket_not_found
 
@@ -157,7 +159,7 @@ defmodule Pleroma.Web.Plugs.RateLimiter do
     key_name = make_key_name(action_settings)
     limit = get_limits(action_settings)
 
-    case Cachex.get_and_update(bucket_name, key_name, &increment_value(&1, limit)) do
+    case @cachex.get_and_update(bucket_name, key_name, &increment_value(&1, limit)) do
       {:commit, value} ->
         {:ok, value}
 
index 28f75b18d624d297559f68e88c24b1fceea57d35..650c6a3fc1d251e36ff4cf42a93e19f9fcd7fc8b 100644 (file)
@@ -12,8 +12,9 @@ defmodule Pleroma.Web.RelMe do
   if Pleroma.Config.get(:env) == :test do
     def parse(url) when is_binary(url), do: parse_url(url)
   else
+    @cachex Pleroma.Config.get([:cachex, :provider], Cachex)
     def parse(url) when is_binary(url) do
-      Cachex.fetch!(:rel_me_cache, url, fn _ ->
+      @cachex.fetch!(:rel_me_cache, url, fn _ ->
         {:commit, parse_url(url)}
       end)
     rescue
index c70d2fdbade7c66a6f253ecbf2e0d3672523e059..d7a49119818a433b9fae494e6b4e85a281ebf14a 100644 (file)
@@ -5,6 +5,8 @@
 defmodule Pleroma.Web.RichMedia.Parser do
   require Logger
 
+  @cachex Pleroma.Config.get([:cachex, :provider], Cachex)
+
   defp parsers do
     Pleroma.Config.get([:rich_media, :parsers])
   end
@@ -24,7 +26,7 @@ defmodule Pleroma.Web.RichMedia.Parser do
     end
 
     defp get_cached_or_parse(url) do
-      case Cachex.fetch(:rich_media_cache, url, fn ->
+      case @cachex.fetch(:rich_media_cache, url, fn ->
              case parse_url(url) do
                {:ok, _} = res ->
                  {:commit, res}
@@ -64,7 +66,7 @@ defmodule Pleroma.Web.RichMedia.Parser do
 
     defp set_error_ttl(url, _reason) do
       ttl = Pleroma.Config.get([:rich_media, :failure_backoff], 60_000)
-      Cachex.expire(:rich_media_cache, url, ttl)
+      @cachex.expire(:rich_media_cache, url, ttl)
       :ok
     end
 
@@ -106,7 +108,7 @@ defmodule Pleroma.Web.RichMedia.Parser do
       {:ok, ttl} when is_number(ttl) ->
         ttl = ttl * 1000
 
-        case Cachex.expire_at(:rich_media_cache, url, ttl) do
+        case @cachex.expire_at(:rich_media_cache, url, ttl) do
           {:ok, true} -> {:ok, ttl}
           {:ok, false} -> {:error, :no_key}
         end
diff --git a/mix.exs b/mix.exs
index fb5b380f4ba356ea6e47a05752370111b3180f65..a596e34ea32b621cefca6fc7c4ba8634315887e9 100644 (file)
--- a/mix.exs
+++ b/mix.exs
@@ -158,7 +158,7 @@ defmodule Pleroma.Mixfile do
       {:floki, "~> 0.27"},
       {:timex, "~> 3.6"},
       {:ueberauth, "~> 0.4"},
-      {:linkify, "~> 0.4.0"},
+      {:linkify, "~> 0.4.1"},
       {:http_signatures, "~> 0.1.0"},
       {:telemetry, "~> 0.3"},
       {:poolboy, "~> 1.5"},
@@ -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
index 7db71453fd40cfbccdbaabaf8d07ce4b31321004..32b2e13911d941b61dbc2e2d699bd5b18c61200a 100644 (file)
--- a/mix.lock
+++ b/mix.lock
@@ -33,7 +33,7 @@
   "ecto_enum": {:hex, :ecto_enum, "1.4.0", "d14b00e04b974afc69c251632d1e49594d899067ee2b376277efd8233027aec8", [:mix], [{:ecto, ">= 3.0.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:ecto_sql, "> 3.0.0", [hex: :ecto_sql, repo: "hexpm", optional: false]}, {:mariaex, ">= 0.0.0", [hex: :mariaex, repo: "hexpm", optional: true]}, {:postgrex, ">= 0.0.0", [hex: :postgrex, repo: "hexpm", optional: true]}], "hexpm", "8fb55c087181c2b15eee406519dc22578fa60dd82c088be376d0010172764ee4"},
   "ecto_sql": {:hex, :ecto_sql, "3.4.5", "30161f81b167d561a9a2df4329c10ae05ff36eca7ccc84628f2c8b9fa1e43323", [:mix], [{:db_connection, "~> 2.2", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.4.3", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.3.0 or ~> 0.4.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.15.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.0", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "31990c6a3579b36a3c0841d34a94c275e727de8b84f58509da5f1b2032c98ac2"},
   "eimp": {:hex, :eimp, "1.0.14", "fc297f0c7e2700457a95a60c7010a5f1dcb768a083b6d53f49cd94ab95a28f22", [:rebar3], [{:p1_utils, "1.0.18", [hex: :p1_utils, repo: "hexpm", optional: false]}], "hexpm", "501133f3112079b92d9e22da8b88bf4f0e13d4d67ae9c15c42c30bd25ceb83b6"},
-  "elixir_make": {:hex, :elixir_make, "0.6.1", "8faa29a5597faba999aeeb72bbb9c91694ef8068f0131192fb199f98d32994ef", [:mix], [], "hexpm", "35d33270680f8d839a4003c3e9f43afb595310a592405a00afc12de4c7f55a18"},
+  "elixir_make": {:hex, :elixir_make, "0.6.2", "7dffacd77dec4c37b39af867cedaabb0b59f6a871f89722c25b28fcd4bd70530", [:mix], [], "hexpm", "03e49eadda22526a7e5279d53321d1cced6552f344ba4e03e619063de75348d9"},
   "esshd": {:hex, :esshd, "0.1.1", "d4dd4c46698093a40a56afecce8a46e246eb35463c457c246dacba2e056f31b5", [:mix], [], "hexpm", "d73e341e3009d390aa36387dc8862860bf9f874c94d9fd92ade2926376f49981"},
   "eternal": {:hex, :eternal, "1.2.1", "d5b6b2499ba876c57be2581b5b999ee9bdf861c647401066d3eeed111d096bc4", [:mix], [], "hexpm", "b14f1dc204321429479c569cfbe8fb287541184ed040956c8862cb7a677b8406"},
   "ex2ms": {:hex, :ex2ms, "1.5.0", "19e27f9212be9a96093fed8cdfbef0a2b56c21237196d26760f11dfcfae58e97", [:mix], [], "hexpm"},
@@ -65,7 +65,7 @@
   "jose": {:hex, :jose, "1.10.1", "16d8e460dae7203c6d1efa3f277e25b5af8b659febfc2f2eb4bacf87f128b80a", [:mix, :rebar3], [], "hexpm", "3c7ddc8a9394b92891db7c2771da94bf819834a1a4c92e30857b7d582e2f8257"},
   "jumper": {:hex, :jumper, "1.0.1", "3c00542ef1a83532b72269fab9f0f0c82bf23a35e27d278bfd9ed0865cecabff", [:mix], [], "hexpm", "318c59078ac220e966d27af3646026db9b5a5e6703cb2aa3e26bcfaba65b7433"},
   "libring": {:hex, :libring, "1.4.0", "41246ba2f3fbc76b3971f6bce83119dfec1eee17e977a48d8a9cfaaf58c2a8d6", [:mix], [], "hexpm"},
-  "linkify": {:hex, :linkify, "0.4.0", "7845b6ac33050a41acaf9318923ce6e7f3854418be9a5f22184de103f7a68ff9", [:mix], [], "hexpm", "a0ceb4c78591fecccf1d99fecc10c13dba75a307c663c80e28af9e2cdd9776ee"},
+  "linkify": {:hex, :linkify, "0.4.1", "f881eb3429ae88010cf736e6fb3eed406c187bcdd544902ec937496636b7c7b3", [:mix], [], "hexpm", "ce98693f54ae9ace59f2f7a8aed3de2ef311381a8ce7794804bd75484c371dda"},
   "majic": {:git, "https://git.pleroma.social/pleroma/elixir-libraries/majic.git", "4c692e544b28d1f5e543fb8a44be090f8cd96f80", [ref: "4c692e544b28d1f5e543fb8a44be090f8cd96f80"]},
   "makeup": {:hex, :makeup, "1.0.3", "e339e2f766d12e7260e6672dd4047405963c5ec99661abdc432e6ec67d29ef95", [:mix], [{:nimble_parsec, "~> 0.5", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "2e9b4996d11832947731f7608fed7ad2f9443011b3b479ae288011265cdd3dad"},
   "makeup_elixir": {:hex, :makeup_elixir, "0.14.1", "4f0e96847c63c17841d42c08107405a005a2680eb9c7ccadfd757bd31dabccfb", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "f2438b1a80eaec9ede832b5c41cd4f373b38fd7aa33e3b22d9db79e640cbde11"},
@@ -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"},
index cdddc47eab0384cb97927cdbc2dacd0eb548da66..2f5952ef18891ae57a6a583e7030112924b8ded6 100644 (file)
@@ -32,8 +32,7 @@ config :pleroma, Pleroma.Repo,
   username: "<%= dbuser %>",
   password: "<%= dbpass %>",
   database: "<%= dbname %>",
-  hostname: "<%= dbhost %>",
-  pool_size: 10
+  hostname: "<%= dbhost %>"
 
 # Configure web push notifications
 config :web_push_encryption, :vapid_details,
index c5cd16960a70055681570b0a4d85d94e7aec3357..8fe3959ea6b080849ecbc6c91ddcc8aae16cc1fc 100644 (file)
@@ -3,6 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Mix.Tasks.Pleroma.CountStatusesTest do
+  # Uses log capture, has to stay synchronous
   use Pleroma.DataCase
 
   alias Pleroma.User
index cf28576b5317bde98c053242a5d677ccaed410b5..eefb124266df9c8d04d48a6f99840cdc87e9005a 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Mix.Tasks.Pleroma.DatabaseTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
   use Oban.Testing, repo: Pleroma.Repo
 
   alias Pleroma.Activity
index 43df176a19b3d98012b64c2979cb1b2aa6831f5b..548357508aa9210fce8f2d222e6c61c66fece14a 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-onl
 
 defmodule Mix.Tasks.Pleroma.Ecto.MigrateTest do
-  use Pleroma.DataCase, async: true
+  use Pleroma.DataCase
   import ExUnit.CaptureLog
   require Logger
 
index 0236e35d529afe9e6a734ae814a871796d333727..9e39db8fa1eb6626337309f2eaae5951031dcd0f 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Mix.Tasks.Pleroma.Ecto.RollbackTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
   import ExUnit.CaptureLog
   require Logger
 
index 6580fc932b831a5515cf76c6da870d58fbd18687..1d2dde10869b46a22dbee0501800c77ae97e7ef7 100644 (file)
@@ -3,7 +3,8 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Mix.Tasks.Pleroma.InstanceTest do
-  use ExUnit.Case
+  # Modifies the Application Environment, has to stay synchronous.
+  use Pleroma.DataCase
 
   setup do
     File.mkdir_p!(tmp_path())
@@ -15,15 +16,17 @@ defmodule Mix.Tasks.Pleroma.InstanceTest do
       if File.exists?(static_dir) do
         File.rm_rf(Path.join(static_dir, "robots.txt"))
       end
-
-      Pleroma.Config.put([:instance, :static_dir], static_dir)
     end)
 
+    # Is being modified by the mix task.
+    clear_config([:instance, :static_dir])
+
     :ok
   end
 
+  @uuid Ecto.UUID.generate()
   defp tmp_path do
-    "/tmp/generated_files/"
+    "/tmp/generated_files/#{@uuid}/"
   end
 
   test "running gen" do
index 6a1a9ac1741a3d804afc69efd535ebfa071f00d7..e79dc063214123db6530b36a8619421665c5e426 100644 (file)
@@ -3,6 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Mix.Tasks.Pleroma.RefreshCounterCacheTest do
+  # Uses log capture, has to stay synchronous
   use Pleroma.DataCase
   alias Pleroma.Web.CommonAPI
   import ExUnit.CaptureIO, only: [capture_io: 1]
index cf48e7dda84dbde167fec1c9e35114fd777743eb..b453ed1c6b0888398395aec36fa5074a226eb9b5 100644 (file)
@@ -100,7 +100,7 @@ defmodule Mix.Tasks.Pleroma.RelayTest do
       end)
 
       Pleroma.Repo.delete(user)
-      Cachex.clear(:user_cache)
+      User.invalidate_cache(user)
 
       Mix.Tasks.Pleroma.Relay.run(["unfollow", target_instance])
 
@@ -137,7 +137,7 @@ defmodule Mix.Tasks.Pleroma.RelayTest do
       end)
 
       Pleroma.Repo.delete(user)
-      Cachex.clear(:user_cache)
+      User.invalidate_cache(user)
 
       Mix.Tasks.Pleroma.Relay.run(["unfollow", target_instance, "--force"])
 
index 5e5c2f8dac7d48138931187a147c0685084a9782..b464822d9c21274cf9afa435c22d2d967861746f 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Activity.Ir.TopicsTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
 
   alias Pleroma.Activity
   alias Pleroma.Activity.Ir.Topics
index fc910e7255031dfa6559cdaffb0e470b53e14a4c..49b7aa2922955037185f280ba31e8fc3230c0bd2 100644 (file)
@@ -7,7 +7,7 @@ defmodule Pleroma.Activity.SearchTest do
   alias Pleroma.Web.CommonAPI
   import Pleroma.Factory
 
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
 
   test "it finds something" do
     user = insert(:user)
index b432dbc37e073ea211ad85509b8093866deb0887..e3cca5487d6ee0fcf9c2e82232a0b0605b75973d 100644 (file)
@@ -15,6 +15,7 @@ defmodule Pleroma.ApplicationRequirementsTest do
   describe "check_repo_pool_size!/1" do
     test "raises if the pool size is unexpected" do
       clear_config([Pleroma.Repo, :pool_size], 11)
+      clear_config([:dangerzone, :override_repo_pool_size], false)
 
       assert_raise Pleroma.ApplicationRequirements.VerifyError,
                    "Repo.pool_size different than recommended value.",
index e605c2726b66b388f62f7d6bb376c329b51bbb1d..bba8fab0faa60045705232cdc89bd20dd6a2dc79 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.BBS.HandlerTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
   alias Pleroma.Activity
   alias Pleroma.BBS.Handler
   alias Pleroma.Object
index 2726fe7cd02f3f29428ef52d2a37a63276d66369..ef090d785138cfbeaec8e921a916c1d264ac51a1 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.BookmarkTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
   import Pleroma.Factory
   alias Pleroma.Bookmark
   alias Pleroma.Web.CommonAPI
index 1b9f4a12f5be8b3055cc2d49fb7ad492db7da429..bde3c72f7b7e11f5acd64da370586b162519dd36 100644 (file)
@@ -80,7 +80,6 @@ defmodule Pleroma.CaptchaTest do
 
       assert is_binary(answer)
       assert :ok = Captcha.validate(token, "63615261b77f5354fb8c4e4986477555", answer)
-      Cachex.del(:used_captcha_cache, token)
     end
 
     test "doesn't validate invalid answer" do
index 9e8a9ebf01abcca2ba80528c72ecef060e79afc8..1dd04916c1b1219ff6d0e5f7225bde2cebe0837c 100644 (file)
@@ -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
index 1556e4237420cf35c253f7a19f43b7b57495dca6..f524d90ddfd9b11b503d06b83bdb181b9f12bf0f 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.ConfigTest do
-  use ExUnit.Case
+  use Pleroma.DataCase
 
   test "get/1 with an atom" do
     assert Pleroma.Config.get(:instance) == Application.get_env(:pleroma, :instance)
index 5a603dcc1cdb18994cbcb81f1efb8a409c35030f..122b10486f8562ff00f491efbfb8fc22d6feb6d9 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Conversation.ParticipationTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
   import Pleroma.Factory
   alias Pleroma.Conversation
   alias Pleroma.Conversation.Participation
@@ -96,12 +96,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)
index 220d97d168d07b5d8df0c0ea42ebf32c723588f7..73aaec7f4eaf934bea90f9b9d88a3ec086c5d133 100644 (file)
@@ -2,7 +2,7 @@
 # Copyright © 2020 Pleroma Authors <https://pleroma.social/>
 # SPDX-License-Identifier: AGPL-3.0-only
 defmodule Pleroma.EarmarkRendererTest do
-  use ExUnit.Case
+  use Pleroma.DataCase, async: true
 
   test "Paragraph" do
     code = ~s[Hello\n\nWorld!]
index 8124634547b5b8071556013f81ff5dd179392056..a8471e2e37d83473aea8aeec3959bf532a576c0d 100644 (file)
@@ -4,7 +4,7 @@
 
 defmodule Pleroma.EctoType.ActivityPub.ObjectValidators.DateTimeTest do
   alias Pleroma.EctoType.ActivityPub.ObjectValidators.DateTime
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
 
   test "it validates an xsd:Datetime" do
     valid_strings = [
index 732e2365ff91f52eaa60e8070f16aeb2fe218f1f..3b600685466a51ffe0fd2a2e2e0aef713603e2f1 100644 (file)
@@ -4,7 +4,7 @@
 
 defmodule Pleroma.EctoType.ActivityPub.ObjectValidators.ObjectIDTest do
   alias Pleroma.EctoType.ActivityPub.ObjectValidators.ObjectID
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
 
   @uris [
     "http://lain.com/users/lain",
index 2e6a0c83d45089134d4a87e50a44e024648fa62b..b7eb59ab0db3c457a87a60adb0ec87034fb870df 100644 (file)
@@ -4,7 +4,7 @@
 
 defmodule Pleroma.EctoType.ActivityPub.ObjectValidators.RecipientsTest do
   alias Pleroma.EctoType.ActivityPub.ObjectValidators.Recipients
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
 
   test "it asserts that all elements of the list are object ids" do
     list = ["https://lain.com/users/lain", "invalid"]
index 7eddd2388e9f750a005781db654a8a379628dc3c..154363f684ce095ce1fd29eb5a08cea2ae3aab15 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.EctoType.ActivityPub.ObjectValidators.SafeTextTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
 
   alias Pleroma.EctoType.ActivityPub.ObjectValidators.SafeText
 
index 0da0699ccddf3a4c8144372f9d260a54c2989291..9aaf7b04fcf1a1541732eb9eae4615e48e476eb8 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Emails.AdminEmailTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
   import Pleroma.Factory
 
   alias Pleroma.Emails.AdminEmail
index a214e59a7d1a0e944d54ddd5605adc8b152182f2..bd21d8dec52b8f14bc8b5fefc532eaea39dd68c1 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Emails.UserEmailTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
 
   alias Pleroma.Emails.UserEmail
   alias Pleroma.Web.Endpoint
index 12af6cd8b1e0b5c545191594bb15838bf5e83b61..096d23ca680ff6bae9fc8f41de10b40b584fcc7a 100644 (file)
@@ -4,7 +4,7 @@
 
 defmodule Pleroma.Emoji.FormatterTest do
   alias Pleroma.Emoji.Formatter
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
 
   describe "emojify" do
     test "it adds cool emoji" do
index 70d1eaa1b638d58df8891892be48018a751fa1b0..158dfee06de2d25d3b097340b483672b29cd706c 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Emoji.PackTest do
-  use ExUnit.Case, async: true
+  use Pleroma.DataCase
   alias Pleroma.Emoji.Pack
 
   @emoji_path Path.join(
index 9cfd7b46b3d93ca14c98294e445085dce2357259..c99c9ef4c863fde77a2291df7b5ea2da455dedbf 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.EmojiTest do
-  use ExUnit.Case
+  use ExUnit.Case, async: true
   alias Pleroma.Emoji
 
   describe "is_unicode_emoji?/1" do
index 0a5c4426aaf69a2849816ef18cad8033a0044fd6..da9515902d93545aaaeb9a3f0eae6fb8f119520a 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.FilterTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
 
   import Pleroma.Factory
 
index 17a468abb48a12725bbd2a620efbd464584bc682..f0d2c38461fee476bec36900d663de5b7226e33b 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.FollowingRelationshipTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
 
   alias Pleroma.FollowingRelationship
   alias Pleroma.Web.ActivityPub.InternalFetchActor
index e341e698359abc8b71093f8d6ac99209f327c439..a1bc25d2546ee348e04176e800abf623b072dba4 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.HealthcheckTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
   alias Pleroma.Healthcheck
 
   test "system_info/0" do
index 7d37568844915adae8a6f95b8e100a1bae7760ad..9737f24588dd4b3a3daf401ef42d4ca3c6eca252 100644 (file)
@@ -6,7 +6,7 @@ defmodule Pleroma.HTMLTest do
   alias Pleroma.HTML
   alias Pleroma.Object
   alias Pleroma.Web.CommonAPI
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
 
   import Pleroma.Factory
 
index 80589c73d5f452cdccb64d4b164afc23055464f7..487d2e7c17eb14a08f4b90dd433405e407f4f81d 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.HTTP.AdapterHelper.GunTest do
-  use ExUnit.Case, async: true
+  use ExUnit.Case
   use Pleroma.Tests.Helpers
 
   import Mox
index bb8e795b723c5f1bf7e31aeee47a901e8cbe9e03..4a7dbda71aa916d50c307c9ec98b99099298c46a 100644 (file)
@@ -3,6 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Integration.MastodonWebsocketTest do
+  # Needs a streamer, needs to stay synchronous
   use Pleroma.DataCase
 
   import ExUnit.CaptureLog
index 9e8528cbafaee754535df713da5267282ae1899b..55a7aa1bc8f00fdea5803722d56e1b4671373e01 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.KeysTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
 
   alias Pleroma.Keys
 
index b5572cbae916368be2a744299933334219aa936a..854e276f155630631f044d4f1a7dfbad3e78d655 100644 (file)
@@ -4,7 +4,7 @@
 
 defmodule Pleroma.ListTest do
   alias Pleroma.Repo
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
 
   import Pleroma.Factory
 
index 7b3943c7be5ca907b3c990daa46c72abc7d2a104..3055f1ce24e14372c82e76e3a39a19435dc15696 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.MarkerTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
   alias Pleroma.Marker
 
   import Pleroma.Factory
index 41adb1e9621a7f060fc7bcbfb824d121eb9220cb..c3eaf40b6b147b61545d5e72b659d37d12b8b6db 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.MFA.BackupCodesTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
 
   alias Pleroma.MFA.BackupCodes
 
index 9edb6fd54d130c4dfc4236ac94d0cf9bd302c0e8..8c09bf447c1baa773d09886a0be42a28b4793f45 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.MFA.TOTPTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
 
   alias Pleroma.MFA.TOTP
 
index 8875cefd992650b8e1e31d497271dff20f0beb40..cd1f7d0aff8b394c9845847109e5fa0e1e5613d6 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.MFATest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
 
   import Pleroma.Factory
   alias Pleroma.MFA
index 2a62a2b00212ecf2f21799599b5b222c4d7ba0f7..6fe8a11acd39c4f0a5e70c09f32c0adf7b4f50fe 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.MigrationHelper.NotificationBackfillTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
 
   alias Pleroma.Activity
   alias Pleroma.MigrationHelper.NotificationBackfill
index 03b32a0609a69eedc50b3ca954df6bab1ef0c41f..d1e0e1e6b33a626a120662e156f1848055e639d9 100644 (file)
@@ -6,7 +6,7 @@ defmodule Pleroma.ModerationLogTest do
   alias Pleroma.Activity
   alias Pleroma.ModerationLog
 
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
 
   import Pleroma.Factory
 
index e526f23e89731c27fa0c63476aaced445748ab38..5ee1e60aeeae301876fe3ab90224c6655b264337 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.PaginationTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
 
   import Pleroma.Factory
 
index 7db8e3664ab92e5f02a29b0223d397fbe08ca9cc..462ab452bdc2c10d71f1a9abe1d309bd65fe6376 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.RegistrationTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
 
   import Pleroma.Factory
 
index 432055e459e6b81b44b6c2048653a50ad3162b26..adfed11429c99cd10eb45895ba85ad75a3cff95e 100644 (file)
@@ -4,7 +4,7 @@
 
 defmodule Pleroma.Repo.Migrations.FixLegacyTagsTest do
   alias Pleroma.User
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
   import Pleroma.Factory
   import Pleroma.Tests.Helpers
 
index 53d05a55aef4ef0834cc2225a815c06759ba6232..5dbe9d7b0e119ee499eaca00248c9129d15a6ad1 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Repo.Migrations.MoveWelcomeSettingsTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
   import Pleroma.Factory
   import Pleroma.Tests.Helpers
   alias Pleroma.ConfigDB
index 155791be22fd1fb2905ca0c82d97d9d1f14d4f01..eaddef3a683e912a8f2ab32bdee81a541bad3c3d 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.RepoTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
   import Pleroma.Factory
 
   alias Pleroma.User
index 25c1d6a6122052bac91dac8a42523a46d396843a..cc4561eea9066e10f9af55eda44323392be778b8 100644 (file)
@@ -4,7 +4,7 @@
 
 defmodule Pleroma.ReportNoteTest do
   alias Pleroma.ReportNote
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
   import Pleroma.Factory
 
   test "create/3" do
index 8df63de6550792385024933b36b3f92374a83ef7..0a2c169cef8969119d69182e090df62fb988203b 100644 (file)
@@ -3,8 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.ReverseProxyTest do
-  use Pleroma.Web.ConnCase, async: true
-
+  use Pleroma.Web.ConnCase
   import ExUnit.CaptureLog
   import Mox
 
index 8b12745452f318dd85e504e6cb8bcd98528701e9..6d70f10266f7918995cc388dd589eefe044f93b5 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.SafeJsonbSetTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
 
   test "it doesn't wipe the object when asked to set the value to NULL" do
     assert %{rows: [[%{"key" => "value", "test" => nil}]]} =
index 74bf785b0ef0dc1991b8e1fab366c421a9fe566b..6c2fd5726af985587c0b25ef54ad1d02c15e7e86 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.StatsTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
 
   import Pleroma.Factory
 
index 92a3d7df32e8175cff045d46f876a67d09673749..6559cbb5017e2e9bf3bc6b90660aca572f7871c6 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Upload.Filter.DedupeTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
 
   alias Pleroma.Upload
   alias Pleroma.Upload.Filter.Dedupe
index 6b978b64cbf69a8a8d4941cc62c276d31ba1b4d0..b5a5ba18d59bcc1f236a991ba1346c66dae6f8dd 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Upload.Filter.ExiftoolTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
   alias Pleroma.Upload.Filter
 
   test "apply exiftool filter" do
index 1ce7be485607ef3ef723a4bf7fc90cdd3f408ed6..5b377d5803ea1b1e46b77371e52ba5dd6b9d377f 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Uploaders.LocalTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
   alias Pleroma.Uploaders.Local
 
   describe "get_file/1" do
index 308da216a3a0fd97f1188751658df31bc2dc34af..701130380ab34757d92f3162437060bb85fb4e12 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.User.NotificationSettingTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
 
   alias Pleroma.User.NotificationSetting
 
index f12406097f1e460ec732b163f49aa93d6708c8ae..da4982065c194bb80377b1bbcd9dfd4d4582b45c 100644 (file)
@@ -5,7 +5,7 @@
 defmodule Pleroma.UserRelationshipTest do
   alias Pleroma.UserRelationship
 
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
 
   import Pleroma.Factory
 
index 3c795f5ac407a35869d222857e9df41799f9ba2b..49bbc271d40db0270883e79b393b221b8f140d84 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.ActivityPub.MRF.AntiFollowbotPolicyTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
   import Pleroma.Factory
 
   alias Pleroma.Web.ActivityPub.MRF.AntiFollowbotPolicy
index 9a283f27d6b3330532e06ed5fd525a56f022eb96..19ea491c0ff13762325399d2f3360e90365f56dd 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.ActivityPub.MRF.EnsureRePrependedTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
 
   alias Pleroma.Activity
   alias Pleroma.Object
index 86dd9ddae4430802b1c0dfdcbe713f21388d6a0e..b5f401ad23b64d59626c24a7a6f8c2820800872d 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.ActivityPub.MRF.ForceBotUnlistedPolicyTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
   import Pleroma.Factory
 
   alias Pleroma.Web.ActivityPub.MRF.ForceBotUnlistedPolicy
index 64ea61dd441be97756913ded6f9be75b6ae66f71..d03456b34fcf0833ad934423f77c0fa4674a7590 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.ActivityPub.MRF.NoPlaceholderTextPolicyTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
   alias Pleroma.Web.ActivityPub.MRF.NoPlaceholderTextPolicy
 
   test "it clears content object" do
index 9b39c45bdb28cb71226ab1c1a8aa1b726d9c8634..5fccf7760a24b78042f577b74aeee1188ce5f2ca 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.ActivityPub.MRF.NormalizeMarkupTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
   alias Pleroma.Web.ActivityPub.MRF.NormalizeMarkup
 
   @html_sample """
index ffc30ba6281e03140c3ac41bf2d5bf07b95f0d98..4f289739f8a94ce1b032bc4e6174ae69abce074c 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.ActivityPub.MRF.TagPolicyTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
   import Pleroma.Factory
 
   alias Pleroma.Web.ActivityPub.MRF.TagPolicy
index d6111ba414c498362bd466bcd771f3d46ab43be9..bafa2a67218df7703c868d10bf25eab230b7b1bd 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.ActivityPub.ObjectValidators.AcceptValidationTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
 
   alias Pleroma.Web.ActivityPub.Builder
   alias Pleroma.Web.ActivityPub.ObjectValidator
index 4771c4698d20e41ad320c20ef688da9e0df03a07..9613dea9bf03a11a54fb5348a3e102ec6418d9f8 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.ActivityPub.ObjectValidators.AnnounceValidationTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
 
   alias Pleroma.Object
   alias Pleroma.Web.ActivityPub.Builder
index cc6dab872d95c6534f3ebf0a69bf02ddc462d53d..1f992b3973c8afe98f152705058a102c3faab206 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.ActivityPub.ObjectValidators.ArticleNoteValidatorTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
 
   alias Pleroma.Web.ActivityPub.ObjectValidators.ArticleNoteValidator
   alias Pleroma.Web.ActivityPub.Utils
index 2e1975a7995504c0c822e9107c893a0f6d8cd1e3..45e1d8852066a75cdfb9715812e0ffb0d3bff281 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.ActivityPub.ObjectValidators.AttachmentValidatorTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
 
   alias Pleroma.Web.ActivityPub.ActivityPub
   alias Pleroma.Web.ActivityPub.ObjectValidators.AttachmentValidator
index c08d4b2e89ae463aeab02599f1912dde55b9b5e2..d133aeb1a8975600966dd2a1a9dec141363edc5c 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.ActivityPub.ObjectValidators.BlockValidationTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
 
   alias Pleroma.Web.ActivityPub.Builder
   alias Pleroma.Web.ActivityPub.ObjectValidator
index 02683b899d762630c89cb5d3084f0ddbcfdc1908..57de83c8a0cb7571068ae8678c988e4e31496a8f 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.ActivityPub.ObjectValidators.DeleteValidationTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
 
   alias Pleroma.Object
   alias Pleroma.Web.ActivityPub.Builder
index 582e6d7852b54211dbf56a8ac1847c002e559ab5..342cfeef8ff1853c9c64029485d7e8b5057ddefa 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.ActivityPub.ObjectValidators.EmojiReactHandlingTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
 
   alias Pleroma.Web.ActivityPub.Builder
   alias Pleroma.Web.ActivityPub.ObjectValidator
index 6e1378be22f352dd6294783a26d6486c74c0d014..0f77ac8df36213ce430e6cfadc8806874c189da8 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.ActivityPub.ObjectValidators.FollowValidationTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
 
   alias Pleroma.Web.ActivityPub.Builder
   alias Pleroma.Web.ActivityPub.ObjectValidator
index 2c033b7e2df079513f122651682bb08cee45c64d..4cda3742daf2027b1327dfb769744e607fc1d32a 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.ActivityPub.ObjectValidators.LikeValidationTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
 
   alias Pleroma.Web.ActivityPub.ObjectValidator
   alias Pleroma.Web.ActivityPub.ObjectValidators.LikeValidator
index 370bb6e5cf95cc90f7cb17acf996f83ef181fb62..69f5e8ac49abdb947981f67308a9d2e12a2d837c 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.ActivityPub.ObjectValidators.RejectValidationTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
 
   alias Pleroma.Web.ActivityPub.Builder
   alias Pleroma.Web.ActivityPub.ObjectValidator
index 75bbcc4b6b1ce0fcab28703f4f127151fb1af388..dc85d1ac31ccdf6fa278fc3c8ff5c9df0aae4b8c 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.ActivityPub.ObjectValidators.UndoHandlingTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
 
   alias Pleroma.Web.ActivityPub.Builder
   alias Pleroma.Web.ActivityPub.ObjectValidator
index 5e80cf7311330e8a13cf7a21838d0b2a054f00c9..2c4a50bfd2f1dfc5296c74000b7e8c47a68fe2aa 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.ActivityPub.ObjectValidators.UpdateHandlingTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
 
   alias Pleroma.Web.ActivityPub.Builder
   alias Pleroma.Web.ActivityPub.ObjectValidator
index 210a06563b467f5d20e3cdb0deda8bb8f016b6de..d568d825ba7e7c200cd6b4f1d71a5b458104e7a2 100644 (file)
@@ -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)
-
-        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
+      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(
+                 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)
-
-        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
+      FederatorMock
+      |> expect(:publish, fn ^activity -> :ok 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)
-
-        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
+      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 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)
-
-        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
+      ConfigMock
+      |> expect(:get, fn [:instance, :federating] -> false end)
+
+      assert {:ok, ^activity, ^meta} =
+               Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity, meta)
     end
   end
 end
index 3284980f75ca62170136203db24196b76bfd4374..a7cd732bb7513c0f4491b97bcdd91588fae1555c 100644 (file)
@@ -84,7 +84,7 @@ defmodule Pleroma.Web.ActivityPub.RelayTest do
              )
 
       Pleroma.Repo.delete(user)
-      Cachex.clear(:user_cache)
+      User.invalidate_cache(user)
 
       assert {:ok, %Activity{} = activity} = Relay.unfollow(user_ap_id, %{force: true})
 
index 485216487137c7c78397821199981639b201ce1e..d356fcc7219a1419d0f9092ceb43068c87afd8b8 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.ActivityPub.Transmogrifier.AcceptHandlingTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
 
   alias Pleroma.User
   alias Pleroma.Web.ActivityPub.Transmogrifier
index 679c33c6cac1fe25ef81157a15662436afb3f10d..6adad88f5ae92ff3e4c22f29d360acad41df5fc0 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.ActivityPub.Transmogrifier.BlockHandlingTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
 
   alias Pleroma.Activity
   alias Pleroma.User
index cffaa7c441437347b4a6ca993b750119d6b6d2e0..1f9e73ff89af821c89d83f269b00fdaef78c33d3 100644 (file)
@@ -51,6 +51,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.DeleteHandlingTest do
       Object.normalize(activity.data["object"])
       |> Repo.delete()
 
+    # TODO: mock cachex
     Cachex.del(:object_cache, "object:#{object.data["id"]}")
 
     deleting_user = insert(:user)
index aea4ed6f8c45f53124260089cbb92a023a2c0beb..1ebf6b1e8e96d62888913bb67f1234d35060c828 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.ActivityPub.Transmogrifier.EmojiReactHandlingTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
 
   alias Pleroma.Activity
   alias Pleroma.Object
index 967bad1512e35ad89d9d23e14df5e834bbd1d00e..35211b8f230a073e38cf8d426459a11d1dc8a178 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.ActivityPub.Transmogrifier.LikeHandlingTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
 
   alias Pleroma.Activity
   alias Pleroma.Web.ActivityPub.Transmogrifier
index 5a3bef7921bf187ea37474d1a51fa6fa76aeda64..851236758d7ad7cec7a03eddd411f385d6f58e9d 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.ActivityPub.Transmogrifier.RejectHandlingTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
 
   alias Pleroma.Activity
   alias Pleroma.User
index fcfc7b4b66849fbe965427d72ecfecb3ab75f9fa..107121ef82100c973a9e73c805edb7270e417f29 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.ActivityPub.Transmogrifier.UndoHandlingTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
 
   alias Pleroma.Activity
   alias Pleroma.Object
index c62d5e139030269b3e9bca78864bab931d5ec1cd..8ed5e5e9073c101a6149952b42f78a21f579c44c 100644 (file)
@@ -103,7 +103,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.UserUpdateHandlingTest do
              %{"name" => "foo1", "value" => "updated"}
            ]
 
-    Pleroma.Config.put([:instance, :max_remote_account_fields], 2)
+    clear_config([:instance, :max_remote_account_fields], 2)
 
     update_data =
       update_data
index be9cd7d13eb45f6f5a3bd0326a9f7f9be2b4b512..2263b6091536f24b5c59d923d32f1a1067f11e87 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.ActivityPub.UtilsTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
   alias Pleroma.Activity
   alias Pleroma.Object
   alias Pleroma.Repo
index 98c7c9d0966ab5c60b766b9c9dbeeb9863cf60d2..fe6ddf0d683c1c50867178ecb8ad881bb2885b3d 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.ActivityPub.UserViewTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
   import Pleroma.Factory
 
   alias Pleroma.User
index 836d4499419b00cbeb3966f56c54f5a133296485..1ec41aa1947c7073de5133a9a25f9d2573a13653 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.ActivityPub.VisibilityTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
 
   alias Pleroma.Activity
   alias Pleroma.Web.ActivityPub.Visibility
@@ -159,7 +159,7 @@ defmodule Pleroma.Web.ActivityPub.VisibilityTest do
          user: user
        } do
     Repo.delete(user)
-    Cachex.clear(:user_cache)
+    Pleroma.User.invalidate_cache(user)
     refute Visibility.is_private?(direct)
   end
 
index 5aefa1e603f18fad18abb025a1d72b8950486c60..dead1c09e4e887c426d41169491adaea1773e579 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.AdminAPI.ChatControllerTest do
-  use Pleroma.Web.ConnCase
+  use Pleroma.Web.ConnCase, async: true
 
   import Pleroma.Factory
 
index e6b203e7470685ba5838df176072fd93ed834a2b..df5d74d459674e8ebd9a47b12392b65fc8a9bf82 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
-  use Pleroma.Web.ConnCase, async: true
+  use Pleroma.Web.ConnCase
 
   import ExUnit.CaptureLog
   import Pleroma.Factory
index f243d1fb29787508176b4cc6e687750456242a01..62fb9592a0b9dc4eede406edada71493e91d3b13 100644 (file)
@@ -12,10 +12,6 @@ defmodule Pleroma.Web.AdminAPI.MediaProxyCacheControllerTest do
 
   setup do: clear_config([:media_proxy])
 
-  setup do
-    on_exit(fn -> Cachex.clear(:banned_urls_cache) end)
-  end
-
   setup do
     admin = insert(:user, is_admin: true)
     token = insert(:oauth_admin_token, user: admin)
index cbfc2e7b0655b22e4f86b58b334d4f3ab26d33f4..2ab2f2f6d52a3d77c94a68f16552f6dbca206bfa 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.AdminAPI.ReportControllerTest do
-  use Pleroma.Web.ConnCase
+  use Pleroma.Web.ConnCase, async: true
 
   import Pleroma.Factory
 
index a18ef9e4b31fe2bc4db9d10906fa1e2826ea0fd6..40714c8a45a2cdc74d363965b8d109164bb62f64 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.AdminAPI.StatusControllerTest do
-  use Pleroma.Web.ConnCase
+  use Pleroma.Web.ConnCase, async: true
 
   import Pleroma.Factory
 
index 9bc58640c7901c8e584ebaedba643cbeca6cdf2a..fdf22a8e6d91e6707b3c9e1fbef3a9a4e5ce29c0 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.AdminAPI.SearchTest do
-  use Pleroma.Web.ConnCase
+  use Pleroma.Web.ConnCase, async: true
 
   alias Pleroma.Web.AdminAPI.Search
 
index e6c5aaa7fa4b3c81c2489e25afb3ea00db647c61..390d7bbebf87cc1f67f3ffa74db037b6065cb4c0 100644 (file)
@@ -2,7 +2,7 @@
 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
 # SPDX-License-Identifier: AGPL-3.0-only
 defmodule Pleroma.Web.AdminAPI.ModerationLogViewTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
 
   alias Pleroma.Web.AdminAPI.ModerationLogView
 
index 5a02292be77a1d66ee621c77d27db13187fa3a7f..ff345320875e4368554e96b60e429cbd5ae4eb13 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.AdminAPI.ReportViewTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
 
   import Pleroma.Factory
 
index d54253343d297facb8ccbdfc538fccc2e3b96b16..862eb80517322059c0fd410738386bea8b388b68 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.Auth.AuthenticatorTest do
-  use Pleroma.Web.ConnCase
+  use Pleroma.Web.ConnCase, async: true
 
   alias Pleroma.Web.Auth.Authenticator
   import Pleroma.Factory
index bf6e3d2fc2542c24baea459ed666cb2b832e9fac..e56c1e1e8ba4fdf42b74f9e123719e1ed436652d 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.Auth.BasicAuthTest do
-  use Pleroma.Web.ConnCase
+  use Pleroma.Web.ConnCase, async: true
 
   import Pleroma.Factory
 
index 1ba0dfecc53c8e1dfc20ff4252846880b7dcb5b9..4539ffe87d20c38aaccd9386195abb9d928d4aae 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.Auth.PleromaAuthenticatorTest do
-  use Pleroma.Web.ConnCase
+  use Pleroma.Web.ConnCase, async: true
 
   alias Pleroma.Web.Auth.PleromaAuthenticator
   import Pleroma.Factory
index 84d4cd8402f1a177e5f9d5cec348982dee2bb661..7f99d62bf34e2169c851d2695707ff4dbf202d9e 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.Auth.TOTPAuthenticatorTest do
-  use Pleroma.Web.ConnCase
+  use Pleroma.Web.ConnCase, async: true
 
   alias Pleroma.MFA
   alias Pleroma.MFA.BackupCodes
index 875addc96521b737dcec41598989818f9eee0771..d0cae3d42b70f522414b663dc994ccb84762482b 100644 (file)
@@ -3,6 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.Endpoint.MetricsExporterTest do
+  # Modifies AppEnv, has to stay synchronous
   use Pleroma.Web.ConnCase
 
   alias Pleroma.Web.Endpoint.MetricsExporter
index 3361c8669319313f1ee3a8586b6bf2be45a66648..f6285853a16d7a5db189fdcd48eac676f53cbc38 100644 (file)
@@ -1411,8 +1411,6 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
                |> json_response_and_validate_schema(:ok)
 
       assert Token |> Repo.get_by(token: access_token) |> Repo.preload(:user) |> Map.get(:user)
-
-      Cachex.del(:used_captcha_cache, token)
     end
 
     test "returns 400 if any captcha field is not provided", %{conn: conn} do
index d7834c876d820b10092cf9c61a278242aee555e8..ce957054bf0f7fda5068c0f18612cb212df8a4c6 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.MastodonAPI.AuthControllerTest do
-  use Pleroma.Web.ConnCase
+  use Pleroma.Web.ConnCase, async: true
 
   alias Pleroma.Config
   alias Pleroma.Repo
index b00615ac9ece5c67f23c4d7698b3dfb57c632989..a03513e06bf7c615456abc39de73f5e81fd9f5f2 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.MastodonAPI.ConversationControllerTest do
-  use Pleroma.Web.ConnCase
+  use Pleroma.Web.ConnCase, async: true
 
   alias Pleroma.Conversation.Participation
   alias Pleroma.User
index 66465450003c213770b0b7ffa583eeee019b9d75..b10aa6966fdf2283d02ee51273267972d0bcfe1f 100644 (file)
@@ -3,6 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.MastodonAPI.DomainBlockControllerTest do
+  # TODO: Should not need Cachex
   use Pleroma.Web.ConnCase
 
   alias Pleroma.User
index 0d426ec342ccf788f7b3d36b02d991d8891cdf37..e639cdde18ba5d3413d1e9418faf103acd2d4c17 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.MastodonAPI.FilterControllerTest do
-  use Pleroma.Web.ConnCase
+  use Pleroma.Web.ConnCase, async: true
 
   alias Pleroma.Web.MastodonAPI.FilterView
 
index b977b41ae0ab1fec866ffad9d786f20cb4fd25ed..f0a466212ffdd1de1d01257b3cd3d24a5dc65b9e 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.MastodonAPI.FollowRequestControllerTest do
-  use Pleroma.Web.ConnCase
+  use Pleroma.Web.ConnCase, async: true
 
   alias Pleroma.User
   alias Pleroma.Web.CommonAPI
index 605df6ed66b2fb841dd610067857fc7b8e603cfe..71a170240a178429e195b9add04354478c85f7fd 100644 (file)
@@ -3,6 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.MastodonAPI.InstanceControllerTest do
+  # TODO: Should not need Cachex
   use Pleroma.Web.ConnCase
 
   alias Pleroma.User
index 091ec006c67456790ca140e9fe1be4fda7fa4d93..01f64cfcc5b2f3dcfae7d7d6bc247d9e5e8cddb2 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.MastodonAPI.ListControllerTest do
-  use Pleroma.Web.ConnCase
+  use Pleroma.Web.ConnCase, async: true
 
   alias Pleroma.Repo
 
index 9f0481120df495e61ab4f4812b9ac50beb8c9e4f..ee944a67c36022dd7906cb3a0d9a54ff7010a8d2 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.MastodonAPI.MarkerControllerTest do
-  use Pleroma.Web.ConnCase
+  use Pleroma.Web.ConnCase, async: true
 
   import Pleroma.Factory
 
index f41de64485ec40bbe558dfeabf0f915da5c94806..95e27623d7111358784cb804edc7d9d9b7ab11bc 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.MastodonAPI.PollControllerTest do
-  use Pleroma.Web.ConnCase
+  use Pleroma.Web.ConnCase, async: true
 
   alias Pleroma.Object
   alias Pleroma.Web.CommonAPI
index 6636cff96c788b2b28ae7a12f87f99f7b718c640..322eb475c70a1b47255392af990f45736a6ee26c 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.MastodonAPI.ReportControllerTest do
-  use Pleroma.Web.ConnCase
+  use Pleroma.Web.ConnCase, async: true
 
   alias Pleroma.Web.CommonAPI
 
index 30d542dfa8876fa55ef45d3b83d2c9cd2413fb24..de542e5df8e654ea0e4994a02fe2df93b55ad62a 100644 (file)
@@ -67,10 +67,6 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
           "sensitive" => "0"
         })
 
-      {:ok, ttl} = Cachex.ttl(:idempotency_cache, idempotency_key)
-      # Six hours
-      assert ttl > :timer.seconds(6 * 60 * 60 - 1)
-
       assert %{"content" => "cofe", "id" => id, "spoiler_text" => "2hu", "sensitive" => false} =
                json_response_and_validate_schema(conn_one, 200)
 
index 5ef39bdb26f4958871b1b8e0f50d547e5cb77254..4bb08575042f84683fb710030f483f7c286cfa76 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.MastodonAPI.SubscriptionControllerTest do
-  use Pleroma.Web.ConnCase
+  use Pleroma.Web.ConnCase, async: true
 
   import Pleroma.Factory
 
index 7f08e187cfcfe650abae8c5b554d0a63b6a2f00c..c3471266a3f0f1170d185f171be5b16820e93595 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.MastodonAPI.SuggestionControllerTest do
-  use Pleroma.Web.ConnCase
+  use Pleroma.Web.ConnCase, async: true
 
   setup do: oauth_access(["read"])
 
index bb4bc43965fb2274c7016ff937e6bc0fa498d4ec..be5bf68a33c33f2427d32d135149cc870f7cb7e1 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
-  use Pleroma.Web.ConnCase
+  use Pleroma.Web.ConnCase, async: true
 
   describe "empty_array/2 (stubs)" do
     test "GET /api/v1/accounts/:id/identity_proofs" do
index 687fe55851e4d557eb712154ad95dbf2f1cf4228..cf7f464beafddab5bd6678d898d74773877260e5 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.MastodonAPI.MastodonAPITest do
-  use Pleroma.Web.ConnCase
+  use Pleroma.Web.ConnCase, async: true
 
   alias Pleroma.Notification
   alias Pleroma.ScheduledActivity
index ed1921c9145d2b503b6a1c7160bdab4cbba89961..023726468ef070892b7ee9808ddcc633da2753ea 100644 (file)
@@ -11,8 +11,6 @@ defmodule Pleroma.Web.MastodonAPI.UpdateCredentialsTest do
   import Mock
   import Pleroma.Factory
 
-  setup do: clear_config([:instance, :max_account_fields])
-
   describe "updating credentials" do
     setup do: oauth_access(["write:accounts"])
     setup :request_content_type
@@ -446,7 +444,7 @@ defmodule Pleroma.Web.MastodonAPI.UpdateCredentialsTest do
                |> patch("/api/v1/accounts/update_credentials", %{"fields_attributes" => fields})
                |> json_response_and_validate_schema(403)
 
-      Pleroma.Config.put([:instance, :max_account_fields], 1)
+      clear_config([:instance, :max_account_fields], 1)
 
       fields = [
         %{"name" => "foo", "value" => "bar"},
index 20c10ba3de77a0c5b2c5a177a89129d919eefae1..f02253b682ad2d74f72dd24d3a2153066c57bccb 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.MastodonAPI.ConversationViewTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
 
   alias Pleroma.Conversation.Participation
   alias Pleroma.Web.CommonAPI
index ca99242cb719d82ecfae2621af0d7c3d525d6244..3779413329437c94481a7057086d3d4730cb1483 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.MastodonAPI.ListViewTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
   import Pleroma.Factory
   alias Pleroma.Web.MastodonAPI.ListView
 
index 48a0a6d331d3beedadeb0719dfeb1f056014ce66..a0bec758fd87e1c8677070f6edc872a196c72248 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.MastodonAPI.MarkerViewTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
   alias Pleroma.Web.MastodonAPI.MarkerView
   import Pleroma.Factory
 
index 04f73f5a015aff6e56d6f37a63225786cd4cef38..c41ac7f7f3dd5f42c04c6d04571394c6e30df4e0 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.MastodonAPI.ScheduledActivityViewTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
   alias Pleroma.ScheduledActivity
   alias Pleroma.Web.ActivityPub.ActivityPub
   alias Pleroma.Web.CommonAPI
index 6b8afc960a900e6135821a5a10668b97a6c6c2be..22717ce90bf3dc3aabefac0bd351ccfe75b0d53d 100644 (file)
@@ -160,7 +160,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
     {:ok, activity} = CommonAPI.post(user, %{status: "Hey @shp!", visibility: "direct"})
 
     Repo.delete(user)
-    Cachex.clear(:user_cache)
+    User.invalidate_cache(user)
 
     finger_url =
       "https://localhost/.well-known/webfinger?resource=acct:#{user.nickname}@localhost"
@@ -194,7 +194,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
       |> Ecto.Changeset.change(%{ap_id: "#{user.ap_id}/extension/#{user.nickname}"})
       |> Repo.update()
 
-    Cachex.clear(:user_cache)
+    User.invalidate_cache(user)
 
     result = StatusView.render("show.json", activity: activity)
 
index 981524c0e8848d738b16b7367fe1bad75460d498..c2bb535c568a6d22ce418cd612b806d1aed10c9f 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.MastodonAPI.SubscriptionViewTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
   import Pleroma.Factory
   alias Pleroma.Web.MastodonAPI.SubscriptionView, as: View
   alias Pleroma.Web.Push
index 13d0813256692f40ad817b21a4fa47d02fcb2263..c81010423b70cba2cb5be74ea2a0e982a48d23b9 100644 (file)
@@ -9,10 +9,6 @@ defmodule Pleroma.Web.MediaProxy.Invalidation.HttpTest do
   import ExUnit.CaptureLog
   import Tesla.Mock
 
-  setup do
-    on_exit(fn -> Cachex.clear(:banned_urls_cache) end)
-  end
-
   test "logs hasn't error message when request is valid" do
     mock(fn
       %{method: :purge, url: "http://example.com/media/example.jpg"} ->
index 692cbb2df59e78466e7cf6d3928fc78038eb5a0e..6940a4539760407ac9f0bf04f4c76053c80b809a 100644 (file)
@@ -3,15 +3,11 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.MediaProxy.Invalidation.ScriptTest do
-  use ExUnit.Case
+  use ExUnit.Case, async: true
   alias Pleroma.Web.MediaProxy.Invalidation
 
   import ExUnit.CaptureLog
 
-  setup do
-    on_exit(fn -> Cachex.clear(:banned_urls_cache) end)
-  end
-
   test "it logger error when script not found" do
     assert capture_log(fn ->
              assert Invalidation.Script.purge(
index aa1435ac0994b2b05cfbc278d533db0d24f04514..b7be36b470a0a8a6c9874dca05466eaa5296a7bc 100644 (file)
@@ -3,8 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.MediaProxy.InvalidationTest do
-  use ExUnit.Case
-  use Pleroma.Tests.Helpers
+  use Pleroma.DataCase
 
   alias Pleroma.Config
   alias Pleroma.Web.MediaProxy.Invalidation
@@ -15,10 +14,6 @@ defmodule Pleroma.Web.MediaProxy.InvalidationTest do
 
   setup do: clear_config([:media_proxy])
 
-  setup do
-    on_exit(fn -> Cachex.clear(:banned_urls_cache) end)
-  end
-
   describe "Invalidation.Http" do
     test "perform request to clear cache" do
       Config.put([:media_proxy, :enabled], false)
index e9b58482289684453536488c45cfdaf438dfe8dd..65cf2a01b0c4157474f83be8dab4b2727708436a 100644 (file)
@@ -10,10 +10,6 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do
   alias Pleroma.Web.MediaProxy
   alias Plug.Conn
 
-  setup do
-    on_exit(fn -> Cachex.clear(:banned_urls_cache) end)
-  end
-
   describe "Media Proxy" do
     setup do
       clear_config([:media_proxy, :enabled], true)
index e6c990242f2422017950653fc4893c3d84820c59..6d22317d26b3d09809a1b0ed9242f16bd17c6fda 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.Metadata.PlayerViewTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
 
   alias Pleroma.Web.Metadata.PlayerView
 
index e6e5cc5ed894ffa7e79f27fcc4383c0416a0aa0d..c7359e00bc2e55e3624f2175ffe00ab9e5a5788a 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.Metadata.Providers.FeedTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
   import Pleroma.Factory
   alias Pleroma.Web.Metadata.Providers.Feed
 
index 2293d6e1344f854c023b4b49419eca1e292e67f8..ae449c052ab257be442f40c976f0ecf81d9890f1 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.Metadata.Providers.RelMeTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
   import Pleroma.Factory
   alias Pleroma.Web.Metadata.Providers.RelMe
 
index 8183256d8536e04bf29de4868b1b3fd2dcdcaf15..3794db766e9f3f45f1c83f3639724f993cb277bd 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.Metadata.UtilsTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
   import Pleroma.Factory
   alias Pleroma.Web.Metadata.Utils
 
index e3a8aa3d872a082c1bc7b8a1e69f396bfcd87247..4590e1296e64e3b56349518f9f35fc356a499c48 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.MongooseIMControllerTest do
-  use Pleroma.Web.ConnCase
+  use Pleroma.Web.ConnCase, async: true
   import Pleroma.Factory
 
   test "/user_exists", %{conn: conn} do
index 993a490e0519538c37f1ca17d4cdab3686d87929..24d7049f18d54d984839a29cd2948684043428a4 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.OAuth.AppTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
 
   alias Pleroma.Web.OAuth.App
   import Pleroma.Factory
index d74b26cf8a48318d8c39d6127de0a25970f25f64..d1920962ceb1b30b3fc01994e30565155428c70b 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.OAuth.AuthorizationTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
   alias Pleroma.Web.OAuth.App
   alias Pleroma.Web.OAuth.Authorization
   import Pleroma.Factory
index 6ecd0f6c9223524fe76d14c2620a18849d921e2b..bc50d8d18d7725e5b6c41588e5d688f6cee5450f 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.OAuth.MFAControllerTest do
-  use Pleroma.Web.ConnCase
+  use Pleroma.Web.ConnCase, async: true
   import Pleroma.Factory
 
   alias Pleroma.MFA
index a610d92f865a1d7d95f5f8b981169169cb910670..3444692ec8b4a5545dd22009851d91707d71e4c3 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.OAuth.Token.UtilsTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
   alias Pleroma.Web.OAuth.Token.Utils
   import Pleroma.Factory
 
index c88b9cc9892cfab28c36f78b49e1cd73a00713e9..866f1c00acfe9899d879d91c4df7b682aa7c00fd 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.OAuth.TokenTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
   alias Pleroma.Repo
   alias Pleroma.Web.OAuth.App
   alias Pleroma.Web.OAuth.Authorization
index a6c9d0c1b56bb26a247ff3963f5c59df72bb5ca4..415c3decdbca7ffb24d54fdf0648c94182fd29fb 100644 (file)
@@ -394,11 +394,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)
index f2feeaaef1f111220cdf4e21157ee653a08bcc54..c8c2433aea9b3c4d2611abc5a7577173692d18ca 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.PleromaAPI.ConversationControllerTest do
-  use Pleroma.Web.ConnCase
+  use Pleroma.Web.ConnCase, async: true
 
   alias Pleroma.Conversation.Participation
   alias Pleroma.Repo
index 289119d4531e78ee96715ae48964f4b22d199012..5f8fa03f670c8c07b8d2b89351abfd7fd965c13d 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.PleromaAPI.MascotControllerTest do
-  use Pleroma.Web.ConnCase
+  use Pleroma.Web.ConnCase, async: true
 
   alias Pleroma.User
 
index bb4fe6c4992d9f93ec78eb6fe46dfc52e8666e82..03af4d70c4cc0386660fc30e5edaee229e887f38 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.PleromaAPI.NotificationControllerTest do
-  use Pleroma.Web.ConnCase
+  use Pleroma.Web.ConnCase, async: true
 
   alias Pleroma.Notification
   alias Pleroma.Repo
index f39c07ac649ea52986a477c3c728dcd13680a33e..4ab6d91329f514e950e9e52c14555894db13f817 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.PleromaAPI.ScrobbleControllerTest do
-  use Pleroma.Web.ConnCase
+  use Pleroma.Web.ConnCase, async: true
 
   alias Pleroma.Web.CommonAPI
 
index 22988c88158349c0c95e5be460032e0acc58ae22..8d4e0104af482a80df12373690eb92c39dac5d3f 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.PleromaAPI.TwoFactorAuthenticationControllerTest do
-  use Pleroma.Web.ConnCase
+  use Pleroma.Web.ConnCase, async: true
 
   import Pleroma.Factory
   alias Pleroma.MFA.Settings
index 02484b705b7ccd380fd60d41d1eb5b5ea2602ba1..b60b597e857e16893ab84eb31df686c3c770f7d6 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.PleromaAPI.ChatViewTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
 
   alias Pleroma.Chat
   alias Pleroma.Chat.MessageReference
index 0f43cbdc3adedd0f5a5980932658891fb872f25c..113b8f690185c049da990e3881e39cd0b043f0f3 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.PleromaAPI.ScrobbleViewTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
 
   alias Pleroma.Web.PleromaAPI.ScrobbleView
 
index fcf3d2be80f9b99418bf14f85818e1e71ac35537..c775787ca379c38b3dfe9ca79b804eaf8dac6d50 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.Plugs.CacheControlTest do
-  use Pleroma.Web.ConnCase
+  use Pleroma.Web.ConnCase, async: true
   alias Plug.Conn
 
   test "Verify Cache-Control header on static assets", %{conn: conn} do
index 93a66f5d30bba870188ad8d63b1ea7f3a95fe9da..0e5fa6f3692a43ac7fe440591dc37ffb02f89244 100644 (file)
@@ -3,7 +3,8 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.Plugs.CacheTest do
-  use ExUnit.Case, async: true
+  # Relies on Cachex, has to stay synchronous
+  use Pleroma.DataCase
   use Plug.Test
 
   alias Pleroma.Web.Plugs.Cache
@@ -24,11 +25,6 @@ defmodule Pleroma.Web.Plugs.CacheTest do
 
   @ttl 5
 
-  setup do
-    Cachex.clear(:web_resp_cache)
-    :ok
-  end
-
   test "caches a response" do
     assert @miss_resp ==
              conn(:get, "/")
index 211443a55033f91bfd88d928a267c6c838cf8ec5..9f15f5c936fa451ae025b3c303524ab86c6d2d98 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.Plugs.EnsurePublicOrAuthenticatedPlugTest do
-  use Pleroma.Web.ConnCase, async: true
+  use Pleroma.Web.ConnCase
 
   alias Pleroma.Config
   alias Pleroma.User
index 4a7835993324159dda0e11b170189f4abf200c7f..ed8b3fc1ac34484c5055ae8d4a4e9c1c926f43cc 100644 (file)
@@ -3,7 +3,8 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.Plugs.IdempotencyPlugTest do
-  use ExUnit.Case, async: true
+  # Relies on Cachex, has to stay synchronous
+  use Pleroma.DataCase
   use Plug.Test
 
   alias Pleroma.Web.Plugs.IdempotencyPlug
index 7c83131212dda896e286c7f8be4259ce47fdd893..bae9208ec520a4a053c3311d702217aa75b14c0a 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.Plugs.UploadedMediaPlugTest do
-  use Pleroma.Web.ConnCase
+  use Pleroma.Web.ConnCase, async: true
   alias Pleroma.Upload
 
   defp upload_file(context) do
index 71c56f03a4d2a6c86a566a8f1c314ba633fa1f0a..e9c9e5f3e0e4366a3e357690c48b58847a410365 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.Plugs.UserEnabledPlugTest do
-  use Pleroma.Web.ConnCase, async: true
+  use Pleroma.Web.ConnCase
 
   alias Pleroma.Web.Plugs.UserEnabledPlug
   import Pleroma.Factory
index 83f065e27aaaa2382bddd9b1ec1036686f9fd6aa..6be03af7903d44af86f033b8e6520fb9871c9608 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.Preload.Providers.UserTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
   import Pleroma.Factory
   alias Pleroma.Web.Preload.Providers.User
 
index 2a4a8fd06269e199112c86458d213a46b31deef1..326a67963410e71c17ef096c14a25827b95c038f 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.Push.ImplTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
 
   import Pleroma.Factory
 
index 65255916d083f9788e7a70f7b777515601127490..811cb0893e8a87b74ebd858097d07894ae349c05 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.RelMeTest do
-  use ExUnit.Case
+  use Pleroma.DataCase
 
   setup_all do
     Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
index 2f17bebd7279d718f64195bdf720bf47f9ecb578..2425211387136606e2651dc0c78927cf72eda394 100644 (file)
@@ -3,7 +3,8 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.RichMedia.Parser.TTL.AwsSignedUrlTest do
-  use ExUnit.Case, async: true
+  # Relies on Cachex, needs to be synchronous
+  use Pleroma.DataCase
 
   test "s3 signed url is parsed correct for expiration time" do
     url = "https://pleroma.social/amz"
index 464d0ea2eed10825ed7210df2b4c323cc2ccb195..b3ca676373d6f7439c9a8f0a5927a041b00ea158 100644 (file)
@@ -3,11 +3,11 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.TwitterAPI.ControllerTest do
-  use Pleroma.Web.ConnCase
+  use Pleroma.Web.ConnCase, async: true
 
-  alias Pleroma.Builders.ActivityBuilder
   alias Pleroma.Repo
   alias Pleroma.User
+  alias Pleroma.Web.CommonAPI
   alias Pleroma.Web.OAuth.Token
 
   import Pleroma.Factory
@@ -36,22 +36,20 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
       other_user = insert(:user)
 
       {:ok, _activity} =
-        ActivityBuilder.insert(%{"to" => [current_user.ap_id]}, %{user: other_user})
+        CommonAPI.post(other_user, %{
+          status: "Hey @#{current_user.nickname}"
+        })
 
       response_conn =
         conn
-        |> assign(:user, current_user)
         |> get("/api/v1/notifications")
 
-      [notification] = response = json_response(response_conn, 200)
-
-      assert length(response) == 1
+      [notification] = json_response(response_conn, 200)
 
       assert notification["pleroma"]["is_seen"] == false
 
       response_conn =
         conn
-        |> assign(:user, current_user)
         |> post("/api/qvitter/statuses/notifications/read", %{"latest_id" => notification["id"]})
 
       [notification] = response = json_response(response_conn, 200)
index 6d08075cc5187e4b36eae23ab1d4f3237f11a2ac..c1f5bc5c7f08f37a5d23e29d2dad9a60360c1b1f 100644 (file)
@@ -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 = %{
index a3e784d13b7c5ff9f420e37e96a7d12cd7b61e48..dfe5b02bed67811a17cebf426c129b9389fd4fdd 100644 (file)
@@ -14,18 +14,27 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do
   import Pleroma.Factory
   import Ecto.Query
 
-  setup do
-    Tesla.Mock.mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
-    :ok
-  end
-
   setup_all do: clear_config([:instance, :federating], true)
-  setup do: clear_config([:instance])
-  setup do: clear_config([:frontend_configurations, :pleroma_fe])
   setup do: clear_config([:user, :deny_follow_blocked])
 
   describe "GET /ostatus_subscribe - remote_follow/2" do
     test "adds status to pleroma instance if the `acct` is a status", %{conn: conn} do
+      Tesla.Mock.mock(fn
+        %{method: :get, url: "https://mastodon.social/users/emelie/statuses/101849165031453009"} ->
+          %Tesla.Env{
+            status: 200,
+            headers: [{"content-type", "application/activity+json"}],
+            body: File.read!("test/fixtures/tesla_mock/status.emelie.json")
+          }
+
+        %{method: :get, url: "https://mastodon.social/users/emelie"} ->
+          %Tesla.Env{
+            status: 200,
+            headers: [{"content-type", "application/activity+json"}],
+            body: File.read!("test/fixtures/tesla_mock/emelie.json")
+          }
+      end)
+
       assert conn
              |> get(
                remote_follow_path(conn, :follow, %{
@@ -36,6 +45,15 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do
     end
 
     test "show follow account page if the `acct` is a account link", %{conn: conn} do
+      Tesla.Mock.mock(fn
+        %{method: :get, url: "https://mastodon.social/users/emelie"} ->
+          %Tesla.Env{
+            status: 200,
+            headers: [{"content-type", "application/activity+json"}],
+            body: File.read!("test/fixtures/tesla_mock/emelie.json")
+          }
+      end)
+
       response =
         conn
         |> get(remote_follow_path(conn, :follow, %{acct: "https://mastodon.social/users/emelie"}))
@@ -45,6 +63,15 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do
     end
 
     test "show follow page if the `acct` is a account link", %{conn: conn} do
+      Tesla.Mock.mock(fn
+        %{method: :get, url: "https://mastodon.social/users/emelie"} ->
+          %Tesla.Env{
+            status: 200,
+            headers: [{"content-type", "application/activity+json"}],
+            body: File.read!("test/fixtures/tesla_mock/emelie.json")
+          }
+      end)
+
       user = insert(:user)
 
       response =
@@ -56,7 +83,14 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do
       assert response =~ "Remote follow"
     end
 
-    test "show follow page with error when user cannot fecth by `acct` link", %{conn: conn} do
+    test "show follow page with error when user can not be fetched by `acct` link", %{conn: conn} do
+      Tesla.Mock.mock(fn
+        %{method: :get, url: "https://mastodon.social/users/not_found"} ->
+          %Tesla.Env{
+            status: 404
+          }
+      end)
+
       user = insert(:user)
 
       assert capture_log(fn ->
index 4a418dee306bc3b20505a4f5a9f8ec86fbe6be5f..5586a9a13532072a66fd66bdc196a55c08777acd 100644 (file)
@@ -428,10 +428,4 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
     assert is_binary(error)
     refute User.get_cached_by_nickname("lain")
   end
-
-  setup do
-    Supervisor.terminate_child(Pleroma.Supervisor, Cachex)
-    Supervisor.restart_child(Pleroma.Supervisor, Cachex)
-    :ok
-  end
 end
index 21e51823694d5db51772c60ed98dc9f2e60542d2..00f9e72ecbb12cb85208abe524b2a4e71a36484e 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.UploaderControllerTest do
-  use Pleroma.Web.ConnCase
+  use Pleroma.Web.ConnCase, async: true
   alias Pleroma.Uploaders.Uploader
 
   describe "callback/2" do
index 19f33a975b98e5260cfb7fb5336241dced026890..cdb84ae1e26c993f775928dc640f9994e288d59d 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.WebFingerTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
   alias Pleroma.Web.WebFinger
   import Pleroma.Factory
   import Tesla.Mock
index 75c9aa4a30ab7ae1a36908e765ccd6ffd43263f1..e00ed674510cd1ab0ed57dd8d2ecf4ef2b0f8bae 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Workers.Cron.NewUsersDigestWorkerTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
   import Pleroma.Factory
 
   alias Pleroma.Tests.ObanHelpers
index 059384c34f4eefc4f685fc734731200fd7592ac8..a4c73359dfd68fd966d4bcb7bbe981a72d93e0d6 100644 (file)
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.XmlBuilderTest do
-  use Pleroma.DataCase
+  use Pleroma.DataCase, async: true
   alias Pleroma.XmlBuilder
 
   test "Build a basic xml string from a tuple" do
diff --git a/test/support/cachex_proxy.ex b/test/support/cachex_proxy.ex
new file mode 100644 (file)
index 0000000..e296b5c
--- /dev/null
@@ -0,0 +1,40 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.CachexProxy do
+  @behaviour Pleroma.Caching
+
+  @impl true
+  defdelegate get!(cache, key), to: Cachex
+
+  @impl true
+  defdelegate stream!(cache, key), to: Cachex
+
+  @impl true
+  defdelegate put(cache, key, value, options), to: Cachex
+
+  @impl true
+  defdelegate put(cache, key, value), to: Cachex
+
+  @impl true
+  defdelegate get_and_update(cache, key, func), to: Cachex
+
+  @impl true
+  defdelegate get(cache, key), to: Cachex
+
+  @impl true
+  defdelegate fetch!(cache, key, func), to: Cachex
+
+  @impl true
+  defdelegate expire_at(cache, str, num), to: Cachex
+
+  @impl true
+  defdelegate exists?(cache, key), to: Cachex
+
+  @impl true
+  defdelegate del(cache, key), to: Cachex
+
+  @impl true
+  defdelegate execute!(cache, func), to: Cachex
+end
index 114184a9f0b5520cd57a69b5d2991e1045ace1ae..f4696adb305ec47a6466f1f70dbadc9538c3db70 100644 (file)
@@ -33,8 +33,14 @@ defmodule Pleroma.Web.ChannelCase do
   setup tags do
     :ok = Ecto.Adapters.SQL.Sandbox.checkout(Pleroma.Repo)
 
-    unless tags[:async] do
+    if tags[:async] do
+      Mox.stub_with(Pleroma.CachexMock, Pleroma.NullCache)
+      Mox.set_mox_private()
+    else
       Ecto.Adapters.SQL.Sandbox.mode(Pleroma.Repo, {:shared, self()})
+      Mox.stub_with(Pleroma.CachexMock, Pleroma.CachexProxy)
+      Mox.set_mox_global()
+      Pleroma.DataCase.clear_cachex()
     end
 
     :ok
index 47cb65a80ba102febe685a2226c0f4153031be24..02f49c5906a2847c4c2d6aff7d8c0b1b95512765 100644 (file)
@@ -116,12 +116,16 @@ defmodule Pleroma.Web.ConnCase do
   end
 
   setup tags do
-    Cachex.clear(:user_cache)
-    Cachex.clear(:object_cache)
     :ok = Ecto.Adapters.SQL.Sandbox.checkout(Pleroma.Repo)
 
-    unless tags[:async] do
+    if tags[:async] do
+      Mox.stub_with(Pleroma.CachexMock, Pleroma.NullCache)
+      Mox.set_mox_private()
+    else
       Ecto.Adapters.SQL.Sandbox.mode(Pleroma.Repo, {:shared, self()})
+      Mox.stub_with(Pleroma.CachexMock, Pleroma.CachexProxy)
+      Mox.set_mox_global()
+      Pleroma.DataCase.clear_cachex()
     end
 
     if tags[:needs_streamer] do
@@ -132,6 +136,8 @@ defmodule Pleroma.Web.ConnCase do
       })
     end
 
+    Pleroma.DataCase.stub_pipeline()
+
     {:ok, conn: Phoenix.ConnTest.build_conn()}
   end
 end
index d5456521c5296aabe641dabe8b778f324b5f42ec..5c657c1d92cd9a656249ba80c8da8ba08d31018c 100644 (file)
@@ -45,13 +45,34 @@ defmodule Pleroma.DataCase do
     end
   end
 
+  def clear_cachex do
+    Pleroma.Supervisor
+    |> Supervisor.which_children()
+    |> Enum.each(fn
+      {name, _, _, [Cachex]} ->
+        name
+        |> to_string
+        |> String.trim_leading("cachex_")
+        |> Kernel.<>("_cache")
+        |> String.to_existing_atom()
+        |> Cachex.clear()
+
+      _ ->
+        nil
+    end)
+  end
+
   setup tags do
-    Cachex.clear(:user_cache)
-    Cachex.clear(:object_cache)
     :ok = Ecto.Adapters.SQL.Sandbox.checkout(Pleroma.Repo)
 
-    unless tags[:async] do
+    if tags[:async] do
+      Mox.stub_with(Pleroma.CachexMock, Pleroma.NullCache)
+      Mox.set_mox_private()
+    else
       Ecto.Adapters.SQL.Sandbox.mode(Pleroma.Repo, {:shared, self()})
+      Mox.stub_with(Pleroma.CachexMock, Pleroma.CachexProxy)
+      Mox.set_mox_global()
+      clear_cachex()
     end
 
     if tags[:needs_streamer] do
@@ -62,9 +83,25 @@ defmodule Pleroma.DataCase do
       })
     end
 
+    stub_pipeline()
+
     :ok
   end
 
+  def stub_pipeline do
+    Mox.stub_with(Pleroma.Web.ActivityPub.SideEffectsMock, Pleroma.Web.ActivityPub.SideEffects)
+
+    Mox.stub_with(
+      Pleroma.Web.ActivityPub.ObjectValidatorMock,
+      Pleroma.Web.ActivityPub.ObjectValidator
+    )
+
+    Mox.stub_with(Pleroma.Web.ActivityPub.MRFMock, Pleroma.Web.ActivityPub.MRF)
+    Mox.stub_with(Pleroma.Web.ActivityPub.ActivityPubMock, Pleroma.Web.ActivityPub.ActivityPub)
+    Mox.stub_with(Pleroma.Web.FederatorMock, Pleroma.Web.Federator)
+    Mox.stub_with(Pleroma.ConfigMock, Pleroma.Config)
+  end
+
   def ensure_local_uploader(context) do
     test_uploader = Map.get(context, :uploader, Pleroma.Uploaders.Local)
     uploader = Pleroma.Config.get([Pleroma.Upload, :uploader])
index 224034521e683e135f7a354711f43aa23352109d..15e8cbd9d51aeee9cdb289d3e9e012566daa55dd 100644 (file)
@@ -55,6 +55,14 @@ defmodule Pleroma.Tests.Helpers do
           clear_config: 2
         ]
 
+      def time_travel(entity, seconds) do
+        new_time = NaiveDateTime.add(entity.inserted_at, seconds)
+
+        entity
+        |> Ecto.Changeset.change(%{inserted_at: new_time, updated_at: new_time})
+        |> Pleroma.Repo.update()
+      end
+
       def to_datetime(%NaiveDateTime{} = naive_datetime) do
         naive_datetime
         |> DateTime.from_naive!("Etc/UTC")
diff --git a/test/support/mocks.ex b/test/support/mocks.ex
new file mode 100644 (file)
index 0000000..a600a64
--- /dev/null
@@ -0,0 +1,25 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+Mox.defmock(Pleroma.CachexMock, for: Pleroma.Caching)
+
+Mox.defmock(Pleroma.Web.ActivityPub.ObjectValidatorMock,
+  for: Pleroma.Web.ActivityPub.ObjectValidator.Validating
+)
+
+Mox.defmock(Pleroma.Web.ActivityPub.MRFMock,
+  for: Pleroma.Web.ActivityPub.MRF.PipelineFiltering
+)
+
+Mox.defmock(Pleroma.Web.ActivityPub.ActivityPubMock,
+  for: Pleroma.Web.ActivityPub.ActivityPub.Persisting
+)
+
+Mox.defmock(Pleroma.Web.ActivityPub.SideEffectsMock,
+  for: Pleroma.Web.ActivityPub.SideEffects.Handling
+)
+
+Mox.defmock(Pleroma.Web.FederatorMock, for: Pleroma.Web.Federator.Publishing)
+
+Mox.defmock(Pleroma.ConfigMock, for: Pleroma.Config.Getting)
diff --git a/test/support/null_cache.ex b/test/support/null_cache.ex
new file mode 100644 (file)
index 0000000..c63df6a
--- /dev/null
@@ -0,0 +1,49 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.NullCache do
+  @moduledoc """
+  A module simulating a permanently empty cache.
+  """
+  @behaviour Pleroma.Caching
+
+  @impl true
+  def get!(_, _), do: nil
+
+  @impl true
+  def put(_, _, _, _ \\ nil), do: {:ok, true}
+
+  @impl true
+  def stream!(_, _), do: []
+
+  @impl true
+  def get(_, _), do: {:ok, nil}
+
+  @impl true
+  def fetch!(_, key, func) do
+    case func.(key) do
+      {_, res} -> res
+      res -> res
+    end
+  end
+
+  @impl true
+  def get_and_update(_, _, func) do
+    func.(nil)
+  end
+
+  @impl true
+  def expire_at(_, _, _), do: {:ok, true}
+
+  @impl true
+  def exists?(_, _), do: {:ok, false}
+
+  @impl true
+  def execute!(_, func) do
+    func.(:nothing)
+  end
+
+  @impl true
+  def del(_, _), do: {:ok, true}
+end