logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

application_requirements_test.exs (5635B)


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