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
15 describe "check_repo_pool_size!/1" do
16 test "raises if the pool size is unexpected" do
17 clear_config([Pleroma.Repo, :pool_size], 11)
18 clear_config([:dangerzone, :override_repo_pool_size], false)
20 assert_raise Pleroma.ApplicationRequirements.VerifyError,
21 "Repo.pool_size different than recommended value.",
23 capture_log(&Pleroma.ApplicationRequirements.verify!/0)
27 test "doesn't raise if the pool size is unexpected but the respective flag is set" do
28 clear_config([Pleroma.Repo, :pool_size], 11)
29 clear_config([:dangerzone, :override_repo_pool_size], true)
31 assert Pleroma.ApplicationRequirements.verify!() == :ok
35 describe "check_welcome_message_config!/1" do
36 setup do: clear_config([:welcome])
37 setup do: clear_config([Pleroma.Emails.Mailer])
39 test "raises if welcome email enabled but mail disabled" do
40 Pleroma.Config.put([:welcome, :email, :enabled], true)
41 Pleroma.Config.put([Pleroma.Emails.Mailer, :enabled], false)
43 assert_raise Pleroma.ApplicationRequirements.VerifyError, "The mail disabled.", fn ->
44 capture_log(&Pleroma.ApplicationRequirements.verify!/0)
49 describe "check_confirmation_accounts!" do
51 {Pleroma.ApplicationRequirements, [:passthrough],
53 check_migrations_applied!: fn _ -> :ok end
59 setup do: clear_config([:instance, :account_activation_required])
61 test "raises if account confirmation is required but mailer isn't enable" do
62 Pleroma.Config.put([:instance, :account_activation_required], true)
63 Pleroma.Config.put([Pleroma.Emails.Mailer, :enabled], false)
65 assert_raise Pleroma.ApplicationRequirements.VerifyError,
66 "Account activation enabled, but Mailer is disabled. Cannot send confirmation emails.",
68 capture_log(&Pleroma.ApplicationRequirements.verify!/0)
72 test "doesn't do anything if account confirmation is disabled" do
73 Pleroma.Config.put([:instance, :account_activation_required], false)
74 Pleroma.Config.put([Pleroma.Emails.Mailer, :enabled], false)
75 assert Pleroma.ApplicationRequirements.verify!() == :ok
78 test "doesn't do anything if account confirmation is required and mailer is enabled" do
79 Pleroma.Config.put([:instance, :account_activation_required], true)
80 Pleroma.Config.put([Pleroma.Emails.Mailer, :enabled], true)
81 assert Pleroma.ApplicationRequirements.verify!() == :ok
85 describe "check_rum!" do
87 {Pleroma.ApplicationRequirements, [:passthrough],
88 [check_migrations_applied!: fn _ -> :ok end]}
93 setup do: clear_config([:database, :rum_enabled])
95 test "raises if rum is enabled and detects unapplied rum migrations" do
96 Config.put([:database, :rum_enabled], true)
98 with_mocks([{Repo, [:passthrough], [exists?: fn _, _ -> false end]}]) do
99 assert_raise ApplicationRequirements.VerifyError,
100 "Unapplied RUM Migrations detected",
102 capture_log(&ApplicationRequirements.verify!/0)
107 test "raises if rum is disabled and detects rum migrations" do
108 Config.put([:database, :rum_enabled], false)
110 with_mocks([{Repo, [:passthrough], [exists?: fn _, _ -> true end]}]) do
111 assert_raise ApplicationRequirements.VerifyError,
112 "RUM Migrations detected",
114 capture_log(&ApplicationRequirements.verify!/0)
119 test "doesn't do anything if rum enabled and applied migrations" do
120 Config.put([:database, :rum_enabled], true)
122 with_mocks([{Repo, [:passthrough], [exists?: fn _, _ -> true end]}]) do
123 assert ApplicationRequirements.verify!() == :ok
127 test "doesn't do anything if rum disabled" do
128 Config.put([:database, :rum_enabled], false)
130 with_mocks([{Repo, [:passthrough], [exists?: fn _, _ -> false end]}]) do
131 assert ApplicationRequirements.verify!() == :ok
136 describe "check_migrations_applied!" do
140 with_repo: fn repo, fun -> passthrough([repo, fun]) end,
141 migrations: fn Repo ->
143 {:up, 20_191_128_153_944, "fix_missing_following_count"},
144 {:up, 20_191_203_043_610, "create_report_notes"},
145 {:down, 20_191_220_174_645, "add_scopes_to_pleroma_feo_auth_records"}
153 setup do: clear_config([:i_am_aware_this_may_cause_data_loss, :disable_migration_check])
155 test "raises if it detects unapplied migrations" do
156 assert_raise ApplicationRequirements.VerifyError,
157 "Unapplied Migrations detected",
159 capture_log(&ApplicationRequirements.verify!/0)
163 test "doesn't do anything if disabled" do
164 Config.put([:i_am_aware_this_may_cause_data_loss, :disable_migration_check], true)
166 assert :ok == ApplicationRequirements.verify!()