Merge branch 'assorted-test-fixes' into secfix

This commit is contained in:
Lain Soykaf 2025-03-10 16:04:46 +04:00
commit edcd816730
35 changed files with 184 additions and 87 deletions

View file

@ -147,6 +147,7 @@ config :pleroma, Pleroma.Search.Meilisearch, url: "http://127.0.0.1:7700/", priv
config :phoenix, :plug_init_mode, :runtime config :phoenix, :plug_init_mode, :runtime
config :pleroma, :config_impl, Pleroma.UnstubbedConfigMock config :pleroma, :config_impl, Pleroma.UnstubbedConfigMock
config :pleroma, :datetime_impl, Pleroma.DateTimeMock
config :pleroma, Pleroma.PromEx, disabled: true config :pleroma, Pleroma.PromEx, disabled: true
@ -161,6 +162,12 @@ config :pleroma, Pleroma.Uploaders.IPFS, config_impl: Pleroma.UnstubbedConfigMoc
config :pleroma, Pleroma.Web.Plugs.HTTPSecurityPlug, config_impl: Pleroma.StaticStubbedConfigMock config :pleroma, Pleroma.Web.Plugs.HTTPSecurityPlug, config_impl: Pleroma.StaticStubbedConfigMock
config :pleroma, Pleroma.Web.Plugs.HTTPSignaturePlug, config_impl: Pleroma.StaticStubbedConfigMock config :pleroma, Pleroma.Web.Plugs.HTTPSignaturePlug, config_impl: Pleroma.StaticStubbedConfigMock
config :pleroma, Pleroma.Upload.Filter.AnonymizeFilename,
config_impl: Pleroma.StaticStubbedConfigMock
config :pleroma, Pleroma.Upload.Filter.Mogrify, config_impl: Pleroma.StaticStubbedConfigMock
config :pleroma, Pleroma.Upload.Filter.Mogrify, mogrify_impl: Pleroma.MogrifyMock
config :pleroma, Pleroma.Signature, http_signatures_impl: Pleroma.StubbedHTTPSignaturesMock config :pleroma, Pleroma.Signature, http_signatures_impl: Pleroma.StubbedHTTPSignaturesMock
peer_module = peer_module =

View file

@ -27,6 +27,7 @@ defmodule Pleroma.Config do
Application.get_env(:pleroma, key, default) Application.get_env(:pleroma, key, default)
end end
@impl true
def get!(key) do def get!(key) do
value = get(key, nil) value = get(key, nil)

View file

@ -5,10 +5,13 @@
defmodule Pleroma.Config.Getting do defmodule Pleroma.Config.Getting do
@callback get(any()) :: any() @callback get(any()) :: any()
@callback get(any(), any()) :: any() @callback get(any(), any()) :: any()
@callback get!(any()) :: any()
def get(key), do: get(key, nil) def get(key), do: get(key, nil)
def get(key, default), do: impl().get(key, default) def get(key, default), do: impl().get(key, default)
def get!(key), do: impl().get!(key)
def impl do def impl do
Application.get_env(:pleroma, :config_impl, Pleroma.Config) Application.get_env(:pleroma, :config_impl, Pleroma.Config)
end end

3
lib/pleroma/datetime.ex Normal file
View file

@ -0,0 +1,3 @@
defmodule Pleroma.DateTime do
@callback utc_now() :: NaiveDateTime.t()
end

View file

@ -0,0 +1,6 @@
defmodule Pleroma.DateTime.Impl do
@behaviour Pleroma.DateTime
@impl true
def utc_now, do: NaiveDateTime.utc_now()
end

42
lib/pleroma/mogrify.ex Normal file
View file

@ -0,0 +1,42 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.MogrifyBehaviour do
@moduledoc """
Behaviour for Mogrify operations.
This module defines the interface for Mogrify operations that can be mocked in tests.
"""
@callback open(binary()) :: map()
@callback custom(map(), binary()) :: map()
@callback custom(map(), binary(), binary()) :: map()
@callback save(map(), keyword()) :: map()
end
defmodule Pleroma.MogrifyWrapper do
@moduledoc """
Default implementation of MogrifyBehaviour that delegates to Mogrify.
"""
@behaviour Pleroma.MogrifyBehaviour
@impl true
def open(file) do
Mogrify.open(file)
end
@impl true
def custom(image, action) do
Mogrify.custom(image, action)
end
@impl true
def custom(image, action, options) do
Mogrify.custom(image, action, options)
end
@impl true
def save(image, opts) do
Mogrify.save(image, opts)
end
end

View file

@ -10,7 +10,7 @@ defmodule Pleroma.Upload.Filter.AnonymizeFilename do
""" """
@behaviour Pleroma.Upload.Filter @behaviour Pleroma.Upload.Filter
alias Pleroma.Config @config_impl Application.compile_env(:pleroma, [__MODULE__, :config_impl], Pleroma.Config)
alias Pleroma.Upload alias Pleroma.Upload
def filter(%Upload{name: name} = upload) do def filter(%Upload{name: name} = upload) do
@ -23,7 +23,7 @@ defmodule Pleroma.Upload.Filter.AnonymizeFilename do
@spec predefined_name(String.t()) :: String.t() | nil @spec predefined_name(String.t()) :: String.t() | nil
defp predefined_name(extension) do defp predefined_name(extension) do
with name when not is_nil(name) <- Config.get([__MODULE__, :text]), with name when not is_nil(name) <- @config_impl.get([__MODULE__, :text]),
do: String.replace(name, "{extension}", extension) do: String.replace(name, "{extension}", extension)
end end

View file

@ -8,9 +8,16 @@ defmodule Pleroma.Upload.Filter.Mogrify do
@type conversion :: action :: String.t() | {action :: String.t(), opts :: String.t()} @type conversion :: action :: String.t() | {action :: String.t(), opts :: String.t()}
@type conversions :: conversion() | [conversion()] @type conversions :: conversion() | [conversion()]
@config_impl Application.compile_env(:pleroma, [__MODULE__, :config_impl], Pleroma.Config)
@mogrify_impl Application.compile_env(
:pleroma,
[__MODULE__, :mogrify_impl],
Pleroma.MogrifyWrapper
)
def filter(%Pleroma.Upload{tempfile: file, content_type: "image" <> _}) do def filter(%Pleroma.Upload{tempfile: file, content_type: "image" <> _}) do
try do try do
do_filter(file, Pleroma.Config.get!([__MODULE__, :args])) do_filter(file, @config_impl.get!([__MODULE__, :args]))
{:ok, :filtered} {:ok, :filtered}
rescue rescue
e in ErlangError -> e in ErlangError ->
@ -22,9 +29,9 @@ defmodule Pleroma.Upload.Filter.Mogrify do
def do_filter(file, filters) do def do_filter(file, filters) do
file file
|> Mogrify.open() |> @mogrify_impl.open()
|> mogrify_filter(filters) |> mogrify_filter(filters)
|> Mogrify.save(in_place: true) |> @mogrify_impl.save(in_place: true)
end end
defp mogrify_filter(mogrify, nil), do: mogrify defp mogrify_filter(mogrify, nil), do: mogrify
@ -38,10 +45,10 @@ defmodule Pleroma.Upload.Filter.Mogrify do
defp mogrify_filter(mogrify, []), do: mogrify defp mogrify_filter(mogrify, []), do: mogrify
defp mogrify_filter(mogrify, {action, options}) do defp mogrify_filter(mogrify, {action, options}) do
Mogrify.custom(mogrify, action, options) @mogrify_impl.custom(mogrify, action, options)
end end
defp mogrify_filter(mogrify, action) when is_binary(action) do defp mogrify_filter(mogrify, action) when is_binary(action) do
Mogrify.custom(mogrify, action) @mogrify_impl.custom(mogrify, action)
end end
end end

View file

@ -55,9 +55,13 @@ defmodule Pleroma.UserRelationship do
def user_relationship_mappings, do: Pleroma.UserRelationship.Type.__enum_map__() def user_relationship_mappings, do: Pleroma.UserRelationship.Type.__enum_map__()
def datetime_impl do
Application.get_env(:pleroma, :datetime_impl, Pleroma.DateTime.Impl)
end
def changeset(%UserRelationship{} = user_relationship, params \\ %{}) do def changeset(%UserRelationship{} = user_relationship, params \\ %{}) do
user_relationship user_relationship
|> cast(params, [:relationship_type, :source_id, :target_id, :expires_at]) |> cast(params, [:relationship_type, :source_id, :target_id, :expires_at, :inserted_at])
|> validate_required([:relationship_type, :source_id, :target_id]) |> validate_required([:relationship_type, :source_id, :target_id])
|> unique_constraint(:relationship_type, |> unique_constraint(:relationship_type,
name: :user_relationships_source_id_relationship_type_target_id_index name: :user_relationships_source_id_relationship_type_target_id_index
@ -65,6 +69,7 @@ defmodule Pleroma.UserRelationship do
|> validate_not_self_relationship() |> validate_not_self_relationship()
end end
@spec exists?(any(), Pleroma.User.t(), Pleroma.User.t()) :: boolean()
def exists?(relationship_type, %User{} = source, %User{} = target) do def exists?(relationship_type, %User{} = source, %User{} = target) do
UserRelationship UserRelationship
|> where(relationship_type: ^relationship_type, source_id: ^source.id, target_id: ^target.id) |> where(relationship_type: ^relationship_type, source_id: ^source.id, target_id: ^target.id)
@ -90,7 +95,8 @@ defmodule Pleroma.UserRelationship do
relationship_type: relationship_type, relationship_type: relationship_type,
source_id: source.id, source_id: source.id,
target_id: target.id, target_id: target.id,
expires_at: expires_at expires_at: expires_at,
inserted_at: datetime_impl().utc_now()
}) })
|> Repo.insert( |> Repo.insert(
on_conflict: {:replace_all_except, [:id, :inserted_at]}, on_conflict: {:replace_all_except, [:id, :inserted_at]},

View file

@ -24,7 +24,7 @@ defmodule Mix.Tasks.Pleroma.DigestTest do
setup do: clear_config([Pleroma.Emails.Mailer, :enabled], true) setup do: clear_config([Pleroma.Emails.Mailer, :enabled], true)
setup do setup do
Mox.stub_with(Pleroma.UnstubbedConfigMock, Pleroma.Config) Mox.stub_with(Pleroma.UnstubbedConfigMock, Pleroma.Test.StaticConfig)
:ok :ok
end end

View file

@ -21,7 +21,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
import Pleroma.Factory import Pleroma.Factory
setup do setup do
Mox.stub_with(Pleroma.UnstubbedConfigMock, Pleroma.Config) Mox.stub_with(Pleroma.UnstubbedConfigMock, Pleroma.Test.StaticConfig)
:ok :ok
end end

View file

@ -14,7 +14,7 @@ defmodule Pleroma.ConversationTest do
setup_all do: clear_config([:instance, :federating], true) setup_all do: clear_config([:instance, :federating], true)
setup do setup do
Mox.stub_with(Pleroma.UnstubbedConfigMock, Pleroma.Config) Mox.stub_with(Pleroma.UnstubbedConfigMock, Pleroma.Test.StaticConfig)
:ok :ok
end end

View file

@ -120,7 +120,7 @@ defmodule Pleroma.Emoji.PackTest do
path: Path.absname("test/instance_static/emoji/test_pack/blank.png") path: Path.absname("test/instance_static/emoji/test_pack/blank.png")
} }
assert Pack.add_file(pack, nil, nil, file) == {:error, :einval} assert {:error, _} = Pack.add_file(pack, nil, nil, file)
end end
test "returns pack when zip file is empty", %{pack: pack} do test "returns pack when zip file is empty", %{pack: pack} do

View file

@ -19,7 +19,7 @@ defmodule Pleroma.NotificationTest do
alias Pleroma.Web.MastodonAPI.NotificationView alias Pleroma.Web.MastodonAPI.NotificationView
setup do setup do
Mox.stub_with(Pleroma.UnstubbedConfigMock, Pleroma.Config) Mox.stub_with(Pleroma.UnstubbedConfigMock, Pleroma.Test.StaticConfig)
:ok :ok
end end

View file

@ -3,12 +3,11 @@
# SPDX-License-Identifier: AGPL-3.0-only # SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Repo.Migrations.AutolinkerToLinkifyTest do defmodule Pleroma.Repo.Migrations.AutolinkerToLinkifyTest do
use Pleroma.DataCase use Pleroma.DataCase, async: true
import Pleroma.Factory import Pleroma.Factory
import Pleroma.Tests.Helpers import Pleroma.Tests.Helpers
alias Pleroma.ConfigDB alias Pleroma.ConfigDB
setup do: clear_config(Pleroma.Formatter)
setup_all do: require_migration("20200716195806_autolinker_to_linkify") setup_all do: require_migration("20200716195806_autolinker_to_linkify")
test "change/0 converts auto_linker opts for Pleroma.Formatter", %{migration: migration} do test "change/0 converts auto_linker opts for Pleroma.Formatter", %{migration: migration} do

View file

@ -3,9 +3,11 @@
# SPDX-License-Identifier: AGPL-3.0-only # SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Upload.Filter.AnonymizeFilenameTest do defmodule Pleroma.Upload.Filter.AnonymizeFilenameTest do
use Pleroma.DataCase use Pleroma.DataCase, async: true
import Mox
alias Pleroma.Upload alias Pleroma.Upload
alias Pleroma.StaticStubbedConfigMock, as: ConfigMock
setup do setup do
File.cp!("test/fixtures/image.jpg", "test/fixtures/image_tmp.jpg") File.cp!("test/fixtures/image.jpg", "test/fixtures/image_tmp.jpg")
@ -19,21 +21,26 @@ defmodule Pleroma.Upload.Filter.AnonymizeFilenameTest do
%{upload_file: upload_file} %{upload_file: upload_file}
end end
setup do: clear_config([Pleroma.Upload.Filter.AnonymizeFilename, :text])
test "it replaces filename on pre-defined text", %{upload_file: upload_file} do test "it replaces filename on pre-defined text", %{upload_file: upload_file} do
clear_config([Upload.Filter.AnonymizeFilename, :text], "custom-file.png") ConfigMock
|> stub(:get, fn [Upload.Filter.AnonymizeFilename, :text] -> "custom-file.png" end)
{:ok, :filtered, %Upload{name: name}} = Upload.Filter.AnonymizeFilename.filter(upload_file) {:ok, :filtered, %Upload{name: name}} = Upload.Filter.AnonymizeFilename.filter(upload_file)
assert name == "custom-file.png" assert name == "custom-file.png"
end end
test "it replaces filename on pre-defined text expression", %{upload_file: upload_file} do test "it replaces filename on pre-defined text expression", %{upload_file: upload_file} do
clear_config([Upload.Filter.AnonymizeFilename, :text], "custom-file.{extension}") ConfigMock
|> stub(:get, fn [Upload.Filter.AnonymizeFilename, :text] -> "custom-file.{extension}" end)
{:ok, :filtered, %Upload{name: name}} = Upload.Filter.AnonymizeFilename.filter(upload_file) {:ok, :filtered, %Upload{name: name}} = Upload.Filter.AnonymizeFilename.filter(upload_file)
assert name == "custom-file.jpg" assert name == "custom-file.jpg"
end end
test "it replaces filename on random text", %{upload_file: upload_file} do test "it replaces filename on random text", %{upload_file: upload_file} do
ConfigMock
|> stub(:get, fn [Upload.Filter.AnonymizeFilename, :text] -> nil end)
{:ok, :filtered, %Upload{name: name}} = Upload.Filter.AnonymizeFilename.filter(upload_file) {:ok, :filtered, %Upload{name: name}} = Upload.Filter.AnonymizeFilename.filter(upload_file)
assert <<_::bytes-size(14)>> <> ".jpg" = name assert <<_::bytes-size(14)>> <> ".jpg" = name
refute name == "an… image.jpg" refute name == "an… image.jpg"

View file

@ -3,11 +3,12 @@
# SPDX-License-Identifier: AGPL-3.0-only # SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Upload.Filter.MogrifunTest do defmodule Pleroma.Upload.Filter.MogrifunTest do
use Pleroma.DataCase use Pleroma.DataCase, async: true
import Mock import Mox
alias Pleroma.Upload alias Pleroma.Upload
alias Pleroma.Upload.Filter alias Pleroma.Upload.Filter
alias Pleroma.MogrifyMock
test "apply mogrify filter" do test "apply mogrify filter" do
File.cp!( File.cp!(
@ -22,23 +23,12 @@ defmodule Pleroma.Upload.Filter.MogrifunTest do
tempfile: Path.absname("test/fixtures/image_tmp.jpg") tempfile: Path.absname("test/fixtures/image_tmp.jpg")
} }
task = MogrifyMock
Task.async(fn -> |> stub(:open, fn _file -> %{} end)
assert_receive {:apply_filter, {}}, 4_000 |> stub(:custom, fn _image, _action -> %{} end)
end) |> stub(:custom, fn _image, _action, _options -> %{} end)
|> stub(:save, fn _image, [in_place: true] -> :ok end)
with_mocks([
{Mogrify, [],
[
open: fn _f -> %Mogrify.Image{} end,
custom: fn _m, _a -> send(task.pid, {:apply_filter, {}}) end,
custom: fn _m, _a, _o -> send(task.pid, {:apply_filter, {}}) end,
save: fn _f, _o -> :ok end
]}
]) do
assert Filter.Mogrifun.filter(upload) == {:ok, :filtered} assert Filter.Mogrifun.filter(upload) == {:ok, :filtered}
end end
Task.await(task)
end
end end

View file

@ -3,13 +3,18 @@
# SPDX-License-Identifier: AGPL-3.0-only # SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Upload.Filter.MogrifyTest do defmodule Pleroma.Upload.Filter.MogrifyTest do
use Pleroma.DataCase use Pleroma.DataCase, async: true
import Mock import Mox
alias Pleroma.Upload.Filter alias Pleroma.Upload.Filter
alias Pleroma.StaticStubbedConfigMock, as: ConfigMock
alias Pleroma.MogrifyMock
setup :verify_on_exit!
test "apply mogrify filter" do test "apply mogrify filter" do
clear_config(Filter.Mogrify, args: [{"tint", "40"}]) ConfigMock
|> stub(:get!, fn [Filter.Mogrify, :args] -> [{"tint", "40"}] end)
File.cp!( File.cp!(
"test/fixtures/image.jpg", "test/fixtures/image.jpg",
@ -23,19 +28,11 @@ defmodule Pleroma.Upload.Filter.MogrifyTest do
tempfile: Path.absname("test/fixtures/image_tmp.jpg") tempfile: Path.absname("test/fixtures/image_tmp.jpg")
} }
task = MogrifyMock
Task.async(fn -> |> expect(:open, fn _file -> %{} end)
assert_receive {:apply_filter, {_, "tint", "40"}}, 4_000 |> expect(:custom, fn _image, "tint", "40" -> %{} end)
end) |> expect(:save, fn _image, [in_place: true] -> :ok end)
with_mock Mogrify,
open: fn _f -> %Mogrify.Image{} end,
custom: fn _m, _a -> :ok end,
custom: fn m, a, o -> send(task.pid, {:apply_filter, {m, a, o}}) end,
save: fn _f, _o -> :ok end do
assert Filter.Mogrify.filter(upload) == {:ok, :filtered} assert Filter.Mogrify.filter(upload) == {:ok, :filtered}
end end
Task.await(task)
end
end end

View file

@ -5,12 +5,13 @@
defmodule Pleroma.Upload.FilterTest do defmodule Pleroma.Upload.FilterTest do
use Pleroma.DataCase use Pleroma.DataCase
import Mox
alias Pleroma.Upload.Filter alias Pleroma.Upload.Filter
alias Pleroma.StaticStubbedConfigMock, as: ConfigMock
setup do: clear_config([Pleroma.Upload.Filter.AnonymizeFilename, :text])
test "applies filters" do test "applies filters" do
clear_config([Pleroma.Upload.Filter.AnonymizeFilename, :text], "custom-file.png") ConfigMock
|> stub(:get, fn [Pleroma.Upload.Filter.AnonymizeFilename, :text] -> "custom-file.png" end)
File.cp!( File.cp!(
"test/fixtures/image.jpg", "test/fixtures/image.jpg",

View file

@ -3,11 +3,12 @@
# SPDX-License-Identifier: AGPL-3.0-only # SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.UserRelationshipTest do defmodule Pleroma.UserRelationshipTest do
alias Pleroma.DateTimeMock
alias Pleroma.UserRelationship alias Pleroma.UserRelationship
use Pleroma.DataCase, async: false use Pleroma.DataCase, async: true
import Mock import Mox
import Pleroma.Factory import Pleroma.Factory
describe "*_exists?/2" do describe "*_exists?/2" do
@ -52,6 +53,9 @@ defmodule Pleroma.UserRelationshipTest do
end end
test "creates user relationship record if it doesn't exist", %{users: [user1, user2]} do test "creates user relationship record if it doesn't exist", %{users: [user1, user2]} do
DateTimeMock
|> stub_with(Pleroma.DateTime.Impl)
for relationship_type <- [ for relationship_type <- [
:block, :block,
:mute, :mute,
@ -80,13 +84,15 @@ defmodule Pleroma.UserRelationshipTest do
end end
test "if record already exists, returns it", %{users: [user1, user2]} do test "if record already exists, returns it", %{users: [user1, user2]} do
user_block = fixed_datetime = ~N[2017-03-17 17:09:58]
with_mock NaiveDateTime, [:passthrough], utc_now: fn -> ~N[2017-03-17 17:09:58] end do
{:ok, %{inserted_at: ~N[2017-03-17 17:09:58]}} =
UserRelationship.create_block(user1, user2)
end
assert user_block == UserRelationship.create_block(user1, user2) Pleroma.DateTimeMock
|> expect(:utc_now, 2, fn -> fixed_datetime end)
{:ok, %{inserted_at: ^fixed_datetime}} = UserRelationship.create_block(user1, user2)
# Test the idempotency without caring about the exact time
assert {:ok, _} = UserRelationship.create_block(user1, user2)
end end
end end

View file

@ -20,7 +20,7 @@ defmodule Pleroma.UserTest do
import Swoosh.TestAssertions import Swoosh.TestAssertions
setup do setup do
Mox.stub_with(Pleroma.UnstubbedConfigMock, Pleroma.Config) Mox.stub_with(Pleroma.UnstubbedConfigMock, Pleroma.Test.StaticConfig)
:ok :ok
end end

View file

@ -26,7 +26,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
require Pleroma.Constants require Pleroma.Constants
setup do setup do
Mox.stub_with(Pleroma.UnstubbedConfigMock, Pleroma.Config) Mox.stub_with(Pleroma.UnstubbedConfigMock, Pleroma.Test.StaticConfig)
:ok :ok
end end

View file

@ -1211,8 +1211,6 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
end end
test "args for Pleroma.Upload.Filter.Mogrify with custom tuples", %{conn: conn} do test "args for Pleroma.Upload.Filter.Mogrify with custom tuples", %{conn: conn} do
clear_config(Pleroma.Upload.Filter.Mogrify)
assert conn assert conn
|> put_req_header("content-type", "application/json") |> put_req_header("content-type", "application/json")
|> post("/api/pleroma/admin/config", %{ |> post("/api/pleroma/admin/config", %{
@ -1240,7 +1238,8 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
"need_reboot" => false "need_reboot" => false
} }
assert Config.get(Pleroma.Upload.Filter.Mogrify) == [args: ["auto-orient", "strip"]] config = Config.get(Pleroma.Upload.Filter.Mogrify)
assert {:args, ["auto-orient", "strip"]} in config
assert conn assert conn
|> put_req_header("content-type", "application/json") |> put_req_header("content-type", "application/json")
@ -1289,9 +1288,9 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
"need_reboot" => false "need_reboot" => false
} }
assert Config.get(Pleroma.Upload.Filter.Mogrify) == [ config = Config.get(Pleroma.Upload.Filter.Mogrify)
args: ["auto-orient", "strip", {"implode", "1"}, {"resize", "3840x1080>"}]
] assert {:args, ["auto-orient", "strip", {"implode", "1"}, {"resize", "3840x1080>"}]} in config
end end
test "enables the welcome messages", %{conn: conn} do test "enables the welcome messages", %{conn: conn} do

View file

@ -20,7 +20,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
alias Pleroma.Web.MediaProxy alias Pleroma.Web.MediaProxy
setup do setup do
Mox.stub_with(Pleroma.UnstubbedConfigMock, Pleroma.Config) Mox.stub_with(Pleroma.UnstubbedConfigMock, Pleroma.Test.StaticConfig)
:ok :ok
end end

View file

@ -19,7 +19,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
import Pleroma.Factory import Pleroma.Factory
setup do setup do
Mox.stub_with(Pleroma.UnstubbedConfigMock, Pleroma.Config) Mox.stub_with(Pleroma.UnstubbedConfigMock, Pleroma.Test.StaticConfig)
:ok :ok
end end

View file

@ -13,7 +13,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
import Pleroma.Factory import Pleroma.Factory
setup do setup do
Mox.stub_with(Pleroma.UnstubbedConfigMock, Pleroma.Config) Mox.stub_with(Pleroma.UnstubbedConfigMock, Pleroma.Test.StaticConfig)
:ok :ok
end end

View file

@ -14,7 +14,7 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
import Mock import Mock
setup do setup do
Mox.stub_with(Pleroma.UnstubbedConfigMock, Pleroma.Config) Mox.stub_with(Pleroma.UnstubbedConfigMock, Pleroma.Test.StaticConfig)
:ok :ok
end end

View file

@ -23,7 +23,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do
import Pleroma.Factory import Pleroma.Factory
setup do setup do
Mox.stub_with(Pleroma.UnstubbedConfigMock, Pleroma.Config) Mox.stub_with(Pleroma.UnstubbedConfigMock, Pleroma.Test.StaticConfig)
:ok :ok
end end

View file

@ -58,16 +58,28 @@ defmodule Pleroma.Web.OAuth.AppTest do
attrs = %{client_name: "Mastodon-Local", redirect_uris: "."} attrs = %{client_name: "Mastodon-Local", redirect_uris: "."}
{:ok, %App{} = old_app} = App.get_or_make(attrs, ["write"]) {:ok, %App{} = old_app} = App.get_or_make(attrs, ["write"])
# backdate the old app so it's within the threshold for being cleaned up
one_hour_ago = DateTime.add(DateTime.utc_now(), -3600)
{:ok, _} =
"UPDATE apps SET inserted_at = $1, updated_at = $1 WHERE id = $2"
|> Pleroma.Repo.query([one_hour_ago, old_app.id])
# Create the new app after backdating the old one
attrs = %{client_name: "PleromaFE", redirect_uris: "."} attrs = %{client_name: "PleromaFE", redirect_uris: "."}
{:ok, %App{} = app} = App.get_or_make(attrs, ["write"]) {:ok, %App{} = app} = App.get_or_make(attrs, ["write"])
# backdate the old app so it's within the threshold for being cleaned up # Ensure the new app has a recent timestamp
now = DateTime.utc_now()
{:ok, _} = {:ok, _} =
"UPDATE apps SET inserted_at = now() - interval '1 hour' WHERE id = #{old_app.id}" "UPDATE apps SET inserted_at = $1, updated_at = $1 WHERE id = $2"
|> Pleroma.Repo.query() |> Pleroma.Repo.query([now, app.id])
App.remove_orphans() App.remove_orphans()
assert [app] == Pleroma.Repo.all(App) assert [returned_app] = Pleroma.Repo.all(App)
assert returned_app.client_name == "PleromaFE"
assert returned_app.id == app.id
end end
end end

View file

@ -14,7 +14,7 @@ defmodule Pleroma.Web.PleromaAPI.EmojiReactionControllerTest do
import Pleroma.Factory import Pleroma.Factory
setup do setup do
Mox.stub_with(Pleroma.UnstubbedConfigMock, Pleroma.Config) Mox.stub_with(Pleroma.UnstubbedConfigMock, Pleroma.Test.StaticConfig)
:ok :ok
end end

View file

@ -14,7 +14,7 @@ defmodule Pleroma.Workers.Cron.DigestEmailsWorkerTest do
setup do: clear_config([:email_notifications, :digest]) setup do: clear_config([:email_notifications, :digest])
setup do setup do
Mox.stub_with(Pleroma.UnstubbedConfigMock, Pleroma.Config) Mox.stub_with(Pleroma.UnstubbedConfigMock, Pleroma.Test.StaticConfig)
:ok :ok
end end

View file

@ -11,7 +11,7 @@ defmodule Pleroma.Workers.Cron.NewUsersDigestWorkerTest do
alias Pleroma.Workers.Cron.NewUsersDigestWorker alias Pleroma.Workers.Cron.NewUsersDigestWorker
setup do setup do
Mox.stub_with(Pleroma.UnstubbedConfigMock, Pleroma.Config) Mox.stub_with(Pleroma.UnstubbedConfigMock, Pleroma.Test.StaticConfig)
:ok :ok
end end

View file

@ -117,6 +117,8 @@ defmodule Pleroma.DataCase do
Mox.stub_with(Pleroma.ConfigMock, Pleroma.Config) Mox.stub_with(Pleroma.ConfigMock, Pleroma.Config)
Mox.stub_with(Pleroma.StaticStubbedConfigMock, Pleroma.Test.StaticConfig) Mox.stub_with(Pleroma.StaticStubbedConfigMock, Pleroma.Test.StaticConfig)
Mox.stub_with(Pleroma.StubbedHTTPSignaturesMock, Pleroma.Test.HTTPSignaturesProxy) Mox.stub_with(Pleroma.StubbedHTTPSignaturesMock, Pleroma.Test.HTTPSignaturesProxy)
Mox.stub_with(Pleroma.DateTimeMock, Pleroma.DateTime.Impl)
end end
def ensure_local_uploader(context) do def ensure_local_uploader(context) do

View file

@ -33,3 +33,6 @@ Mox.defmock(Pleroma.StubbedHTTPSignaturesMock, for: Pleroma.HTTPSignaturesAPI)
Mox.defmock(Pleroma.LoggerMock, for: Pleroma.Logging) Mox.defmock(Pleroma.LoggerMock, for: Pleroma.Logging)
Mox.defmock(Pleroma.Uploaders.S3.ExAwsMock, for: Pleroma.Uploaders.S3.ExAwsAPI) Mox.defmock(Pleroma.Uploaders.S3.ExAwsMock, for: Pleroma.Uploaders.S3.ExAwsAPI)
Mox.defmock(Pleroma.DateTimeMock, for: Pleroma.DateTime)
Mox.defmock(Pleroma.MogrifyMock, for: Pleroma.MogrifyBehaviour)

View file

@ -34,7 +34,13 @@ defmodule Pleroma.Test.StaticConfig do
@behaviour Pleroma.Config.Getting @behaviour Pleroma.Config.Getting
@config Application.get_all_env(:pleroma) @config Application.get_all_env(:pleroma)
@impl true
def get(path, default \\ nil) do def get(path, default \\ nil) do
get_in(@config, path) || default get_in(@config, path) || default
end end
@impl true
def get!(path) do
get_in(@config, path)
end
end end