Merge branch 'no-async-clear-config' into 'develop'
Various test improvements and refactors See merge request pleroma/pleroma!3991
This commit is contained in:
commit
2c560266e9
|
@ -191,7 +191,7 @@ unit-testing-rum:
|
||||||
|
|
||||||
lint:
|
lint:
|
||||||
extends: .build_changes_policy
|
extends: .build_changes_policy
|
||||||
image: ¤t_elixir elixir:1.12-alpine
|
image: ¤t_elixir elixir:1.13-alpine
|
||||||
stage: test
|
stage: test
|
||||||
cache: *testing_cache_policy
|
cache: *testing_cache_policy
|
||||||
before_script: ¤t_bfr_script
|
before_script: ¤t_bfr_script
|
||||||
|
|
|
@ -143,6 +143,16 @@
|
||||||
|
|
||||||
config :pleroma, :config_impl, Pleroma.UnstubbedConfigMock
|
config :pleroma, :config_impl, Pleroma.UnstubbedConfigMock
|
||||||
|
|
||||||
|
config :pleroma, Pleroma.PromEx, disabled: true
|
||||||
|
|
||||||
|
# Mox definitions. Only read during compile time.
|
||||||
|
config :pleroma, Pleroma.User.Backup, config_impl: Pleroma.UnstubbedConfigMock
|
||||||
|
config :pleroma, Pleroma.Uploaders.S3, ex_aws_impl: Pleroma.Uploaders.S3.ExAwsMock
|
||||||
|
config :pleroma, Pleroma.Uploaders.S3, config_impl: Pleroma.UnstubbedConfigMock
|
||||||
|
config :pleroma, Pleroma.Upload, config_impl: Pleroma.UnstubbedConfigMock
|
||||||
|
config :pleroma, Pleroma.ScheduledActivity, config_impl: Pleroma.UnstubbedConfigMock
|
||||||
|
config :pleroma, Pleroma.Web.RichMedia.Helpers, config_impl: Pleroma.StaticStubbedConfigMock
|
||||||
|
|
||||||
if File.exists?("./config/test.secret.exs") do
|
if File.exists?("./config/test.secret.exs") do
|
||||||
import_config "test.secret.exs"
|
import_config "test.secret.exs"
|
||||||
else
|
else
|
||||||
|
|
|
@ -6,7 +6,6 @@ defmodule Pleroma.ScheduledActivity do
|
||||||
use Ecto.Schema
|
use Ecto.Schema
|
||||||
|
|
||||||
alias Ecto.Multi
|
alias Ecto.Multi
|
||||||
alias Pleroma.Config
|
|
||||||
alias Pleroma.Repo
|
alias Pleroma.Repo
|
||||||
alias Pleroma.ScheduledActivity
|
alias Pleroma.ScheduledActivity
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
|
@ -20,6 +19,8 @@ defmodule Pleroma.ScheduledActivity do
|
||||||
|
|
||||||
@min_offset :timer.minutes(5)
|
@min_offset :timer.minutes(5)
|
||||||
|
|
||||||
|
@config_impl Application.compile_env(:pleroma, [__MODULE__, :config_impl], Pleroma.Config)
|
||||||
|
|
||||||
schema "scheduled_activities" do
|
schema "scheduled_activities" do
|
||||||
belongs_to(:user, User, type: FlakeId.Ecto.CompatType)
|
belongs_to(:user, User, type: FlakeId.Ecto.CompatType)
|
||||||
field(:scheduled_at, :naive_datetime)
|
field(:scheduled_at, :naive_datetime)
|
||||||
|
@ -87,7 +88,7 @@ def exceeds_daily_user_limit?(user_id, scheduled_at) do
|
||||||
|> where([sa], type(sa.scheduled_at, :date) == type(^scheduled_at, :date))
|
|> where([sa], type(sa.scheduled_at, :date) == type(^scheduled_at, :date))
|
||||||
|> select([sa], count(sa.id))
|
|> select([sa], count(sa.id))
|
||||||
|> Repo.one()
|
|> Repo.one()
|
||||||
|> Kernel.>=(Config.get([ScheduledActivity, :daily_user_limit]))
|
|> Kernel.>=(@config_impl.get([ScheduledActivity, :daily_user_limit]))
|
||||||
end
|
end
|
||||||
|
|
||||||
def exceeds_total_user_limit?(user_id) do
|
def exceeds_total_user_limit?(user_id) do
|
||||||
|
@ -95,7 +96,7 @@ def exceeds_total_user_limit?(user_id) do
|
||||||
|> where(user_id: ^user_id)
|
|> where(user_id: ^user_id)
|
||||||
|> select([sa], count(sa.id))
|
|> select([sa], count(sa.id))
|
||||||
|> Repo.one()
|
|> Repo.one()
|
||||||
|> Kernel.>=(Config.get([ScheduledActivity, :total_user_limit]))
|
|> Kernel.>=(@config_impl.get([ScheduledActivity, :total_user_limit]))
|
||||||
end
|
end
|
||||||
|
|
||||||
def far_enough?(scheduled_at) when is_binary(scheduled_at) do
|
def far_enough?(scheduled_at) when is_binary(scheduled_at) do
|
||||||
|
@ -123,7 +124,7 @@ def new(%User{} = user, attrs) do
|
||||||
def create(%User{} = user, attrs) do
|
def create(%User{} = user, attrs) do
|
||||||
Multi.new()
|
Multi.new()
|
||||||
|> Multi.insert(:scheduled_activity, new(user, attrs))
|
|> Multi.insert(:scheduled_activity, new(user, attrs))
|
||||||
|> maybe_add_jobs(Config.get([ScheduledActivity, :enabled]))
|
|> maybe_add_jobs(@config_impl.get([ScheduledActivity, :enabled]))
|
||||||
|> Repo.transaction()
|
|> Repo.transaction()
|
||||||
|> transaction_response
|
|> transaction_response
|
||||||
end
|
end
|
||||||
|
|
|
@ -34,7 +34,6 @@ defmodule Pleroma.Upload do
|
||||||
|
|
||||||
"""
|
"""
|
||||||
alias Ecto.UUID
|
alias Ecto.UUID
|
||||||
alias Pleroma.Config
|
|
||||||
alias Pleroma.Maps
|
alias Pleroma.Maps
|
||||||
alias Pleroma.Web.ActivityPub.Utils
|
alias Pleroma.Web.ActivityPub.Utils
|
||||||
require Logger
|
require Logger
|
||||||
|
@ -76,6 +75,8 @@ defmodule Pleroma.Upload do
|
||||||
:path
|
:path
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@config_impl Application.compile_env(:pleroma, [__MODULE__, :config_impl], Pleroma.Config)
|
||||||
|
|
||||||
defp get_description(upload) do
|
defp get_description(upload) do
|
||||||
case {upload.description, Pleroma.Config.get([Pleroma.Upload, :default_description])} do
|
case {upload.description, Pleroma.Config.get([Pleroma.Upload, :default_description])} do
|
||||||
{description, _} when is_binary(description) -> description
|
{description, _} when is_binary(description) -> description
|
||||||
|
@ -244,18 +245,18 @@ defp url_from_spec(%__MODULE__{name: name}, base_url, {:file, path}) do
|
||||||
defp url_from_spec(_upload, _base_url, {:url, url}), do: url
|
defp url_from_spec(_upload, _base_url, {:url, url}), do: url
|
||||||
|
|
||||||
def base_url do
|
def base_url do
|
||||||
uploader = Config.get([Pleroma.Upload, :uploader])
|
uploader = @config_impl.get([Pleroma.Upload, :uploader])
|
||||||
upload_base_url = Config.get([Pleroma.Upload, :base_url])
|
upload_base_url = @config_impl.get([Pleroma.Upload, :base_url])
|
||||||
public_endpoint = Config.get([uploader, :public_endpoint])
|
public_endpoint = @config_impl.get([uploader, :public_endpoint])
|
||||||
|
|
||||||
case uploader do
|
case uploader do
|
||||||
Pleroma.Uploaders.Local ->
|
Pleroma.Uploaders.Local ->
|
||||||
upload_base_url || Pleroma.Web.Endpoint.url() <> "/media/"
|
upload_base_url || Pleroma.Web.Endpoint.url() <> "/media/"
|
||||||
|
|
||||||
Pleroma.Uploaders.S3 ->
|
Pleroma.Uploaders.S3 ->
|
||||||
bucket = Config.get([Pleroma.Uploaders.S3, :bucket])
|
bucket = @config_impl.get([Pleroma.Uploaders.S3, :bucket])
|
||||||
truncated_namespace = Config.get([Pleroma.Uploaders.S3, :truncated_namespace])
|
truncated_namespace = @config_impl.get([Pleroma.Uploaders.S3, :truncated_namespace])
|
||||||
namespace = Config.get([Pleroma.Uploaders.S3, :bucket_namespace])
|
namespace = @config_impl.get([Pleroma.Uploaders.S3, :bucket_namespace])
|
||||||
|
|
||||||
bucket_with_namespace =
|
bucket_with_namespace =
|
||||||
cond do
|
cond do
|
||||||
|
|
|
@ -10,8 +10,6 @@ defmodule Pleroma.Upload.Filter.Exiftool.ReadDescription do
|
||||||
"""
|
"""
|
||||||
@behaviour Pleroma.Upload.Filter
|
@behaviour Pleroma.Upload.Filter
|
||||||
|
|
||||||
@spec filter(Pleroma.Upload.t()) :: {:ok, any()} | {:error, String.t()}
|
|
||||||
|
|
||||||
def filter(%Pleroma.Upload{description: description})
|
def filter(%Pleroma.Upload{description: description})
|
||||||
when is_binary(description),
|
when is_binary(description),
|
||||||
do: {:ok, :noop}
|
do: {:ok, :noop}
|
||||||
|
|
|
@ -6,7 +6,8 @@ defmodule Pleroma.Uploaders.S3 do
|
||||||
@behaviour Pleroma.Uploaders.Uploader
|
@behaviour Pleroma.Uploaders.Uploader
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
alias Pleroma.Config
|
@ex_aws_impl Application.compile_env(:pleroma, [__MODULE__, :ex_aws_impl], ExAws)
|
||||||
|
@config_impl Application.compile_env(:pleroma, [__MODULE__, :config_impl], Pleroma.Config)
|
||||||
|
|
||||||
# The file name is re-encoded with S3's constraints here to comply with previous
|
# The file name is re-encoded with S3's constraints here to comply with previous
|
||||||
# links with less strict filenames
|
# links with less strict filenames
|
||||||
|
@ -22,7 +23,7 @@ def get_file(file) do
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def put_file(%Pleroma.Upload{} = upload) do
|
def put_file(%Pleroma.Upload{} = upload) do
|
||||||
config = Config.get([__MODULE__])
|
config = @config_impl.get([__MODULE__])
|
||||||
bucket = Keyword.get(config, :bucket)
|
bucket = Keyword.get(config, :bucket)
|
||||||
streaming = Keyword.get(config, :streaming_enabled)
|
streaming = Keyword.get(config, :streaming_enabled)
|
||||||
|
|
||||||
|
@ -56,7 +57,7 @@ def put_file(%Pleroma.Upload{} = upload) do
|
||||||
])
|
])
|
||||||
end
|
end
|
||||||
|
|
||||||
case ExAws.request(op) do
|
case @ex_aws_impl.request(op) do
|
||||||
{:ok, _} ->
|
{:ok, _} ->
|
||||||
{:ok, {:file, s3_name}}
|
{:ok, {:file, s3_name}}
|
||||||
|
|
||||||
|
@ -69,9 +70,9 @@ def put_file(%Pleroma.Upload{} = upload) do
|
||||||
@impl true
|
@impl true
|
||||||
def delete_file(file) do
|
def delete_file(file) do
|
||||||
[__MODULE__, :bucket]
|
[__MODULE__, :bucket]
|
||||||
|> Config.get()
|
|> @config_impl.get()
|
||||||
|> ExAws.S3.delete_object(file)
|
|> ExAws.S3.delete_object(file)
|
||||||
|> ExAws.request()
|
|> @ex_aws_impl.request()
|
||||||
|> case do
|
|> case do
|
||||||
{:ok, %{status_code: 204}} -> :ok
|
{:ok, %{status_code: 204}} -> :ok
|
||||||
error -> {:error, inspect(error)}
|
error -> {:error, inspect(error)}
|
||||||
|
@ -83,3 +84,7 @@ def strict_encode(name) do
|
||||||
String.replace(name, @regex, "-")
|
String.replace(name, @regex, "-")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defmodule Pleroma.Uploaders.S3.ExAwsAPI do
|
||||||
|
@callback request(op :: ExAws.Operation.t()) :: {:ok, ExAws.Operation.t()} | {:error, term()}
|
||||||
|
end
|
||||||
|
|
|
@ -35,6 +35,8 @@ defmodule Pleroma.User.Backup do
|
||||||
timestamps()
|
timestamps()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@config_impl Application.compile_env(:pleroma, [__MODULE__, :config_impl], Pleroma.Config)
|
||||||
|
|
||||||
def create(user, admin_id \\ nil) do
|
def create(user, admin_id \\ nil) do
|
||||||
with :ok <- validate_limit(user, admin_id),
|
with :ok <- validate_limit(user, admin_id),
|
||||||
{:ok, backup} <- user |> new() |> Repo.insert() do
|
{:ok, backup} <- user |> new() |> Repo.insert() do
|
||||||
|
@ -124,7 +126,10 @@ defp set_state(backup, state, processed_number \\ nil) do
|
||||||
|> Repo.update()
|
|> Repo.update()
|
||||||
end
|
end
|
||||||
|
|
||||||
def process(%__MODULE__{} = backup) do
|
def process(
|
||||||
|
%__MODULE__{} = backup,
|
||||||
|
processor_module \\ __MODULE__.Processor
|
||||||
|
) do
|
||||||
set_state(backup, :running, 0)
|
set_state(backup, :running, 0)
|
||||||
|
|
||||||
current_pid = self()
|
current_pid = self()
|
||||||
|
@ -132,7 +137,7 @@ def process(%__MODULE__{} = backup) do
|
||||||
task =
|
task =
|
||||||
Task.Supervisor.async_nolink(
|
Task.Supervisor.async_nolink(
|
||||||
Pleroma.TaskSupervisor,
|
Pleroma.TaskSupervisor,
|
||||||
__MODULE__,
|
processor_module,
|
||||||
:do_process,
|
:do_process,
|
||||||
[backup, current_pid]
|
[backup, current_pid]
|
||||||
)
|
)
|
||||||
|
@ -140,25 +145,8 @@ def process(%__MODULE__{} = backup) do
|
||||||
wait_backup(backup, backup.processed_number, task)
|
wait_backup(backup, backup.processed_number, task)
|
||||||
end
|
end
|
||||||
|
|
||||||
def do_process(backup, current_pid) do
|
|
||||||
with {:ok, zip_file} <- export(backup, current_pid),
|
|
||||||
{:ok, %{size: size}} <- File.stat(zip_file),
|
|
||||||
{:ok, _upload} <- upload(backup, zip_file) do
|
|
||||||
backup
|
|
||||||
|> cast(
|
|
||||||
%{
|
|
||||||
file_size: size,
|
|
||||||
processed: true,
|
|
||||||
state: :complete
|
|
||||||
},
|
|
||||||
[:file_size, :processed, :state]
|
|
||||||
)
|
|
||||||
|> Repo.update()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
defp wait_backup(backup, current_processed, task) do
|
defp wait_backup(backup, current_processed, task) do
|
||||||
wait_time = Pleroma.Config.get([__MODULE__, :process_wait_time])
|
wait_time = @config_impl.get([__MODULE__, :process_wait_time])
|
||||||
|
|
||||||
receive do
|
receive do
|
||||||
{:progress, new_processed} ->
|
{:progress, new_processed} ->
|
||||||
|
@ -365,3 +353,35 @@ defp statuses(dir, user, caller_pid) do
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defmodule Pleroma.User.Backup.ProcessorAPI do
|
||||||
|
@callback do_process(%Pleroma.User.Backup{}, pid()) ::
|
||||||
|
{:ok, %Pleroma.User.Backup{}} | {:error, any()}
|
||||||
|
end
|
||||||
|
|
||||||
|
defmodule Pleroma.User.Backup.Processor do
|
||||||
|
@behaviour Pleroma.User.Backup.ProcessorAPI
|
||||||
|
|
||||||
|
alias Pleroma.Repo
|
||||||
|
alias Pleroma.User.Backup
|
||||||
|
|
||||||
|
import Ecto.Changeset
|
||||||
|
|
||||||
|
@impl true
|
||||||
|
def do_process(backup, current_pid) do
|
||||||
|
with {:ok, zip_file} <- Backup.export(backup, current_pid),
|
||||||
|
{:ok, %{size: size}} <- File.stat(zip_file),
|
||||||
|
{:ok, _upload} <- Backup.upload(backup, zip_file) do
|
||||||
|
backup
|
||||||
|
|> cast(
|
||||||
|
%{
|
||||||
|
file_size: size,
|
||||||
|
processed: true,
|
||||||
|
state: :complete
|
||||||
|
},
|
||||||
|
[:file_size, :processed, :state]
|
||||||
|
)
|
||||||
|
|> Repo.update()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
|
@ -4,11 +4,12 @@
|
||||||
|
|
||||||
defmodule Pleroma.Web.RichMedia.Helpers do
|
defmodule Pleroma.Web.RichMedia.Helpers do
|
||||||
alias Pleroma.Activity
|
alias Pleroma.Activity
|
||||||
alias Pleroma.Config
|
|
||||||
alias Pleroma.HTML
|
alias Pleroma.HTML
|
||||||
alias Pleroma.Object
|
alias Pleroma.Object
|
||||||
alias Pleroma.Web.RichMedia.Parser
|
alias Pleroma.Web.RichMedia.Parser
|
||||||
|
|
||||||
|
@config_impl Application.compile_env(:pleroma, [__MODULE__, :config_impl], Pleroma.Config)
|
||||||
|
|
||||||
@options [
|
@options [
|
||||||
pool: :media,
|
pool: :media,
|
||||||
max_body: 2_000_000,
|
max_body: 2_000_000,
|
||||||
|
@ -17,7 +18,7 @@ defmodule Pleroma.Web.RichMedia.Helpers do
|
||||||
|
|
||||||
@spec validate_page_url(URI.t() | binary()) :: :ok | :error
|
@spec validate_page_url(URI.t() | binary()) :: :ok | :error
|
||||||
defp validate_page_url(page_url) when is_binary(page_url) do
|
defp validate_page_url(page_url) when is_binary(page_url) do
|
||||||
validate_tld = Config.get([Pleroma.Formatter, :validate_tld])
|
validate_tld = @config_impl.get([Pleroma.Formatter, :validate_tld])
|
||||||
|
|
||||||
page_url
|
page_url
|
||||||
|> Linkify.Parser.url?(validate_tld: validate_tld)
|
|> Linkify.Parser.url?(validate_tld: validate_tld)
|
||||||
|
@ -27,10 +28,10 @@ defp validate_page_url(page_url) when is_binary(page_url) do
|
||||||
defp validate_page_url(%URI{host: host, scheme: "https", authority: authority})
|
defp validate_page_url(%URI{host: host, scheme: "https", authority: authority})
|
||||||
when is_binary(authority) do
|
when is_binary(authority) do
|
||||||
cond do
|
cond do
|
||||||
host in Config.get([:rich_media, :ignore_hosts], []) ->
|
host in @config_impl.get([:rich_media, :ignore_hosts], []) ->
|
||||||
:error
|
:error
|
||||||
|
|
||||||
get_tld(host) in Config.get([:rich_media, :ignore_tld], []) ->
|
get_tld(host) in @config_impl.get([:rich_media, :ignore_tld], []) ->
|
||||||
:error
|
:error
|
||||||
|
|
||||||
true ->
|
true ->
|
||||||
|
@ -56,7 +57,7 @@ defp get_tld(host) do
|
||||||
end
|
end
|
||||||
|
|
||||||
def fetch_data_for_object(object) do
|
def fetch_data_for_object(object) do
|
||||||
with true <- Config.get([:rich_media, :enabled]),
|
with true <- @config_impl.get([:rich_media, :enabled]),
|
||||||
{:ok, page_url} <-
|
{:ok, page_url} <-
|
||||||
HTML.extract_first_external_url_from_object(object),
|
HTML.extract_first_external_url_from_object(object),
|
||||||
:ok <- validate_page_url(page_url),
|
:ok <- validate_page_url(page_url),
|
||||||
|
@ -68,7 +69,7 @@ def fetch_data_for_object(object) do
|
||||||
end
|
end
|
||||||
|
|
||||||
def fetch_data_for_activity(%Activity{data: %{"type" => "Create"}} = activity) do
|
def fetch_data_for_activity(%Activity{data: %{"type" => "Create"}} = activity) do
|
||||||
with true <- Config.get([:rich_media, :enabled]),
|
with true <- @config_impl.get([:rich_media, :enabled]),
|
||||||
%Object{} = object <- Object.normalize(activity, fetch: false) do
|
%Object{} = object <- Object.normalize(activity, fetch: false) do
|
||||||
fetch_data_for_object(object)
|
fetch_data_for_object(object)
|
||||||
else
|
else
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.Activity.Ir.TopicsTest do
|
defmodule Pleroma.Activity.Ir.TopicsTest do
|
||||||
use Pleroma.DataCase, async: true
|
use Pleroma.DataCase
|
||||||
|
|
||||||
alias Pleroma.Activity
|
alias Pleroma.Activity
|
||||||
alias Pleroma.Activity.Ir.Topics
|
alias Pleroma.Activity.Ir.Topics
|
||||||
|
|
|
@ -145,7 +145,6 @@ test "when association is not loaded" do
|
||||||
|
|
||||||
setup do: clear_config([:instance, :limit_to_local_content])
|
setup do: clear_config([:instance, :limit_to_local_content])
|
||||||
|
|
||||||
@tag :skip_on_mac
|
|
||||||
test "finds utf8 text in statuses", %{
|
test "finds utf8 text in statuses", %{
|
||||||
japanese_activity: japanese_activity,
|
japanese_activity: japanese_activity,
|
||||||
user: user
|
user: user
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.HTTP.AdapterHelper.HackneyTest do
|
defmodule Pleroma.HTTP.AdapterHelper.HackneyTest do
|
||||||
use ExUnit.Case, async: true
|
use ExUnit.Case
|
||||||
use Pleroma.Tests.Helpers
|
use Pleroma.Tests.Helpers
|
||||||
|
|
||||||
alias Pleroma.HTTP.AdapterHelper.Hackney
|
alias Pleroma.HTTP.AdapterHelper.Hackney
|
||||||
|
|
|
@ -7,6 +7,7 @@ defmodule Pleroma.ObjectTest do
|
||||||
use Oban.Testing, repo: Pleroma.Repo
|
use Oban.Testing, repo: Pleroma.Repo
|
||||||
|
|
||||||
import ExUnit.CaptureLog
|
import ExUnit.CaptureLog
|
||||||
|
import Mox
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
import Tesla.Mock
|
import Tesla.Mock
|
||||||
|
|
||||||
|
@ -15,10 +16,12 @@ defmodule Pleroma.ObjectTest do
|
||||||
alias Pleroma.Object
|
alias Pleroma.Object
|
||||||
alias Pleroma.Repo
|
alias Pleroma.Repo
|
||||||
alias Pleroma.Tests.ObanHelpers
|
alias Pleroma.Tests.ObanHelpers
|
||||||
|
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||||
alias Pleroma.Web.CommonAPI
|
alias Pleroma.Web.CommonAPI
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||||
|
ConfigMock |> stub_with(Pleroma.Test.StaticConfig)
|
||||||
:ok
|
:ok
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -3,19 +3,23 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.ScheduledActivityTest do
|
defmodule Pleroma.ScheduledActivityTest do
|
||||||
use Pleroma.DataCase
|
use Pleroma.DataCase, async: true
|
||||||
|
|
||||||
alias Pleroma.ScheduledActivity
|
alias Pleroma.ScheduledActivity
|
||||||
|
alias Pleroma.Test.StaticConfig
|
||||||
|
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||||
|
|
||||||
|
import Mox
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
|
|
||||||
setup do: clear_config([ScheduledActivity, :enabled])
|
|
||||||
|
|
||||||
setup [:ensure_local_uploader]
|
|
||||||
|
|
||||||
describe "creation" do
|
describe "creation" do
|
||||||
test "scheduled activities with jobs when ScheduledActivity enabled" do
|
test "scheduled activities with jobs when ScheduledActivity enabled" do
|
||||||
clear_config([ScheduledActivity, :enabled], true)
|
ConfigMock
|
||||||
|
|> stub(:get, fn
|
||||||
|
[ScheduledActivity, :enabled] -> true
|
||||||
|
path -> StaticConfig.get(path)
|
||||||
|
end)
|
||||||
|
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
|
||||||
today =
|
today =
|
||||||
|
@ -34,7 +38,12 @@ test "scheduled activities with jobs when ScheduledActivity enabled" do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "scheduled activities without jobs when ScheduledActivity disabled" do
|
test "scheduled activities without jobs when ScheduledActivity disabled" do
|
||||||
clear_config([ScheduledActivity, :enabled], false)
|
ConfigMock
|
||||||
|
|> stub(:get, fn
|
||||||
|
[ScheduledActivity, :enabled] -> false
|
||||||
|
path -> StaticConfig.get(path)
|
||||||
|
end)
|
||||||
|
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
|
||||||
today =
|
today =
|
||||||
|
@ -53,6 +62,9 @@ test "scheduled activities without jobs when ScheduledActivity disabled" do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "when daily user limit is exceeded" do
|
test "when daily user limit is exceeded" do
|
||||||
|
ConfigMock
|
||||||
|
|> stub_with(StaticConfig)
|
||||||
|
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
|
||||||
today =
|
today =
|
||||||
|
@ -69,6 +81,9 @@ test "when daily user limit is exceeded" do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "when total user limit is exceeded" do
|
test "when total user limit is exceeded" do
|
||||||
|
ConfigMock
|
||||||
|
|> stub_with(StaticConfig)
|
||||||
|
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
|
||||||
today =
|
today =
|
||||||
|
@ -89,6 +104,9 @@ test "when total user limit is exceeded" do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "when scheduled_at is earlier than 5 minute from now" do
|
test "when scheduled_at is earlier than 5 minute from now" do
|
||||||
|
ConfigMock
|
||||||
|
|> stub_with(StaticConfig)
|
||||||
|
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
|
||||||
scheduled_at =
|
scheduled_at =
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.Upload.Filter.Exiftool.ReadDescriptionTest do
|
defmodule Pleroma.Upload.Filter.Exiftool.ReadDescriptionTest do
|
||||||
use Pleroma.DataCase, async: true
|
use Pleroma.DataCase
|
||||||
alias Pleroma.Upload.Filter
|
alias Pleroma.Upload.Filter
|
||||||
|
|
||||||
@uploads %Pleroma.Upload{
|
@uploads %Pleroma.Upload{
|
||||||
|
|
|
@ -6,10 +6,19 @@ defmodule Pleroma.UploadTest do
|
||||||
use Pleroma.DataCase
|
use Pleroma.DataCase
|
||||||
|
|
||||||
import ExUnit.CaptureLog
|
import ExUnit.CaptureLog
|
||||||
|
import Mox
|
||||||
|
|
||||||
|
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||||
alias Pleroma.Upload
|
alias Pleroma.Upload
|
||||||
alias Pleroma.Uploaders.Uploader
|
alias Pleroma.Uploaders.Uploader
|
||||||
|
|
||||||
|
setup do
|
||||||
|
ConfigMock
|
||||||
|
|> stub_with(Pleroma.Test.StaticConfig)
|
||||||
|
|
||||||
|
:ok
|
||||||
|
end
|
||||||
|
|
||||||
@upload_file %Plug.Upload{
|
@upload_file %Plug.Upload{
|
||||||
content_type: "image/jpeg",
|
content_type: "image/jpeg",
|
||||||
path: Path.absname("test/fixtures/image_tmp.jpg"),
|
path: Path.absname("test/fixtures/image_tmp.jpg"),
|
||||||
|
@ -236,6 +245,8 @@ test "escapes reserved uri characters" do
|
||||||
describe "Setting a custom base_url for uploaded media" do
|
describe "Setting a custom base_url for uploaded media" do
|
||||||
setup do: clear_config([Pleroma.Upload, :base_url], "https://cache.pleroma.social")
|
setup do: clear_config([Pleroma.Upload, :base_url], "https://cache.pleroma.social")
|
||||||
|
|
||||||
|
# This seems to be backwards. Skipped for that reason
|
||||||
|
@tag skip: true
|
||||||
test "returns a media url with configured base_url" do
|
test "returns a media url with configured base_url" do
|
||||||
base_url = Pleroma.Config.get([Pleroma.Upload, :base_url])
|
base_url = Pleroma.Config.get([Pleroma.Upload, :base_url])
|
||||||
|
|
||||||
|
|
|
@ -3,22 +3,27 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.Uploaders.S3Test do
|
defmodule Pleroma.Uploaders.S3Test do
|
||||||
use Pleroma.DataCase
|
use Pleroma.DataCase, async: true
|
||||||
|
|
||||||
|
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||||
alias Pleroma.Uploaders.S3
|
alias Pleroma.Uploaders.S3
|
||||||
|
alias Pleroma.Uploaders.S3.ExAwsMock
|
||||||
|
|
||||||
import Mock
|
import Mox
|
||||||
import ExUnit.CaptureLog
|
import ExUnit.CaptureLog
|
||||||
|
|
||||||
setup do
|
|
||||||
clear_config([Pleroma.Upload, :uploader], Pleroma.Uploaders.S3)
|
|
||||||
clear_config([Pleroma.Upload, :base_url], "https://s3.amazonaws.com")
|
|
||||||
clear_config([Pleroma.Uploaders.S3])
|
|
||||||
clear_config([Pleroma.Uploaders.S3, :bucket], "test_bucket")
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "get_file/1" do
|
describe "get_file/1" do
|
||||||
test "it returns path to local folder for files" do
|
test "it returns url for files" do
|
||||||
|
ConfigMock
|
||||||
|
|> expect(:get, 6, fn key ->
|
||||||
|
[
|
||||||
|
{Pleroma.Upload,
|
||||||
|
[uploader: Pleroma.Uploaders.S3, base_url: "https://s3.amazonaws.com"]},
|
||||||
|
{Pleroma.Uploaders.S3, [bucket: "test_bucket"]}
|
||||||
|
]
|
||||||
|
|> get_in(key)
|
||||||
|
end)
|
||||||
|
|
||||||
assert S3.get_file("test_image.jpg") == {
|
assert S3.get_file("test_image.jpg") == {
|
||||||
:ok,
|
:ok,
|
||||||
{:url, "https://s3.amazonaws.com/test_bucket/test_image.jpg"}
|
{:url, "https://s3.amazonaws.com/test_bucket/test_image.jpg"}
|
||||||
|
@ -26,13 +31,16 @@ test "it returns path to local folder for files" do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it returns path without bucket when truncated_namespace set to ''" do
|
test "it returns path without bucket when truncated_namespace set to ''" do
|
||||||
clear_config([Pleroma.Uploaders.S3],
|
ConfigMock
|
||||||
bucket: "test_bucket",
|
|> expect(:get, 6, fn key ->
|
||||||
bucket_namespace: "myaccount",
|
[
|
||||||
truncated_namespace: ""
|
{Pleroma.Upload,
|
||||||
)
|
[uploader: Pleroma.Uploaders.S3, base_url: "https://s3.amazonaws.com"]},
|
||||||
|
{Pleroma.Uploaders.S3,
|
||||||
clear_config([Pleroma.Upload, :base_url], "https://s3.amazonaws.com")
|
[bucket: "test_bucket", truncated_namespace: "", bucket_namespace: "myaccount"]}
|
||||||
|
]
|
||||||
|
|> get_in(key)
|
||||||
|
end)
|
||||||
|
|
||||||
assert S3.get_file("test_image.jpg") == {
|
assert S3.get_file("test_image.jpg") == {
|
||||||
:ok,
|
:ok,
|
||||||
|
@ -41,10 +49,15 @@ test "it returns path without bucket when truncated_namespace set to ''" do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it returns path with bucket namespace when namespace is set" do
|
test "it returns path with bucket namespace when namespace is set" do
|
||||||
clear_config([Pleroma.Uploaders.S3],
|
ConfigMock
|
||||||
bucket: "test_bucket",
|
|> expect(:get, 6, fn key ->
|
||||||
bucket_namespace: "family"
|
[
|
||||||
)
|
{Pleroma.Upload,
|
||||||
|
[uploader: Pleroma.Uploaders.S3, base_url: "https://s3.amazonaws.com"]},
|
||||||
|
{Pleroma.Uploaders.S3, [bucket: "test_bucket", bucket_namespace: "family"]}
|
||||||
|
]
|
||||||
|
|> get_in(key)
|
||||||
|
end)
|
||||||
|
|
||||||
assert S3.get_file("test_image.jpg") == {
|
assert S3.get_file("test_image.jpg") == {
|
||||||
:ok,
|
:ok,
|
||||||
|
@ -62,28 +75,42 @@ test "it returns path with bucket namespace when namespace is set" do
|
||||||
tempfile: Path.absname("test/instance_static/add/shortcode.png")
|
tempfile: Path.absname("test/instance_static/add/shortcode.png")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ConfigMock
|
||||||
|
|> expect(:get, fn [Pleroma.Uploaders.S3] ->
|
||||||
|
[
|
||||||
|
bucket: "test_bucket"
|
||||||
|
]
|
||||||
|
end)
|
||||||
|
|
||||||
[file_upload: file_upload]
|
[file_upload: file_upload]
|
||||||
end
|
end
|
||||||
|
|
||||||
test "save file", %{file_upload: file_upload} do
|
test "save file", %{file_upload: file_upload} do
|
||||||
with_mock ExAws, request: fn _ -> {:ok, :ok} end do
|
ExAwsMock
|
||||||
assert S3.put_file(file_upload) == {:ok, {:file, "test_folder/image-tet.jpg"}}
|
|> expect(:request, fn _req -> {:ok, %{status_code: 200}} end)
|
||||||
end
|
|
||||||
|
assert S3.put_file(file_upload) == {:ok, {:file, "test_folder/image-tet.jpg"}}
|
||||||
end
|
end
|
||||||
|
|
||||||
test "returns error", %{file_upload: file_upload} do
|
test "returns error", %{file_upload: file_upload} do
|
||||||
with_mock ExAws, request: fn _ -> {:error, "S3 Upload failed"} end do
|
ExAwsMock
|
||||||
assert capture_log(fn ->
|
|> expect(:request, fn _req -> {:error, "S3 Upload failed"} end)
|
||||||
assert S3.put_file(file_upload) == {:error, "S3 Upload failed"}
|
|
||||||
end) =~ "Elixir.Pleroma.Uploaders.S3: {:error, \"S3 Upload failed\"}"
|
assert capture_log(fn ->
|
||||||
end
|
assert S3.put_file(file_upload) == {:error, "S3 Upload failed"}
|
||||||
|
end) =~ "Elixir.Pleroma.Uploaders.S3: {:error, \"S3 Upload failed\"}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "delete_file/1" do
|
describe "delete_file/1" do
|
||||||
test_with_mock "deletes file", ExAws, request: fn _req -> {:ok, %{status_code: 204}} end do
|
test "deletes file" do
|
||||||
|
ExAwsMock
|
||||||
|
|> expect(:request, fn _req -> {:ok, %{status_code: 204}} end)
|
||||||
|
|
||||||
|
ConfigMock
|
||||||
|
|> expect(:get, fn [Pleroma.Uploaders.S3, :bucket] -> "test_bucket" end)
|
||||||
|
|
||||||
assert :ok = S3.delete_file("image.jpg")
|
assert :ok = S3.delete_file("image.jpg")
|
||||||
assert_called(ExAws.request(:_))
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
# Pleroma: A lightweight social networking server
|
||||||
|
# Copyright © 2017-2023 Pleroma Authors <https://pleroma.social/>
|
||||||
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
defmodule Pleroma.User.BackupAsyncTest do
|
||||||
|
use Pleroma.DataCase, async: true
|
||||||
|
|
||||||
|
import Pleroma.Factory
|
||||||
|
import Mox
|
||||||
|
|
||||||
|
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||||
|
alias Pleroma.User.Backup
|
||||||
|
alias Pleroma.User.Backup.ProcessorMock
|
||||||
|
|
||||||
|
setup do
|
||||||
|
user = insert(:user, %{nickname: "cofe", name: "Cofe", ap_id: "http://cofe.io/users/cofe"})
|
||||||
|
|
||||||
|
{:ok, backup} = user |> Backup.new() |> Repo.insert()
|
||||||
|
%{backup: backup}
|
||||||
|
end
|
||||||
|
|
||||||
|
@tag capture_log: true
|
||||||
|
test "it handles unrecoverable exceptions", %{backup: backup} do
|
||||||
|
ProcessorMock
|
||||||
|
|> expect(:do_process, fn _, _ ->
|
||||||
|
raise "mock exception"
|
||||||
|
end)
|
||||||
|
|
||||||
|
ConfigMock
|
||||||
|
|> stub_with(Pleroma.Config)
|
||||||
|
|
||||||
|
{:error, %{backup: backup, reason: :exit}} = Backup.process(backup, ProcessorMock)
|
||||||
|
|
||||||
|
assert backup.state == :failed
|
||||||
|
end
|
||||||
|
|
||||||
|
@tag capture_log: true
|
||||||
|
test "it handles timeouts", %{backup: backup} do
|
||||||
|
ProcessorMock
|
||||||
|
|> expect(:do_process, fn _, _ ->
|
||||||
|
Process.sleep(:timer.seconds(4))
|
||||||
|
end)
|
||||||
|
|
||||||
|
ConfigMock
|
||||||
|
|> expect(:get, fn [Pleroma.User.Backup, :process_wait_time] -> :timer.seconds(2) end)
|
||||||
|
|
||||||
|
{:error, %{backup: backup, reason: :timeout}} = Backup.process(backup, ProcessorMock)
|
||||||
|
|
||||||
|
assert backup.state == :failed
|
||||||
|
end
|
||||||
|
end
|
|
@ -9,10 +9,14 @@ defmodule Pleroma.User.BackupTest do
|
||||||
import Mock
|
import Mock
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
import Swoosh.TestAssertions
|
import Swoosh.TestAssertions
|
||||||
|
import Mox
|
||||||
|
|
||||||
alias Pleroma.Bookmark
|
alias Pleroma.Bookmark
|
||||||
alias Pleroma.Tests.ObanHelpers
|
alias Pleroma.Tests.ObanHelpers
|
||||||
|
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||||
|
alias Pleroma.Uploaders.S3.ExAwsMock
|
||||||
alias Pleroma.User.Backup
|
alias Pleroma.User.Backup
|
||||||
|
alias Pleroma.User.Backup.ProcessorMock
|
||||||
alias Pleroma.Web.CommonAPI
|
alias Pleroma.Web.CommonAPI
|
||||||
alias Pleroma.Workers.BackupWorker
|
alias Pleroma.Workers.BackupWorker
|
||||||
|
|
||||||
|
@ -20,6 +24,14 @@ defmodule Pleroma.User.BackupTest do
|
||||||
clear_config([Pleroma.Upload, :uploader])
|
clear_config([Pleroma.Upload, :uploader])
|
||||||
clear_config([Backup, :limit_days])
|
clear_config([Backup, :limit_days])
|
||||||
clear_config([Pleroma.Emails.Mailer, :enabled], true)
|
clear_config([Pleroma.Emails.Mailer, :enabled], true)
|
||||||
|
|
||||||
|
ConfigMock
|
||||||
|
|> stub_with(Pleroma.Config)
|
||||||
|
|
||||||
|
ProcessorMock
|
||||||
|
|> stub_with(Pleroma.User.Backup.Processor)
|
||||||
|
|
||||||
|
:ok
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it does not requrie enabled email" do
|
test "it does not requrie enabled email" do
|
||||||
|
@ -302,24 +314,6 @@ test "it handles errors" do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it handles unrecoverable exceptions" do
|
|
||||||
user = insert(:user, %{nickname: "cofe", name: "Cofe", ap_id: "http://cofe.io/users/cofe"})
|
|
||||||
|
|
||||||
assert {:ok, backup} = user |> Backup.new() |> Repo.insert()
|
|
||||||
|
|
||||||
with_mock Backup, [:passthrough], do_process: fn _, _ -> raise "mock exception" end do
|
|
||||||
{:error, %{backup: backup, reason: :exit}} = Backup.process(backup)
|
|
||||||
|
|
||||||
assert backup.state == :failed
|
|
||||||
end
|
|
||||||
|
|
||||||
with_mock Backup, [:passthrough], do_process: fn _, _ -> Process.sleep(:timer.seconds(32)) end do
|
|
||||||
{:error, %{backup: backup, reason: :timeout}} = Backup.process(backup)
|
|
||||||
|
|
||||||
assert backup.state == :failed
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "it uploads and deletes a backup archive" do
|
describe "it uploads and deletes a backup archive" do
|
||||||
setup do
|
setup do
|
||||||
clear_config([Pleroma.Upload, :base_url], "https://s3.amazonaws.com")
|
clear_config([Pleroma.Upload, :base_url], "https://s3.amazonaws.com")
|
||||||
|
@ -345,14 +339,14 @@ test "S3", %{path: path, backup: backup} do
|
||||||
clear_config([Pleroma.Upload, :uploader], Pleroma.Uploaders.S3)
|
clear_config([Pleroma.Upload, :uploader], Pleroma.Uploaders.S3)
|
||||||
clear_config([Pleroma.Uploaders.S3, :streaming_enabled], false)
|
clear_config([Pleroma.Uploaders.S3, :streaming_enabled], false)
|
||||||
|
|
||||||
with_mock ExAws,
|
ExAwsMock
|
||||||
request: fn
|
|> expect(:request, 2, fn
|
||||||
%{http_method: :put} -> {:ok, :ok}
|
%{http_method: :put} -> {:ok, :ok}
|
||||||
%{http_method: :delete} -> {:ok, %{status_code: 204}}
|
%{http_method: :delete} -> {:ok, %{status_code: 204}}
|
||||||
end do
|
end)
|
||||||
assert {:ok, %Pleroma.Upload{}} = Backup.upload(backup, path)
|
|
||||||
assert {:ok, _backup} = Backup.delete(backup)
|
assert {:ok, %Pleroma.Upload{}} = Backup.upload(backup, path)
|
||||||
end
|
assert {:ok, _backup} = Backup.delete(backup)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "Local", %{path: path, backup: backup} do
|
test "Local", %{path: path, backup: backup} do
|
||||||
|
|
|
@ -11,6 +11,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
||||||
alias Pleroma.Config
|
alias Pleroma.Config
|
||||||
alias Pleroma.Notification
|
alias Pleroma.Notification
|
||||||
alias Pleroma.Object
|
alias Pleroma.Object
|
||||||
|
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||||
alias Pleroma.Web.ActivityPub.Utils
|
alias Pleroma.Web.ActivityPub.Utils
|
||||||
|
@ -19,11 +20,16 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
||||||
|
|
||||||
import ExUnit.CaptureLog
|
import ExUnit.CaptureLog
|
||||||
import Mock
|
import Mock
|
||||||
|
import Mox
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
import Tesla.Mock
|
import Tesla.Mock
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||||
|
|
||||||
|
ConfigMock
|
||||||
|
|> stub_with(Pleroma.Test.StaticConfig)
|
||||||
|
|
||||||
:ok
|
:ok
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -2681,6 +2687,7 @@ test "allow fetching of accounts with an empty string name field" do
|
||||||
assert user.name == " "
|
assert user.name == " "
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@tag capture_log: true
|
||||||
test "pin_data_from_featured_collection will ignore unsupported values" do
|
test "pin_data_from_featured_collection will ignore unsupported values" do
|
||||||
assert %{} ==
|
assert %{} ==
|
||||||
ActivityPub.pin_data_from_featured_collection(%{
|
ActivityPub.pin_data_from_featured_collection(%{
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.Web.ActivityPub.MRF.FollowBotPolicyTest do
|
defmodule Pleroma.Web.ActivityPub.MRF.FollowBotPolicyTest do
|
||||||
use Pleroma.DataCase, async: true
|
use Pleroma.DataCase
|
||||||
|
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
alias Pleroma.Web.ActivityPub.MRF.FollowBotPolicy
|
alias Pleroma.Web.ActivityPub.MRF.FollowBotPolicy
|
||||||
|
|
|
@ -7,10 +7,12 @@ defmodule Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicyTest do
|
||||||
use Pleroma.Tests.Helpers
|
use Pleroma.Tests.Helpers
|
||||||
|
|
||||||
alias Pleroma.HTTP
|
alias Pleroma.HTTP
|
||||||
|
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||||
alias Pleroma.Web.ActivityPub.MRF
|
alias Pleroma.Web.ActivityPub.MRF
|
||||||
alias Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicy
|
alias Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicy
|
||||||
|
|
||||||
import Mock
|
import Mock
|
||||||
|
import Mox
|
||||||
|
|
||||||
@message %{
|
@message %{
|
||||||
"type" => "Create",
|
"type" => "Create",
|
||||||
|
@ -42,6 +44,13 @@ defmodule Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicyTest do
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setup do
|
||||||
|
ConfigMock
|
||||||
|
|> stub_with(Pleroma.Test.StaticConfig)
|
||||||
|
|
||||||
|
:ok
|
||||||
|
end
|
||||||
|
|
||||||
setup do: clear_config([:media_proxy, :enabled], true)
|
setup do: clear_config([:media_proxy, :enabled], true)
|
||||||
|
|
||||||
test "it prefetches media proxy URIs" do
|
test "it prefetches media proxy URIs" do
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.Web.ActivityPub.MRFTest do
|
defmodule Pleroma.Web.ActivityPub.MRFTest do
|
||||||
use ExUnit.Case, async: true
|
use ExUnit.Case
|
||||||
use Pleroma.Tests.Helpers
|
use Pleroma.Tests.Helpers
|
||||||
alias Pleroma.Web.ActivityPub.MRF
|
alias Pleroma.Web.ActivityPub.MRF
|
||||||
|
|
||||||
|
|
|
@ -5,9 +5,11 @@
|
||||||
defmodule Pleroma.Web.ActivityPub.ObjectValidators.AttachmentValidatorTest do
|
defmodule Pleroma.Web.ActivityPub.ObjectValidators.AttachmentValidatorTest do
|
||||||
use Pleroma.DataCase, async: true
|
use Pleroma.DataCase, async: true
|
||||||
|
|
||||||
|
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||||
alias Pleroma.Web.ActivityPub.ObjectValidators.AttachmentValidator
|
alias Pleroma.Web.ActivityPub.ObjectValidators.AttachmentValidator
|
||||||
|
|
||||||
|
import Mox
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
|
|
||||||
describe "attachments" do
|
describe "attachments" do
|
||||||
|
@ -116,6 +118,9 @@ test "it handles our own uploads" do
|
||||||
filename: "an_image.jpg"
|
filename: "an_image.jpg"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ConfigMock
|
||||||
|
|> stub_with(Pleroma.Test.StaticConfig)
|
||||||
|
|
||||||
{:ok, attachment} = ActivityPub.upload(file, actor: user.ap_id)
|
{:ok, attachment} = ActivityPub.upload(file, actor: user.ap_id)
|
||||||
|
|
||||||
{:ok, attachment} =
|
{:ok, attachment} =
|
||||||
|
|
|
@ -5,11 +5,13 @@
|
||||||
defmodule Pleroma.Web.ActivityPub.ObjectValidators.ChatValidationTest do
|
defmodule Pleroma.Web.ActivityPub.ObjectValidators.ChatValidationTest do
|
||||||
use Pleroma.DataCase
|
use Pleroma.DataCase
|
||||||
alias Pleroma.Object
|
alias Pleroma.Object
|
||||||
|
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||||
alias Pleroma.Web.ActivityPub.Builder
|
alias Pleroma.Web.ActivityPub.Builder
|
||||||
alias Pleroma.Web.ActivityPub.ObjectValidator
|
alias Pleroma.Web.ActivityPub.ObjectValidator
|
||||||
alias Pleroma.Web.CommonAPI
|
alias Pleroma.Web.CommonAPI
|
||||||
|
|
||||||
|
import Mox
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
|
|
||||||
describe "chat message create activities" do
|
describe "chat message create activities" do
|
||||||
|
@ -82,6 +84,9 @@ test "validates for a basic object with an attachment", %{
|
||||||
filename: "an_image.jpg"
|
filename: "an_image.jpg"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ConfigMock
|
||||||
|
|> stub_with(Pleroma.Test.StaticConfig)
|
||||||
|
|
||||||
{:ok, attachment} = ActivityPub.upload(file, actor: user.ap_id)
|
{:ok, attachment} = ActivityPub.upload(file, actor: user.ap_id)
|
||||||
|
|
||||||
valid_chat_message =
|
valid_chat_message =
|
||||||
|
@ -103,6 +108,9 @@ test "validates for a basic object with an attachment in an array", %{
|
||||||
filename: "an_image.jpg"
|
filename: "an_image.jpg"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ConfigMock
|
||||||
|
|> stub_with(Pleroma.Test.StaticConfig)
|
||||||
|
|
||||||
{:ok, attachment} = ActivityPub.upload(file, actor: user.ap_id)
|
{:ok, attachment} = ActivityPub.upload(file, actor: user.ap_id)
|
||||||
|
|
||||||
valid_chat_message =
|
valid_chat_message =
|
||||||
|
@ -124,6 +132,9 @@ test "validates for a basic object with an attachment but without content", %{
|
||||||
filename: "an_image.jpg"
|
filename: "an_image.jpg"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ConfigMock
|
||||||
|
|> stub_with(Pleroma.Test.StaticConfig)
|
||||||
|
|
||||||
{:ok, attachment} = ActivityPub.upload(file, actor: user.ap_id)
|
{:ok, attachment} = ActivityPub.upload(file, actor: user.ap_id)
|
||||||
|
|
||||||
valid_chat_message =
|
valid_chat_message =
|
||||||
|
|
|
@ -128,10 +128,11 @@ test "it keeps link tags" do
|
||||||
|
|
||||||
message = File.read!("test/fixtures/fep-e232.json") |> Jason.decode!()
|
message = File.read!("test/fixtures/fep-e232.json") |> Jason.decode!()
|
||||||
|
|
||||||
assert {:ok, activity} = Transmogrifier.handle_incoming(message)
|
assert capture_log(fn ->
|
||||||
|
assert {:ok, activity} = Transmogrifier.handle_incoming(message)
|
||||||
object = Object.normalize(activity)
|
object = Object.normalize(activity)
|
||||||
assert [%{"type" => "Mention"}, %{"type" => "Link"}] = object.data["tag"]
|
assert [%{"type" => "Mention"}, %{"type" => "Link"}] = object.data["tag"]
|
||||||
|
end) =~ "Error while fetching"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it accepts quote posts" do
|
test "it accepts quote posts" do
|
||||||
|
|
|
@ -15,6 +15,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
||||||
alias Pleroma.ModerationLog
|
alias Pleroma.ModerationLog
|
||||||
alias Pleroma.Repo
|
alias Pleroma.Repo
|
||||||
alias Pleroma.Tests.ObanHelpers
|
alias Pleroma.Tests.ObanHelpers
|
||||||
|
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
alias Pleroma.Web.CommonAPI
|
alias Pleroma.Web.CommonAPI
|
||||||
|
|
||||||
|
@ -1077,6 +1078,9 @@ test "it requires privileged role :statistics_read", %{conn: conn} do
|
||||||
|
|
||||||
describe "/api/pleroma/backups" do
|
describe "/api/pleroma/backups" do
|
||||||
test "it creates a backup", %{conn: conn} do
|
test "it creates a backup", %{conn: conn} do
|
||||||
|
ConfigMock
|
||||||
|
|> Mox.stub_with(Pleroma.Config)
|
||||||
|
|
||||||
admin = %{id: admin_id, nickname: admin_nickname} = insert(:user, is_admin: true)
|
admin = %{id: admin_id, nickname: admin_nickname} = insert(:user, is_admin: true)
|
||||||
token = insert(:oauth_admin_token, user: admin)
|
token = insert(:oauth_admin_token, user: admin)
|
||||||
user = %{id: user_id, nickname: user_nickname} = insert(:user)
|
user = %{id: user_id, nickname: user_nickname} = insert(:user)
|
||||||
|
|
|
@ -5,9 +5,11 @@
|
||||||
defmodule Pleroma.Web.AdminAPI.MediaProxyCacheControllerTest do
|
defmodule Pleroma.Web.AdminAPI.MediaProxyCacheControllerTest do
|
||||||
use Pleroma.Web.ConnCase
|
use Pleroma.Web.ConnCase
|
||||||
|
|
||||||
import Pleroma.Factory
|
|
||||||
import Mock
|
import Mock
|
||||||
|
import Mox
|
||||||
|
import Pleroma.Factory
|
||||||
|
|
||||||
|
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||||
alias Pleroma.Web.MediaProxy
|
alias Pleroma.Web.MediaProxy
|
||||||
|
|
||||||
setup do: clear_config([:media_proxy])
|
setup do: clear_config([:media_proxy])
|
||||||
|
@ -128,6 +130,9 @@ test "perform invalidates cache of MediaProxy", %{conn: conn} do
|
||||||
"http://example.com/media/fb1f4d.jpg"
|
"http://example.com/media/fb1f4d.jpg"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
ConfigMock
|
||||||
|
|> stub_with(Pleroma.Test.StaticConfig)
|
||||||
|
|
||||||
with_mocks [
|
with_mocks [
|
||||||
{MediaProxy.Invalidation.Script, [],
|
{MediaProxy.Invalidation.Script, [],
|
||||||
[
|
[
|
||||||
|
@ -150,6 +155,9 @@ test "perform invalidates cache of MediaProxy and adds url to banned", %{conn: c
|
||||||
"http://example.com/media/fb1f4d.jpg"
|
"http://example.com/media/fb1f4d.jpg"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
ConfigMock
|
||||||
|
|> stub_with(Pleroma.Test.StaticConfig)
|
||||||
|
|
||||||
with_mocks [{MediaProxy.Invalidation.Script, [], [purge: fn _, _ -> {"ok", 0} end]}] do
|
with_mocks [{MediaProxy.Invalidation.Script, [], [purge: fn _, _ -> {"ok", 0} end]}] do
|
||||||
conn
|
conn
|
||||||
|> put_req_header("content-type", "application/json")
|
|> put_req_header("content-type", "application/json")
|
||||||
|
|
|
@ -12,6 +12,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
||||||
alias Pleroma.Notification
|
alias Pleroma.Notification
|
||||||
alias Pleroma.Object
|
alias Pleroma.Object
|
||||||
alias Pleroma.Repo
|
alias Pleroma.Repo
|
||||||
|
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||||
alias Pleroma.Web.ActivityPub.Transmogrifier
|
alias Pleroma.Web.ActivityPub.Transmogrifier
|
||||||
|
@ -20,9 +21,10 @@ defmodule Pleroma.Web.CommonAPITest do
|
||||||
alias Pleroma.Web.CommonAPI
|
alias Pleroma.Web.CommonAPI
|
||||||
alias Pleroma.Workers.PollWorker
|
alias Pleroma.Workers.PollWorker
|
||||||
|
|
||||||
import Pleroma.Factory
|
|
||||||
import Mock
|
|
||||||
import Ecto.Query, only: [from: 2]
|
import Ecto.Query, only: [from: 2]
|
||||||
|
import Mock
|
||||||
|
import Mox
|
||||||
|
import Pleroma.Factory
|
||||||
|
|
||||||
require Pleroma.Constants
|
require Pleroma.Constants
|
||||||
|
|
||||||
|
@ -31,6 +33,13 @@ defmodule Pleroma.Web.CommonAPITest do
|
||||||
:ok
|
:ok
|
||||||
end
|
end
|
||||||
|
|
||||||
|
setup do
|
||||||
|
ConfigMock
|
||||||
|
|> stub_with(Pleroma.Test.StaticConfig)
|
||||||
|
|
||||||
|
:ok
|
||||||
|
end
|
||||||
|
|
||||||
setup do: clear_config([:instance, :safe_dm_mentions])
|
setup do: clear_config([:instance, :safe_dm_mentions])
|
||||||
setup do: clear_config([:instance, :limit])
|
setup do: clear_config([:instance, :limit])
|
||||||
setup do: clear_config([:instance, :max_pinned_statuses])
|
setup do: clear_config([:instance, :max_pinned_statuses])
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.Web.MastodonAPI.DirectoryControllerTest do
|
defmodule Pleroma.Web.MastodonAPI.DirectoryControllerTest do
|
||||||
use Pleroma.Web.ConnCase, async: true
|
use Pleroma.Web.ConnCase
|
||||||
alias Pleroma.Web.CommonAPI
|
alias Pleroma.Web.CommonAPI
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,10 @@ defmodule Pleroma.Web.MastodonAPI.MediaControllerTest do
|
||||||
use Pleroma.Web.ConnCase
|
use Pleroma.Web.ConnCase
|
||||||
|
|
||||||
import ExUnit.CaptureLog
|
import ExUnit.CaptureLog
|
||||||
|
import Mox
|
||||||
|
|
||||||
alias Pleroma.Object
|
alias Pleroma.Object
|
||||||
|
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||||
|
|
||||||
|
@ -15,6 +17,9 @@ defmodule Pleroma.Web.MastodonAPI.MediaControllerTest do
|
||||||
setup do: oauth_access(["write:media"])
|
setup do: oauth_access(["write:media"])
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
|
ConfigMock
|
||||||
|
|> stub_with(Pleroma.Test.StaticConfig)
|
||||||
|
|
||||||
image = %Plug.Upload{
|
image = %Plug.Upload{
|
||||||
content_type: "image/jpeg",
|
content_type: "image/jpeg",
|
||||||
path: Path.absname("test/fixtures/image.jpg"),
|
path: Path.absname("test/fixtures/image.jpg"),
|
||||||
|
@ -145,6 +150,9 @@ test "Do not allow nested filename", %{conn: conn, image: image} do
|
||||||
setup do: oauth_access(["write:media"])
|
setup do: oauth_access(["write:media"])
|
||||||
|
|
||||||
setup %{user: actor} do
|
setup %{user: actor} do
|
||||||
|
ConfigMock
|
||||||
|
|> stub_with(Pleroma.Test.StaticConfig)
|
||||||
|
|
||||||
file = %Plug.Upload{
|
file = %Plug.Upload{
|
||||||
content_type: "image/jpeg",
|
content_type: "image/jpeg",
|
||||||
path: Path.absname("test/fixtures/image.jpg"),
|
path: Path.absname("test/fixtures/image.jpg"),
|
||||||
|
@ -177,6 +185,9 @@ test "/api/v1/media/:id good request", %{conn: conn, object: object} do
|
||||||
setup do: oauth_access(["read:media"])
|
setup do: oauth_access(["read:media"])
|
||||||
|
|
||||||
setup %{user: actor} do
|
setup %{user: actor} do
|
||||||
|
ConfigMock
|
||||||
|
|> stub_with(Pleroma.Test.StaticConfig)
|
||||||
|
|
||||||
file = %Plug.Upload{
|
file = %Plug.Upload{
|
||||||
content_type: "image/jpeg",
|
content_type: "image/jpeg",
|
||||||
path: Path.absname("test/fixtures/image.jpg"),
|
path: Path.absname("test/fixtures/image.jpg"),
|
||||||
|
|
|
@ -3,15 +3,25 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.Web.MastodonAPI.ScheduledActivityControllerTest do
|
defmodule Pleroma.Web.MastodonAPI.ScheduledActivityControllerTest do
|
||||||
use Pleroma.Web.ConnCase
|
use Pleroma.Web.ConnCase, async: true
|
||||||
|
|
||||||
alias Pleroma.Repo
|
alias Pleroma.Repo
|
||||||
alias Pleroma.ScheduledActivity
|
alias Pleroma.ScheduledActivity
|
||||||
|
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||||
|
|
||||||
import Pleroma.Factory
|
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
|
import Mox
|
||||||
|
import Pleroma.Factory
|
||||||
|
|
||||||
setup do: clear_config([ScheduledActivity, :enabled])
|
setup do
|
||||||
|
ConfigMock
|
||||||
|
|> stub(:get, fn
|
||||||
|
[ScheduledActivity, :enabled] -> true
|
||||||
|
path -> Pleroma.Test.StaticConfig.get(path)
|
||||||
|
end)
|
||||||
|
|
||||||
|
:ok
|
||||||
|
end
|
||||||
|
|
||||||
test "shows scheduled activities" do
|
test "shows scheduled activities" do
|
||||||
%{user: user, conn: conn} = oauth_access(["read:statuses"])
|
%{user: user, conn: conn} = oauth_access(["read:statuses"])
|
||||||
|
@ -55,7 +65,6 @@ test "shows a scheduled activity" do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "updates a scheduled activity" do
|
test "updates a scheduled activity" do
|
||||||
clear_config([ScheduledActivity, :enabled], true)
|
|
||||||
%{user: user, conn: conn} = oauth_access(["write:statuses"])
|
%{user: user, conn: conn} = oauth_access(["write:statuses"])
|
||||||
|
|
||||||
scheduled_at = Timex.shift(NaiveDateTime.utc_now(), minutes: 60)
|
scheduled_at = Timex.shift(NaiveDateTime.utc_now(), minutes: 60)
|
||||||
|
@ -103,7 +112,6 @@ test "updates a scheduled activity" do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "deletes a scheduled activity" do
|
test "deletes a scheduled activity" do
|
||||||
clear_config([ScheduledActivity, :enabled], true)
|
|
||||||
%{user: user, conn: conn} = oauth_access(["write:statuses"])
|
%{user: user, conn: conn} = oauth_access(["write:statuses"])
|
||||||
scheduled_at = Timex.shift(NaiveDateTime.utc_now(), minutes: 60)
|
scheduled_at = Timex.shift(NaiveDateTime.utc_now(), minutes: 60)
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,6 @@ test "it returns empty result if user or status search return undefined error",
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@tag :skip_on_mac
|
|
||||||
test "search", %{conn: conn} do
|
test "search", %{conn: conn} do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
user_two = insert(:user, %{nickname: "shp@shitposter.club"})
|
user_two = insert(:user, %{nickname: "shp@shitposter.club"})
|
||||||
|
|
|
@ -19,16 +19,24 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
||||||
alias Pleroma.Web.CommonAPI
|
alias Pleroma.Web.CommonAPI
|
||||||
alias Pleroma.Workers.ScheduledActivityWorker
|
alias Pleroma.Workers.ScheduledActivityWorker
|
||||||
|
|
||||||
|
import Mox
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
|
|
||||||
setup do: clear_config([:instance, :federating])
|
setup do: clear_config([:instance, :federating])
|
||||||
setup do: clear_config([:instance, :allow_relay])
|
setup do: clear_config([:instance, :allow_relay])
|
||||||
setup do: clear_config([:rich_media, :enabled])
|
|
||||||
setup do: clear_config([:mrf, :policies])
|
setup do: clear_config([:mrf, :policies])
|
||||||
setup do: clear_config([:mrf_keyword, :reject])
|
setup do: clear_config([:mrf_keyword, :reject])
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
Mox.stub_with(Pleroma.UnstubbedConfigMock, Pleroma.Config)
|
Pleroma.UnstubbedConfigMock
|
||||||
|
|> stub_with(Pleroma.Config)
|
||||||
|
|
||||||
|
Pleroma.StaticStubbedConfigMock
|
||||||
|
|> stub(:get, fn
|
||||||
|
[:rich_media, :enabled] -> false
|
||||||
|
path -> Pleroma.Test.StaticConfig.get(path)
|
||||||
|
end)
|
||||||
|
|
||||||
:ok
|
:ok
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -37,7 +45,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
||||||
|
|
||||||
test "posting a status does not increment reblog_count when relaying", %{conn: conn} do
|
test "posting a status does not increment reblog_count when relaying", %{conn: conn} do
|
||||||
clear_config([:instance, :federating], true)
|
clear_config([:instance, :federating], true)
|
||||||
Config.get([:instance, :allow_relay], true)
|
clear_config([:instance, :allow_relay], true)
|
||||||
|
|
||||||
response =
|
response =
|
||||||
conn
|
conn
|
||||||
|
@ -321,7 +329,11 @@ test "posting a fake status", %{conn: conn} do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "fake statuses' preview card is not cached", %{conn: conn} do
|
test "fake statuses' preview card is not cached", %{conn: conn} do
|
||||||
clear_config([:rich_media, :enabled], true)
|
Pleroma.StaticStubbedConfigMock
|
||||||
|
|> stub(:get, fn
|
||||||
|
[:rich_media, :enabled] -> true
|
||||||
|
path -> Pleroma.Test.StaticConfig.get(path)
|
||||||
|
end)
|
||||||
|
|
||||||
Tesla.Mock.mock(fn
|
Tesla.Mock.mock(fn
|
||||||
%{
|
%{
|
||||||
|
@ -358,7 +370,12 @@ test "fake statuses' preview card is not cached", %{conn: conn} do
|
||||||
|
|
||||||
test "posting a status with OGP link preview", %{conn: conn} do
|
test "posting a status with OGP link preview", %{conn: conn} do
|
||||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||||
clear_config([:rich_media, :enabled], true)
|
|
||||||
|
Pleroma.StaticStubbedConfigMock
|
||||||
|
|> stub(:get, fn
|
||||||
|
[:rich_media, :enabled] -> true
|
||||||
|
path -> Pleroma.Test.StaticConfig.get(path)
|
||||||
|
end)
|
||||||
|
|
||||||
conn =
|
conn =
|
||||||
conn
|
conn
|
||||||
|
@ -1689,7 +1706,11 @@ test "on pin removes deletion job, on unpin reschedule deletion" do
|
||||||
|
|
||||||
describe "cards" do
|
describe "cards" do
|
||||||
setup do
|
setup do
|
||||||
clear_config([:rich_media, :enabled], true)
|
Pleroma.StaticStubbedConfigMock
|
||||||
|
|> stub(:get, fn
|
||||||
|
[:rich_media, :enabled] -> true
|
||||||
|
path -> Pleroma.Test.StaticConfig.get(path)
|
||||||
|
end)
|
||||||
|
|
||||||
oauth_access(["read:statuses"])
|
oauth_access(["read:statuses"])
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,11 +7,13 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPITest do
|
||||||
|
|
||||||
alias Pleroma.Notification
|
alias Pleroma.Notification
|
||||||
alias Pleroma.ScheduledActivity
|
alias Pleroma.ScheduledActivity
|
||||||
|
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
alias Pleroma.Web.CommonAPI
|
alias Pleroma.Web.CommonAPI
|
||||||
alias Pleroma.Web.MastodonAPI.MastodonAPI
|
alias Pleroma.Web.MastodonAPI.MastodonAPI
|
||||||
|
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
|
import Mox
|
||||||
|
|
||||||
describe "follow/3" do
|
describe "follow/3" do
|
||||||
test "returns error when followed user is deactivated" do
|
test "returns error when followed user is deactivated" do
|
||||||
|
@ -88,6 +90,9 @@ test "returns notifications for user" do
|
||||||
|
|
||||||
describe "get_scheduled_activities/2" do
|
describe "get_scheduled_activities/2" do
|
||||||
test "returns user scheduled activities" do
|
test "returns user scheduled activities" do
|
||||||
|
ConfigMock
|
||||||
|
|> stub_with(Pleroma.Test.StaticConfig)
|
||||||
|
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
|
||||||
today =
|
today =
|
||||||
|
|
|
@ -4,13 +4,22 @@
|
||||||
|
|
||||||
defmodule Pleroma.Web.MastodonAPI.UpdateCredentialsTest do
|
defmodule Pleroma.Web.MastodonAPI.UpdateCredentialsTest do
|
||||||
alias Pleroma.Repo
|
alias Pleroma.Repo
|
||||||
|
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
|
|
||||||
use Pleroma.Web.ConnCase
|
use Pleroma.Web.ConnCase
|
||||||
|
|
||||||
import Mock
|
import Mock
|
||||||
|
import Mox
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
|
|
||||||
|
setup do
|
||||||
|
ConfigMock
|
||||||
|
|> stub_with(Pleroma.Test.StaticConfig)
|
||||||
|
|
||||||
|
:ok
|
||||||
|
end
|
||||||
|
|
||||||
describe "updating credentials" do
|
describe "updating credentials" do
|
||||||
setup do: oauth_access(["write:accounts"])
|
setup do: oauth_access(["write:accounts"])
|
||||||
setup :request_content_type
|
setup :request_content_type
|
||||||
|
|
|
@ -5,11 +5,13 @@
|
||||||
defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
||||||
use Pleroma.DataCase, async: false
|
use Pleroma.DataCase, async: false
|
||||||
|
|
||||||
|
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
alias Pleroma.UserRelationship
|
alias Pleroma.UserRelationship
|
||||||
alias Pleroma.Web.CommonAPI
|
alias Pleroma.Web.CommonAPI
|
||||||
alias Pleroma.Web.MastodonAPI.AccountView
|
alias Pleroma.Web.MastodonAPI.AccountView
|
||||||
|
|
||||||
|
import Mox
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
import Tesla.Mock
|
import Tesla.Mock
|
||||||
|
|
||||||
|
@ -753,6 +755,9 @@ test "uses mediaproxy urls when it's enabled (regardless of media preview proxy
|
||||||
clear_config([:media_proxy, :enabled], true)
|
clear_config([:media_proxy, :enabled], true)
|
||||||
clear_config([:media_preview_proxy, :enabled])
|
clear_config([:media_preview_proxy, :enabled])
|
||||||
|
|
||||||
|
ConfigMock
|
||||||
|
|> stub_with(Pleroma.Test.StaticConfig)
|
||||||
|
|
||||||
user =
|
user =
|
||||||
insert(:user,
|
insert(:user,
|
||||||
avatar: %{"url" => [%{"href" => "https://evil.website/avatar.png"}]},
|
avatar: %{"url" => [%{"href" => "https://evil.website/avatar.png"}]},
|
||||||
|
@ -760,7 +765,7 @@ test "uses mediaproxy urls when it's enabled (regardless of media preview proxy
|
||||||
emoji: %{"joker_smile" => "https://evil.website/society.png"}
|
emoji: %{"joker_smile" => "https://evil.website/society.png"}
|
||||||
)
|
)
|
||||||
|
|
||||||
with media_preview_enabled <- [false, true] do
|
Enum.each([true, false], fn media_preview_enabled ->
|
||||||
clear_config([:media_preview_proxy, :enabled], media_preview_enabled)
|
clear_config([:media_preview_proxy, :enabled], media_preview_enabled)
|
||||||
|
|
||||||
AccountView.render("show.json", %{user: user, skip_visibility_check: true})
|
AccountView.render("show.json", %{user: user, skip_visibility_check: true})
|
||||||
|
@ -778,7 +783,7 @@ test "uses mediaproxy urls when it's enabled (regardless of media preview proxy
|
||||||
true
|
true
|
||||||
end)
|
end)
|
||||||
|> assert()
|
|> assert()
|
||||||
end
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "renders mute expiration date" do
|
test "renders mute expiration date" do
|
||||||
|
|
|
@ -4,12 +4,16 @@
|
||||||
|
|
||||||
defmodule Pleroma.Web.MastodonAPI.ScheduledActivityViewTest do
|
defmodule Pleroma.Web.MastodonAPI.ScheduledActivityViewTest do
|
||||||
use Pleroma.DataCase, async: true
|
use Pleroma.DataCase, async: true
|
||||||
|
|
||||||
alias Pleroma.ScheduledActivity
|
alias Pleroma.ScheduledActivity
|
||||||
|
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||||
alias Pleroma.Web.CommonAPI
|
alias Pleroma.Web.CommonAPI
|
||||||
alias Pleroma.Web.CommonAPI.Utils
|
alias Pleroma.Web.CommonAPI.Utils
|
||||||
alias Pleroma.Web.MastodonAPI.ScheduledActivityView
|
alias Pleroma.Web.MastodonAPI.ScheduledActivityView
|
||||||
alias Pleroma.Web.MastodonAPI.StatusView
|
alias Pleroma.Web.MastodonAPI.StatusView
|
||||||
|
|
||||||
|
import Mox
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
|
|
||||||
test "A scheduled activity with a media attachment" do
|
test "A scheduled activity with a media attachment" do
|
||||||
|
@ -27,6 +31,9 @@ test "A scheduled activity with a media attachment" do
|
||||||
filename: "an_image.jpg"
|
filename: "an_image.jpg"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ConfigMock
|
||||||
|
|> stub_with(Pleroma.Test.StaticConfig)
|
||||||
|
|
||||||
{:ok, upload} = ActivityPub.upload(file, actor: user.ap_id)
|
{:ok, upload} = ActivityPub.upload(file, actor: user.ap_id)
|
||||||
|
|
||||||
attrs = %{
|
attrs = %{
|
||||||
|
|
|
@ -9,9 +9,17 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do
|
||||||
import Mox
|
import Mox
|
||||||
|
|
||||||
alias Pleroma.ReverseProxy.ClientMock
|
alias Pleroma.ReverseProxy.ClientMock
|
||||||
|
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||||
alias Pleroma.Web.MediaProxy
|
alias Pleroma.Web.MediaProxy
|
||||||
alias Plug.Conn
|
alias Plug.Conn
|
||||||
|
|
||||||
|
setup do
|
||||||
|
ConfigMock
|
||||||
|
|> stub_with(Pleroma.Test.StaticConfig)
|
||||||
|
|
||||||
|
:ok
|
||||||
|
end
|
||||||
|
|
||||||
describe "Media Proxy" do
|
describe "Media Proxy" do
|
||||||
setup do
|
setup do
|
||||||
clear_config([:media_proxy, :enabled], true)
|
clear_config([:media_proxy, :enabled], true)
|
||||||
|
|
|
@ -7,9 +7,19 @@ defmodule Pleroma.Web.MediaProxyTest do
|
||||||
use Pleroma.Tests.Helpers
|
use Pleroma.Tests.Helpers
|
||||||
|
|
||||||
alias Pleroma.Config
|
alias Pleroma.Config
|
||||||
|
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||||
alias Pleroma.Web.Endpoint
|
alias Pleroma.Web.Endpoint
|
||||||
alias Pleroma.Web.MediaProxy
|
alias Pleroma.Web.MediaProxy
|
||||||
|
|
||||||
|
import Mox
|
||||||
|
|
||||||
|
setup do
|
||||||
|
ConfigMock
|
||||||
|
|> stub_with(Pleroma.Test.StaticConfig)
|
||||||
|
|
||||||
|
:ok
|
||||||
|
end
|
||||||
|
|
||||||
defp decode_result(encoded) do
|
defp decode_result(encoded) do
|
||||||
{:ok, decoded} = MediaProxy.decode_url(encoded)
|
{:ok, decoded} = MediaProxy.decode_url(encoded)
|
||||||
decoded
|
decoded
|
||||||
|
@ -222,7 +232,12 @@ test "does not change whitelisted urls" do
|
||||||
|
|
||||||
test "ensure Pleroma.Upload base_url is always whitelisted" do
|
test "ensure Pleroma.Upload base_url is always whitelisted" do
|
||||||
media_url = "https://media.pleroma.social"
|
media_url = "https://media.pleroma.social"
|
||||||
clear_config([Pleroma.Upload, :base_url], media_url)
|
|
||||||
|
ConfigMock
|
||||||
|
|> stub(:get, fn
|
||||||
|
[Pleroma.Upload, :base_url] -> media_url
|
||||||
|
path -> Pleroma.Test.StaticConfig.get(path)
|
||||||
|
end)
|
||||||
|
|
||||||
url = "#{media_url}/static/logo.png"
|
url = "#{media_url}/static/logo.png"
|
||||||
encoded = MediaProxy.url(url)
|
encoded = MediaProxy.url(url)
|
||||||
|
|
|
@ -4,9 +4,19 @@
|
||||||
|
|
||||||
defmodule Pleroma.Web.Metadata.Providers.OpenGraphTest do
|
defmodule Pleroma.Web.Metadata.Providers.OpenGraphTest do
|
||||||
use Pleroma.DataCase
|
use Pleroma.DataCase
|
||||||
|
import Mox
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
|
|
||||||
|
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||||
alias Pleroma.Web.Metadata.Providers.OpenGraph
|
alias Pleroma.Web.Metadata.Providers.OpenGraph
|
||||||
|
|
||||||
|
setup do
|
||||||
|
ConfigMock
|
||||||
|
|> stub_with(Pleroma.Test.StaticConfig)
|
||||||
|
|
||||||
|
:ok
|
||||||
|
end
|
||||||
|
|
||||||
setup do: clear_config([Pleroma.Web.Metadata, :unfurl_nsfw])
|
setup do: clear_config([Pleroma.Web.Metadata, :unfurl_nsfw])
|
||||||
|
|
||||||
test "it renders all supported types of attachments and skips unknown types" do
|
test "it renders all supported types of attachments and skips unknown types" do
|
||||||
|
|
|
@ -5,12 +5,17 @@
|
||||||
defmodule Pleroma.Web.PleromaAPI.BackupControllerTest do
|
defmodule Pleroma.Web.PleromaAPI.BackupControllerTest do
|
||||||
use Pleroma.Web.ConnCase
|
use Pleroma.Web.ConnCase
|
||||||
|
|
||||||
|
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||||
alias Pleroma.User.Backup
|
alias Pleroma.User.Backup
|
||||||
alias Pleroma.Web.PleromaAPI.BackupView
|
alias Pleroma.Web.PleromaAPI.BackupView
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
clear_config([Pleroma.Upload, :uploader])
|
clear_config([Pleroma.Upload, :uploader])
|
||||||
clear_config([Backup, :limit_days])
|
clear_config([Backup, :limit_days])
|
||||||
|
|
||||||
|
ConfigMock
|
||||||
|
|> Mox.stub_with(Pleroma.Config)
|
||||||
|
|
||||||
oauth_access(["read:backups"])
|
oauth_access(["read:backups"])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -7,10 +7,12 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
|
||||||
alias Pleroma.Chat
|
alias Pleroma.Chat
|
||||||
alias Pleroma.Chat.MessageReference
|
alias Pleroma.Chat.MessageReference
|
||||||
alias Pleroma.Object
|
alias Pleroma.Object
|
||||||
|
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||||
alias Pleroma.Web.CommonAPI
|
alias Pleroma.Web.CommonAPI
|
||||||
|
|
||||||
|
import Mox
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
|
|
||||||
describe "POST /api/v1/pleroma/chats/:id/messages/:message_id/read" do
|
describe "POST /api/v1/pleroma/chats/:id/messages/:message_id/read" do
|
||||||
|
@ -112,6 +114,9 @@ test "it works with an attachment", %{conn: conn, user: user} do
|
||||||
filename: "an_image.jpg"
|
filename: "an_image.jpg"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ConfigMock
|
||||||
|
|> stub_with(Pleroma.Test.StaticConfig)
|
||||||
|
|
||||||
{:ok, upload} = ActivityPub.upload(file, actor: user.ap_id)
|
{:ok, upload} = ActivityPub.upload(file, actor: user.ap_id)
|
||||||
|
|
||||||
other_user = insert(:user)
|
other_user = insert(:user)
|
||||||
|
|
|
@ -5,8 +5,11 @@
|
||||||
defmodule Pleroma.Web.PleromaAPI.MascotControllerTest do
|
defmodule Pleroma.Web.PleromaAPI.MascotControllerTest do
|
||||||
use Pleroma.Web.ConnCase, async: true
|
use Pleroma.Web.ConnCase, async: true
|
||||||
|
|
||||||
|
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
|
|
||||||
|
import Mox
|
||||||
|
|
||||||
test "mascot upload" do
|
test "mascot upload" do
|
||||||
%{conn: conn} = oauth_access(["write:accounts"])
|
%{conn: conn} = oauth_access(["write:accounts"])
|
||||||
|
|
||||||
|
@ -29,6 +32,9 @@ test "mascot upload" do
|
||||||
filename: "an_image.jpg"
|
filename: "an_image.jpg"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ConfigMock
|
||||||
|
|> stub_with(Pleroma.Test.StaticConfig)
|
||||||
|
|
||||||
conn =
|
conn =
|
||||||
conn
|
conn
|
||||||
|> put_req_header("content-type", "multipart/form-data")
|
|> put_req_header("content-type", "multipart/form-data")
|
||||||
|
@ -53,6 +59,9 @@ test "mascot retrieving" do
|
||||||
filename: "an_image.jpg"
|
filename: "an_image.jpg"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ConfigMock
|
||||||
|
|> stub_with(Pleroma.Test.StaticConfig)
|
||||||
|
|
||||||
ret_conn =
|
ret_conn =
|
||||||
conn
|
conn
|
||||||
|> put_req_header("content-type", "multipart/form-data")
|
|> put_req_header("content-type", "multipart/form-data")
|
||||||
|
|
|
@ -4,10 +4,21 @@
|
||||||
|
|
||||||
defmodule Pleroma.Web.PleromaAPI.BackupViewTest do
|
defmodule Pleroma.Web.PleromaAPI.BackupViewTest do
|
||||||
use Pleroma.DataCase, async: true
|
use Pleroma.DataCase, async: true
|
||||||
|
|
||||||
|
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||||
alias Pleroma.User.Backup
|
alias Pleroma.User.Backup
|
||||||
alias Pleroma.Web.PleromaAPI.BackupView
|
alias Pleroma.Web.PleromaAPI.BackupView
|
||||||
|
|
||||||
|
import Mox
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
|
|
||||||
|
setup do
|
||||||
|
ConfigMock
|
||||||
|
|> stub_with(Pleroma.Test.StaticConfig)
|
||||||
|
|
||||||
|
:ok
|
||||||
|
end
|
||||||
|
|
||||||
test "it renders the ID" do
|
test "it renders the ID" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
backup = Backup.new(user)
|
backup = Backup.new(user)
|
||||||
|
|
|
@ -3,21 +3,28 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.Web.PleromaAPI.ChatMessageReferenceViewTest do
|
defmodule Pleroma.Web.PleromaAPI.ChatMessageReferenceViewTest do
|
||||||
use Pleroma.DataCase
|
alias Pleroma.NullCache
|
||||||
|
use Pleroma.DataCase, async: true
|
||||||
|
|
||||||
alias Pleroma.Chat
|
alias Pleroma.Chat
|
||||||
alias Pleroma.Chat.MessageReference
|
alias Pleroma.Chat.MessageReference
|
||||||
alias Pleroma.Object
|
alias Pleroma.Object
|
||||||
|
alias Pleroma.StaticStubbedConfigMock
|
||||||
|
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||||
alias Pleroma.Web.CommonAPI
|
alias Pleroma.Web.CommonAPI
|
||||||
alias Pleroma.Web.PleromaAPI.Chat.MessageReferenceView
|
alias Pleroma.Web.PleromaAPI.Chat.MessageReferenceView
|
||||||
|
|
||||||
|
import Mox
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
|
|
||||||
test "it displays a chat message" do
|
test "it displays a chat message" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
recipient = insert(:user)
|
recipient = insert(:user)
|
||||||
|
|
||||||
|
ConfigMock
|
||||||
|
|> stub_with(Pleroma.Test.StaticConfig)
|
||||||
|
|
||||||
file = %Plug.Upload{
|
file = %Plug.Upload{
|
||||||
content_type: "image/jpeg",
|
content_type: "image/jpeg",
|
||||||
path: Path.absname("test/fixtures/image.jpg"),
|
path: Path.absname("test/fixtures/image.jpg"),
|
||||||
|
@ -35,6 +42,14 @@ test "it displays a chat message" do
|
||||||
|
|
||||||
cm_ref = MessageReference.for_chat_and_object(chat, object)
|
cm_ref = MessageReference.for_chat_and_object(chat, object)
|
||||||
|
|
||||||
|
id = cm_ref.id
|
||||||
|
|
||||||
|
Pleroma.CachexMock
|
||||||
|
|> stub(:get, fn
|
||||||
|
:chat_message_id_idempotency_key_cache, ^id -> {:ok, "123"}
|
||||||
|
cache, key -> NullCache.get(cache, key)
|
||||||
|
end)
|
||||||
|
|
||||||
chat_message = MessageReferenceView.render("show.json", chat_message_reference: cm_ref)
|
chat_message = MessageReferenceView.render("show.json", chat_message_reference: cm_ref)
|
||||||
|
|
||||||
assert chat_message[:id] == cm_ref.id
|
assert chat_message[:id] == cm_ref.id
|
||||||
|
@ -46,7 +61,11 @@ test "it displays a chat message" do
|
||||||
assert match?([%{shortcode: "firefox"}], chat_message[:emojis])
|
assert match?([%{shortcode: "firefox"}], chat_message[:emojis])
|
||||||
assert chat_message[:idempotency_key] == "123"
|
assert chat_message[:idempotency_key] == "123"
|
||||||
|
|
||||||
clear_config([:rich_media, :enabled], true)
|
StaticStubbedConfigMock
|
||||||
|
|> stub(:get, fn
|
||||||
|
[:rich_media, :enabled] -> true
|
||||||
|
path -> Pleroma.Test.StaticConfig.get(path)
|
||||||
|
end)
|
||||||
|
|
||||||
Tesla.Mock.mock_global(fn
|
Tesla.Mock.mock_global(fn
|
||||||
%{url: "https://example.com/ogp"} ->
|
%{url: "https://example.com/ogp"} ->
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.Web.Plugs.EnsurePrivilegedPlugTest do
|
defmodule Pleroma.Web.Plugs.EnsurePrivilegedPlugTest do
|
||||||
use Pleroma.Web.ConnCase, async: true
|
use Pleroma.Web.ConnCase
|
||||||
|
|
||||||
alias Pleroma.Web.Plugs.EnsurePrivilegedPlug
|
alias Pleroma.Web.Plugs.EnsurePrivilegedPlug
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
|
|
|
@ -4,7 +4,11 @@
|
||||||
|
|
||||||
defmodule Pleroma.Web.Plugs.FrontendStaticPlugTest do
|
defmodule Pleroma.Web.Plugs.FrontendStaticPlugTest do
|
||||||
use Pleroma.Web.ConnCase
|
use Pleroma.Web.ConnCase
|
||||||
|
|
||||||
import Mock
|
import Mock
|
||||||
|
import Mox
|
||||||
|
|
||||||
|
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||||
|
|
||||||
@dir "test/tmp/instance_static"
|
@dir "test/tmp/instance_static"
|
||||||
|
|
||||||
|
@ -66,6 +70,9 @@ test "exclude invalid path", %{conn: conn} do
|
||||||
File.mkdir_p!("#{path}/proxy/rr/ss")
|
File.mkdir_p!("#{path}/proxy/rr/ss")
|
||||||
File.write!("#{path}/proxy/rr/ss/Ek7w8WPVcAApOvN.jpg:large", "FB image")
|
File.write!("#{path}/proxy/rr/ss/Ek7w8WPVcAApOvN.jpg:large", "FB image")
|
||||||
|
|
||||||
|
ConfigMock
|
||||||
|
|> stub_with(Pleroma.Test.StaticConfig)
|
||||||
|
|
||||||
url =
|
url =
|
||||||
Pleroma.Web.MediaProxy.encode_url("https://pbs.twimg.com/media/Ek7w8WPVcAApOvN.jpg:large")
|
Pleroma.Web.MediaProxy.encode_url("https://pbs.twimg.com/media/Ek7w8WPVcAApOvN.jpg:large")
|
||||||
|
|
||||||
|
|
|
@ -4,10 +4,18 @@
|
||||||
|
|
||||||
defmodule Pleroma.Web.Plugs.UploadedMediaPlugTest do
|
defmodule Pleroma.Web.Plugs.UploadedMediaPlugTest do
|
||||||
use Pleroma.Web.ConnCase, async: true
|
use Pleroma.Web.ConnCase, async: true
|
||||||
|
|
||||||
|
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||||
alias Pleroma.Upload
|
alias Pleroma.Upload
|
||||||
|
|
||||||
|
import Mox
|
||||||
|
|
||||||
defp upload_file(context) do
|
defp upload_file(context) do
|
||||||
|
ConfigMock
|
||||||
|
|> stub_with(Pleroma.Test.StaticConfig)
|
||||||
|
|
||||||
Pleroma.DataCase.ensure_local_uploader(context)
|
Pleroma.DataCase.ensure_local_uploader(context)
|
||||||
|
|
||||||
File.cp!("test/fixtures/image.jpg", "test/fixtures/image_tmp.jpg")
|
File.cp!("test/fixtures/image.jpg", "test/fixtures/image_tmp.jpg")
|
||||||
|
|
||||||
file = %Plug.Upload{
|
file = %Plug.Upload{
|
||||||
|
@ -23,6 +31,13 @@ defp upload_file(context) do
|
||||||
|
|
||||||
setup_all :upload_file
|
setup_all :upload_file
|
||||||
|
|
||||||
|
setup do
|
||||||
|
ConfigMock
|
||||||
|
|> stub_with(Pleroma.Test.StaticConfig)
|
||||||
|
|
||||||
|
:ok
|
||||||
|
end
|
||||||
|
|
||||||
test "does not send Content-Disposition header when name param is not set", %{
|
test "does not send Content-Disposition header when name param is not set", %{
|
||||||
attachment_url: attachment_url
|
attachment_url: attachment_url
|
||||||
} do
|
} do
|
||||||
|
|
|
@ -5,10 +5,12 @@
|
||||||
defmodule Pleroma.Web.Push.ImplTest do
|
defmodule Pleroma.Web.Push.ImplTest do
|
||||||
use Pleroma.DataCase, async: true
|
use Pleroma.DataCase, async: true
|
||||||
|
|
||||||
|
import Mox
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
|
|
||||||
alias Pleroma.Notification
|
alias Pleroma.Notification
|
||||||
alias Pleroma.Object
|
alias Pleroma.Object
|
||||||
|
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||||
alias Pleroma.Web.CommonAPI
|
alias Pleroma.Web.CommonAPI
|
||||||
|
@ -257,6 +259,9 @@ test "builds content for chat messages with no content" do
|
||||||
filename: "an_image.jpg"
|
filename: "an_image.jpg"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ConfigMock
|
||||||
|
|> stub_with(Pleroma.Test.StaticConfig)
|
||||||
|
|
||||||
{:ok, upload} = ActivityPub.upload(file, actor: user.ap_id)
|
{:ok, upload} = ActivityPub.upload(file, actor: user.ap_id)
|
||||||
|
|
||||||
{:ok, chat} = CommonAPI.post_chat_message(user, recipient, nil, media_id: upload.id)
|
{:ok, chat} = CommonAPI.post_chat_message(user, recipient, nil, media_id: upload.id)
|
||||||
|
|
|
@ -3,22 +3,31 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.Web.RichMedia.HelpersTest do
|
defmodule Pleroma.Web.RichMedia.HelpersTest do
|
||||||
use Pleroma.DataCase
|
use Pleroma.DataCase, async: true
|
||||||
|
|
||||||
|
alias Pleroma.StaticStubbedConfigMock, as: ConfigMock
|
||||||
alias Pleroma.Web.CommonAPI
|
alias Pleroma.Web.CommonAPI
|
||||||
alias Pleroma.Web.RichMedia.Helpers
|
alias Pleroma.Web.RichMedia.Helpers
|
||||||
|
|
||||||
|
import Mox
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
import Tesla.Mock
|
import Tesla.Mock
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||||
|
|
||||||
|
ConfigMock
|
||||||
|
|> stub(:get, fn
|
||||||
|
[:rich_media, :enabled] -> false
|
||||||
|
path -> Pleroma.Test.StaticConfig.get(path)
|
||||||
|
end)
|
||||||
|
|> stub(:get, fn
|
||||||
|
path, default -> Pleroma.Test.StaticConfig.get(path, default)
|
||||||
|
end)
|
||||||
|
|
||||||
:ok
|
:ok
|
||||||
end
|
end
|
||||||
|
|
||||||
setup do: clear_config([:rich_media, :enabled])
|
|
||||||
|
|
||||||
test "refuses to crawl incomplete URLs" do
|
test "refuses to crawl incomplete URLs" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
|
||||||
|
@ -28,7 +37,11 @@ test "refuses to crawl incomplete URLs" do
|
||||||
content_type: "text/markdown"
|
content_type: "text/markdown"
|
||||||
})
|
})
|
||||||
|
|
||||||
clear_config([:rich_media, :enabled], true)
|
ConfigMock
|
||||||
|
|> stub(:get, fn
|
||||||
|
[:rich_media, :enabled] -> true
|
||||||
|
path -> Pleroma.Test.StaticConfig.get(path)
|
||||||
|
end)
|
||||||
|
|
||||||
assert %{} == Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
|
assert %{} == Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
|
||||||
end
|
end
|
||||||
|
@ -42,7 +55,11 @@ test "refuses to crawl malformed URLs" do
|
||||||
content_type: "text/markdown"
|
content_type: "text/markdown"
|
||||||
})
|
})
|
||||||
|
|
||||||
clear_config([:rich_media, :enabled], true)
|
ConfigMock
|
||||||
|
|> stub(:get, fn
|
||||||
|
[:rich_media, :enabled] -> true
|
||||||
|
path -> Pleroma.Test.StaticConfig.get(path)
|
||||||
|
end)
|
||||||
|
|
||||||
assert %{} == Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
|
assert %{} == Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
|
||||||
end
|
end
|
||||||
|
@ -56,12 +73,18 @@ test "crawls valid, complete URLs" do
|
||||||
content_type: "text/markdown"
|
content_type: "text/markdown"
|
||||||
})
|
})
|
||||||
|
|
||||||
clear_config([:rich_media, :enabled], true)
|
ConfigMock
|
||||||
|
|> stub(:get, fn
|
||||||
|
[:rich_media, :enabled] -> true
|
||||||
|
path -> Pleroma.Test.StaticConfig.get(path)
|
||||||
|
end)
|
||||||
|
|
||||||
assert %{page_url: "https://example.com/ogp", rich_media: _} =
|
assert %{page_url: "https://example.com/ogp", rich_media: _} =
|
||||||
Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
|
Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# This does not seem to work. The urls are being fetched.
|
||||||
|
@tag skip: true
|
||||||
test "refuses to crawl URLs of private network from posts" do
|
test "refuses to crawl URLs of private network from posts" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
|
||||||
|
@ -73,7 +96,11 @@ test "refuses to crawl URLs of private network from posts" do
|
||||||
{:ok, activity4} = CommonAPI.post(user, %{status: "https://192.168.10.40/notice/9kCP7V"})
|
{:ok, activity4} = CommonAPI.post(user, %{status: "https://192.168.10.40/notice/9kCP7V"})
|
||||||
{:ok, activity5} = CommonAPI.post(user, %{status: "https://pleroma.local/notice/9kCP7V"})
|
{:ok, activity5} = CommonAPI.post(user, %{status: "https://pleroma.local/notice/9kCP7V"})
|
||||||
|
|
||||||
clear_config([:rich_media, :enabled], true)
|
ConfigMock
|
||||||
|
|> stub(:get, fn
|
||||||
|
[:rich_media, :enabled] -> true
|
||||||
|
path -> Pleroma.Test.StaticConfig.get(path)
|
||||||
|
end)
|
||||||
|
|
||||||
assert %{} = Helpers.fetch_data_for_activity(activity)
|
assert %{} = Helpers.fetch_data_for_activity(activity)
|
||||||
assert %{} = Helpers.fetch_data_for_activity(activity2)
|
assert %{} = Helpers.fetch_data_for_activity(activity2)
|
||||||
|
|
|
@ -3,16 +3,18 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do
|
defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do
|
||||||
use Pleroma.Web.ConnCase, async: true
|
use Pleroma.Web.ConnCase
|
||||||
|
|
||||||
alias Pleroma.MFA
|
alias Pleroma.MFA
|
||||||
alias Pleroma.MFA.TOTP
|
alias Pleroma.MFA.TOTP
|
||||||
|
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
alias Pleroma.Web.CommonAPI
|
alias Pleroma.Web.CommonAPI
|
||||||
|
|
||||||
import ExUnit.CaptureLog
|
|
||||||
import Pleroma.Factory
|
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
|
import ExUnit.CaptureLog
|
||||||
|
import Mox
|
||||||
|
import Pleroma.Factory
|
||||||
|
|
||||||
setup_all do: clear_config([:instance, :federating], true)
|
setup_all do: clear_config([:instance, :federating], true)
|
||||||
setup do: clear_config([:user, :deny_follow_blocked])
|
setup do: clear_config([:user, :deny_follow_blocked])
|
||||||
|
@ -429,6 +431,9 @@ test "without media proxy" do
|
||||||
test "with media proxy" do
|
test "with media proxy" do
|
||||||
clear_config([:media_proxy, :enabled], true)
|
clear_config([:media_proxy, :enabled], true)
|
||||||
|
|
||||||
|
ConfigMock
|
||||||
|
|> stub_with(Pleroma.Test.StaticConfig)
|
||||||
|
|
||||||
user =
|
user =
|
||||||
insert(:user, %{
|
insert(:user, %{
|
||||||
local: false,
|
local: false,
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.Workers.PurgeExpiredTokenTest do
|
defmodule Pleroma.Workers.PurgeExpiredTokenTest do
|
||||||
use Pleroma.DataCase, async: true
|
use Pleroma.DataCase
|
||||||
use Oban.Testing, repo: Pleroma.Repo
|
use Oban.Testing, repo: Pleroma.Repo
|
||||||
|
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.Workers.ReceiverWorkerTest do
|
defmodule Pleroma.Workers.ReceiverWorkerTest do
|
||||||
use Pleroma.DataCase, async: true
|
use Pleroma.DataCase
|
||||||
use Oban.Testing, repo: Pleroma.Repo
|
use Oban.Testing, repo: Pleroma.Repo
|
||||||
|
|
||||||
import Mock
|
import Mock
|
||||||
|
|
|
@ -115,6 +115,7 @@ def stub_pipeline do
|
||||||
Mox.stub_with(Pleroma.Web.ActivityPub.ActivityPubMock, Pleroma.Web.ActivityPub.ActivityPub)
|
Mox.stub_with(Pleroma.Web.ActivityPub.ActivityPubMock, Pleroma.Web.ActivityPub.ActivityPub)
|
||||||
Mox.stub_with(Pleroma.Web.FederatorMock, Pleroma.Web.Federator)
|
Mox.stub_with(Pleroma.Web.FederatorMock, Pleroma.Web.Federator)
|
||||||
Mox.stub_with(Pleroma.ConfigMock, Pleroma.Config)
|
Mox.stub_with(Pleroma.ConfigMock, Pleroma.Config)
|
||||||
|
Mox.stub_with(Pleroma.StaticStubbedConfigMock, Pleroma.Test.StaticConfig)
|
||||||
end
|
end
|
||||||
|
|
||||||
def ensure_local_uploader(context) do
|
def ensure_local_uploader(context) do
|
||||||
|
|
|
@ -27,5 +27,10 @@
|
||||||
|
|
||||||
Mox.defmock(Pleroma.ConfigMock, for: Pleroma.Config.Getting)
|
Mox.defmock(Pleroma.ConfigMock, for: Pleroma.Config.Getting)
|
||||||
Mox.defmock(Pleroma.UnstubbedConfigMock, for: Pleroma.Config.Getting)
|
Mox.defmock(Pleroma.UnstubbedConfigMock, for: Pleroma.Config.Getting)
|
||||||
|
Mox.defmock(Pleroma.StaticStubbedConfigMock, for: Pleroma.Config.Getting)
|
||||||
|
|
||||||
Mox.defmock(Pleroma.LoggerMock, for: Pleroma.Logging)
|
Mox.defmock(Pleroma.LoggerMock, for: Pleroma.Logging)
|
||||||
|
|
||||||
|
Mox.defmock(Pleroma.User.Backup.ProcessorMock, for: Pleroma.User.Backup.ProcessorAPI)
|
||||||
|
|
||||||
|
Mox.defmock(Pleroma.Uploaders.S3.ExAwsMock, for: Pleroma.Uploaders.S3.ExAwsAPI)
|
||||||
|
|
|
@ -4,8 +4,7 @@
|
||||||
|
|
||||||
Code.put_compiler_option(:warnings_as_errors, true)
|
Code.put_compiler_option(:warnings_as_errors, true)
|
||||||
|
|
||||||
os_exclude = if :os.type() == {:unix, :darwin}, do: [skip_on_mac: true], else: []
|
ExUnit.start(exclude: [:federated, :erratic])
|
||||||
ExUnit.start(exclude: [:federated, :erratic] ++ os_exclude)
|
|
||||||
|
|
||||||
Ecto.Adapters.SQL.Sandbox.mode(Pleroma.Repo, :manual)
|
Ecto.Adapters.SQL.Sandbox.mode(Pleroma.Repo, :manual)
|
||||||
|
|
||||||
|
@ -18,3 +17,16 @@
|
||||||
uploads = Pleroma.Config.get([Pleroma.Uploaders.Local, :uploads], "test/uploads")
|
uploads = Pleroma.Config.get([Pleroma.Uploaders.Local, :uploads], "test/uploads")
|
||||||
File.rm_rf!(uploads)
|
File.rm_rf!(uploads)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
defmodule Pleroma.Test.StaticConfig do
|
||||||
|
@moduledoc """
|
||||||
|
This module provides a Config that is completely static, built at startup time from the environment. It's safe to use in testing as it will not modify any state.
|
||||||
|
"""
|
||||||
|
|
||||||
|
@behaviour Pleroma.Config.Getting
|
||||||
|
@config Application.get_all_env(:pleroma)
|
||||||
|
|
||||||
|
def get(path, default \\ nil) do
|
||||||
|
get_in(@config, path) || default
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in New Issue