ReverseProxy tesla client: remove handling of old_conn
[akkoma] / test / application_requirements_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.ApplicationRequirementsTest do
6 use Pleroma.DataCase
7 import ExUnit.CaptureLog
8 import Mock
9
10 alias Pleroma.Repo
11
12 describe "check_confirmation_accounts!" do
13 setup_with_mocks([
14 {Pleroma.ApplicationRequirements, [:passthrough],
15 [
16 check_migrations_applied!: fn _ -> :ok end
17 ]}
18 ]) do
19 :ok
20 end
21
22 setup do: clear_config([:instance, :account_activation_required])
23
24 test "raises if account confirmation is required but mailer isn't enable" do
25 Pleroma.Config.put([:instance, :account_activation_required], true)
26 Pleroma.Config.put([Pleroma.Emails.Mailer, :enabled], false)
27
28 assert_raise Pleroma.ApplicationRequirements.VerifyError,
29 "Account activation enabled, but Mailer is disabled. Cannot send confirmation emails.",
30 fn ->
31 capture_log(&Pleroma.ApplicationRequirements.verify!/0)
32 end
33 end
34
35 test "doesn't do anything if account confirmation is disabled" do
36 Pleroma.Config.put([:instance, :account_activation_required], false)
37 Pleroma.Config.put([Pleroma.Emails.Mailer, :enabled], false)
38 assert Pleroma.ApplicationRequirements.verify!() == :ok
39 end
40
41 test "doesn't do anything if account confirmation is required and mailer is enabled" do
42 Pleroma.Config.put([:instance, :account_activation_required], true)
43 Pleroma.Config.put([Pleroma.Emails.Mailer, :enabled], true)
44 assert Pleroma.ApplicationRequirements.verify!() == :ok
45 end
46 end
47
48 describe "check_rum!" do
49 setup_with_mocks([
50 {Pleroma.ApplicationRequirements, [:passthrough],
51 [check_migrations_applied!: fn _ -> :ok end]}
52 ]) do
53 :ok
54 end
55
56 setup do: clear_config([:database, :rum_enabled])
57
58 test "raises if rum is enabled and detects unapplied rum migrations" do
59 Pleroma.Config.put([:database, :rum_enabled], true)
60
61 with_mocks([{Repo, [:passthrough], [exists?: fn _, _ -> false end]}]) do
62 assert_raise Pleroma.ApplicationRequirements.VerifyError,
63 "Unapplied RUM Migrations detected",
64 fn ->
65 capture_log(&Pleroma.ApplicationRequirements.verify!/0)
66 end
67 end
68 end
69
70 test "raises if rum is disabled and detects rum migrations" do
71 Pleroma.Config.put([:database, :rum_enabled], false)
72
73 with_mocks([{Repo, [:passthrough], [exists?: fn _, _ -> true end]}]) do
74 assert_raise Pleroma.ApplicationRequirements.VerifyError,
75 "RUM Migrations detected",
76 fn ->
77 capture_log(&Pleroma.ApplicationRequirements.verify!/0)
78 end
79 end
80 end
81
82 test "doesn't do anything if rum enabled and applied migrations" do
83 Pleroma.Config.put([:database, :rum_enabled], true)
84
85 with_mocks([{Repo, [:passthrough], [exists?: fn _, _ -> true end]}]) do
86 assert Pleroma.ApplicationRequirements.verify!() == :ok
87 end
88 end
89
90 test "doesn't do anything if rum disabled" do
91 Pleroma.Config.put([:database, :rum_enabled], false)
92
93 with_mocks([{Repo, [:passthrough], [exists?: fn _, _ -> false end]}]) do
94 assert Pleroma.ApplicationRequirements.verify!() == :ok
95 end
96 end
97 end
98
99 describe "check_migrations_applied!" do
100 setup_with_mocks([
101 {Ecto.Migrator, [],
102 [
103 with_repo: fn repo, fun -> passthrough([repo, fun]) end,
104 migrations: fn Repo ->
105 [
106 {:up, 20_191_128_153_944, "fix_missing_following_count"},
107 {:up, 20_191_203_043_610, "create_report_notes"},
108 {:down, 20_191_220_174_645, "add_scopes_to_pleroma_feo_auth_records"}
109 ]
110 end
111 ]}
112 ]) do
113 :ok
114 end
115
116 setup do: clear_config([:i_am_aware_this_may_cause_data_loss, :disable_migration_check])
117
118 test "raises if it detects unapplied migrations" do
119 assert_raise Pleroma.ApplicationRequirements.VerifyError,
120 "Unapplied Migrations detected",
121 fn ->
122 capture_log(&Pleroma.ApplicationRequirements.verify!/0)
123 end
124 end
125
126 test "doesn't do anything if disabled" do
127 Pleroma.Config.put([:i_am_aware_this_may_cause_data_loss, :disable_migration_check], true)
128
129 assert :ok == Pleroma.ApplicationRequirements.verify!()
130 end
131 end
132 end