logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

application_requirements_test.exs (5111B)


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