1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.ApplicationRequirementsTest do
8 import ExUnit.CaptureLog
11 alias Pleroma.ApplicationRequirements
14 describe "check_repo_pool_size!/1" do
15 test "raises if the pool size is unexpected" do
16 clear_config([Pleroma.Repo, :pool_size], 11)
17 clear_config([:dangerzone, :override_repo_pool_size], false)
19 assert_raise Pleroma.ApplicationRequirements.VerifyError,
20 "Repo.pool_size different than recommended value.",
22 capture_log(&Pleroma.ApplicationRequirements.verify!/0)
26 test "doesn't raise if the pool size is unexpected but the respective flag is set" do
27 clear_config([Pleroma.Repo, :pool_size], 11)
28 clear_config([:dangerzone, :override_repo_pool_size], true)
30 assert Pleroma.ApplicationRequirements.verify!() == :ok
34 describe "check_welcome_message_config!/1" do
35 setup do: clear_config([:welcome])
36 setup do: clear_config([Pleroma.Emails.Mailer])
38 test "raises if welcome email enabled but mail disabled" do
39 clear_config([:welcome, :email, :enabled], true)
40 clear_config([Pleroma.Emails.Mailer, :enabled], false)
42 assert_raise Pleroma.ApplicationRequirements.VerifyError, "The mail disabled.", fn ->
43 capture_log(&Pleroma.ApplicationRequirements.verify!/0)
48 describe "check_confirmation_accounts!" do
50 {Pleroma.ApplicationRequirements, [:passthrough],
52 check_migrations_applied!: fn _ -> :ok end
58 setup do: clear_config([:instance, :account_activation_required])
60 test "raises if account confirmation is required but mailer isn't enable" do
61 clear_config([:instance, :account_activation_required], true)
62 clear_config([Pleroma.Emails.Mailer, :enabled], false)
64 assert_raise Pleroma.ApplicationRequirements.VerifyError,
65 "Account activation enabled, but Mailer is disabled. Cannot send confirmation emails.",
67 capture_log(&Pleroma.ApplicationRequirements.verify!/0)
71 test "doesn't do anything if account confirmation is disabled" do
72 clear_config([:instance, :account_activation_required], false)
73 clear_config([Pleroma.Emails.Mailer, :enabled], false)
74 assert Pleroma.ApplicationRequirements.verify!() == :ok
77 test "doesn't do anything if account confirmation is required and mailer is enabled" do
78 clear_config([:instance, :account_activation_required], true)
79 clear_config([Pleroma.Emails.Mailer, :enabled], true)
80 assert Pleroma.ApplicationRequirements.verify!() == :ok
84 describe "check_rum!" do
86 {Pleroma.ApplicationRequirements, [:passthrough],
87 [check_migrations_applied!: fn _ -> :ok end]}
92 setup do: clear_config([:database, :rum_enabled])
94 test "raises if rum is enabled and detects unapplied rum migrations" do
95 clear_config([:database, :rum_enabled], true)
97 with_mocks([{Repo, [:passthrough], [exists?: fn _, _ -> false end]}]) do
98 assert_raise ApplicationRequirements.VerifyError,
99 "Unapplied RUM Migrations detected",
101 capture_log(&ApplicationRequirements.verify!/0)
106 test "raises if rum is disabled and detects rum migrations" do
107 clear_config([:database, :rum_enabled], false)
109 with_mocks([{Repo, [:passthrough], [exists?: fn _, _ -> true end]}]) do
110 assert_raise ApplicationRequirements.VerifyError,
111 "RUM Migrations detected",
113 capture_log(&ApplicationRequirements.verify!/0)
118 test "doesn't do anything if rum enabled and applied migrations" do
119 clear_config([:database, :rum_enabled], true)
121 with_mocks([{Repo, [:passthrough], [exists?: fn _, _ -> true end]}]) do
122 assert ApplicationRequirements.verify!() == :ok
126 test "doesn't do anything if rum disabled" do
127 clear_config([:database, :rum_enabled], false)
129 with_mocks([{Repo, [:passthrough], [exists?: fn _, _ -> false end]}]) do
130 assert ApplicationRequirements.verify!() == :ok
135 describe "check_migrations_applied!" do
139 with_repo: fn repo, fun -> passthrough([repo, fun]) end,
140 migrations: fn Repo ->
142 {:up, 20_191_128_153_944, "fix_missing_following_count"},
143 {:up, 20_191_203_043_610, "create_report_notes"},
144 {:down, 20_191_220_174_645, "add_scopes_to_pleroma_feo_auth_records"}
152 setup do: clear_config([:i_am_aware_this_may_cause_data_loss, :disable_migration_check])
154 test "raises if it detects unapplied migrations" do
155 assert_raise ApplicationRequirements.VerifyError,
156 "Unapplied Migrations detected",
158 capture_log(&ApplicationRequirements.verify!/0)
162 test "doesn't do anything if disabled" do
163 clear_config([:i_am_aware_this_may_cause_data_loss, :disable_migration_check], true)
165 assert :ok == ApplicationRequirements.verify!()