Merge pull request 'docs: fedora install errata' (#398) from acuteaura/akkoma:acuteau...
[akkoma] / test / pleroma / application_requirements_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.ApplicationRequirementsTest do
6 use Pleroma.DataCase
7
8 import ExUnit.CaptureLog
9 import Mock
10
11 alias Pleroma.ApplicationRequirements
12 alias Pleroma.Repo
13
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)
18
19 assert_raise Pleroma.ApplicationRequirements.VerifyError,
20 "Repo.pool_size different than recommended value.",
21 fn ->
22 capture_log(&Pleroma.ApplicationRequirements.verify!/0)
23 end
24 end
25
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)
29
30 assert Pleroma.ApplicationRequirements.verify!() == :ok
31 end
32 end
33
34 describe "check_welcome_message_config!/1" do
35 setup do: clear_config([:welcome])
36 setup do: clear_config([Pleroma.Emails.Mailer])
37
38 test "warns if welcome email enabled but mail disabled" do
39 clear_config([:welcome, :email, :enabled], true)
40 clear_config([Pleroma.Emails.Mailer, :enabled], false)
41
42 assert capture_log(fn ->
43 assert Pleroma.ApplicationRequirements.verify!() == :ok
44 end) =~ "Welcome emails will NOT be sent"
45 end
46 end
47
48 describe "check_confirmation_accounts!" do
49 setup_with_mocks([
50 {Pleroma.ApplicationRequirements, [:passthrough],
51 [
52 check_migrations_applied!: fn _ -> :ok end
53 ]}
54 ]) do
55 :ok
56 end
57
58 setup do: clear_config([:instance, :account_activation_required])
59
60 test "warns if account confirmation is required but mailer isn't enabled" do
61 clear_config([:instance, :account_activation_required], true)
62 clear_config([Pleroma.Emails.Mailer, :enabled], false)
63
64 assert capture_log(fn ->
65 assert Pleroma.ApplicationRequirements.verify!() == :ok
66 end) =~ "Users will NOT be able to confirm their accounts"
67 end
68
69 test "doesn't do anything if account confirmation is disabled" do
70 clear_config([:instance, :account_activation_required], false)
71 clear_config([Pleroma.Emails.Mailer, :enabled], false)
72 assert Pleroma.ApplicationRequirements.verify!() == :ok
73 end
74
75 test "doesn't do anything if account confirmation is required and mailer is enabled" do
76 clear_config([:instance, :account_activation_required], true)
77 clear_config([Pleroma.Emails.Mailer, :enabled], true)
78 assert Pleroma.ApplicationRequirements.verify!() == :ok
79 end
80 end
81
82 describe "check_rum!" do
83 setup_with_mocks([
84 {Pleroma.ApplicationRequirements, [:passthrough],
85 [check_migrations_applied!: fn _ -> :ok end]}
86 ]) do
87 :ok
88 end
89
90 setup do: clear_config([:database, :rum_enabled])
91
92 test "raises if rum is enabled and detects unapplied rum migrations" do
93 clear_config([:database, :rum_enabled], true)
94
95 with_mocks([{Repo, [:passthrough], [exists?: fn _, _ -> false end]}]) do
96 assert_raise ApplicationRequirements.VerifyError,
97 "Unapplied RUM Migrations detected",
98 fn ->
99 capture_log(&ApplicationRequirements.verify!/0)
100 end
101 end
102 end
103
104 test "raises if rum is disabled and detects rum migrations" do
105 clear_config([:database, :rum_enabled], false)
106
107 with_mocks([{Repo, [:passthrough], [exists?: fn _, _ -> true end]}]) do
108 assert_raise ApplicationRequirements.VerifyError,
109 "RUM Migrations detected",
110 fn ->
111 capture_log(&ApplicationRequirements.verify!/0)
112 end
113 end
114 end
115
116 test "doesn't do anything if rum enabled and applied migrations" do
117 clear_config([:database, :rum_enabled], true)
118
119 with_mocks([{Repo, [:passthrough], [exists?: fn _, _ -> true end]}]) do
120 assert ApplicationRequirements.verify!() == :ok
121 end
122 end
123
124 test "doesn't do anything if rum disabled" do
125 clear_config([:database, :rum_enabled], false)
126
127 with_mocks([{Repo, [:passthrough], [exists?: fn _, _ -> false end]}]) do
128 assert ApplicationRequirements.verify!() == :ok
129 end
130 end
131 end
132
133 describe "check_migrations_applied!" do
134 setup_with_mocks([
135 {Ecto.Migrator, [],
136 [
137 with_repo: fn repo, fun -> passthrough([repo, fun]) end,
138 migrations: fn Repo ->
139 [
140 {:up, 20_191_128_153_944, "fix_missing_following_count"},
141 {:up, 20_191_203_043_610, "create_report_notes"},
142 {:down, 20_191_220_174_645, "add_scopes_to_pleroma_feo_auth_records"}
143 ]
144 end
145 ]}
146 ]) do
147 :ok
148 end
149
150 setup do: clear_config([:i_am_aware_this_may_cause_data_loss, :disable_migration_check])
151
152 test "raises if it detects unapplied migrations" do
153 assert_raise ApplicationRequirements.VerifyError,
154 "Unapplied Migrations detected",
155 fn ->
156 capture_log(&ApplicationRequirements.verify!/0)
157 end
158 end
159
160 test "doesn't do anything if disabled" do
161 clear_config([:i_am_aware_this_may_cause_data_loss, :disable_migration_check], true)
162
163 assert :ok == ApplicationRequirements.verify!()
164 end
165 end
166 end