Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

160 lines
5.2KB

  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. defmodule Pleroma.Config.DeprecationWarningsTest do
  5. use ExUnit.Case
  6. use Pleroma.Tests.Helpers
  7. import ExUnit.CaptureLog
  8. alias Pleroma.Config
  9. alias Pleroma.Config.DeprecationWarnings
  10. test "check_old_mrf_config/0" do
  11. clear_config([:instance, :rewrite_policy], [])
  12. clear_config([:instance, :mrf_transparency], true)
  13. clear_config([:instance, :mrf_transparency_exclusions], [])
  14. assert capture_log(fn -> DeprecationWarnings.check_old_mrf_config() end) =~
  15. """
  16. !!!DEPRECATION WARNING!!!
  17. Your config is using old namespaces for MRF configuration. They should work for now, but you are advised to change to new namespaces to prevent possible issues later:
  18. * `config :pleroma, :instance, rewrite_policy` is now `config :pleroma, :mrf, policies`
  19. * `config :pleroma, :instance, mrf_transparency` is now `config :pleroma, :mrf, transparency`
  20. * `config :pleroma, :instance, mrf_transparency_exclusions` is now `config :pleroma, :mrf, transparency_exclusions`
  21. """
  22. end
  23. test "move_namespace_and_warn/2" do
  24. old_group1 = [:group, :key]
  25. old_group2 = [:group, :key2]
  26. old_group3 = [:group, :key3]
  27. new_group1 = [:another_group, :key4]
  28. new_group2 = [:another_group, :key5]
  29. new_group3 = [:another_group, :key6]
  30. clear_config(old_group1, 1)
  31. clear_config(old_group2, 2)
  32. clear_config(old_group3, 3)
  33. clear_config(new_group1)
  34. clear_config(new_group2)
  35. clear_config(new_group3)
  36. config_map = [
  37. {old_group1, new_group1, "\n error :key"},
  38. {old_group2, new_group2, "\n error :key2"},
  39. {old_group3, new_group3, "\n error :key3"}
  40. ]
  41. assert capture_log(fn ->
  42. DeprecationWarnings.move_namespace_and_warn(
  43. config_map,
  44. "Warning preface"
  45. )
  46. end) =~ "Warning preface\n error :key\n error :key2\n error :key3"
  47. assert Config.get(new_group1) == 1
  48. assert Config.get(new_group2) == 2
  49. assert Config.get(new_group3) == 3
  50. end
  51. test "check_media_proxy_whitelist_config/0" do
  52. clear_config([:media_proxy, :whitelist], ["https://example.com", "example2.com"])
  53. assert capture_log(fn ->
  54. DeprecationWarnings.check_media_proxy_whitelist_config()
  55. end) =~ "Your config is using old format (only domain) for MediaProxy whitelist option"
  56. end
  57. test "check_welcome_message_config/0" do
  58. clear_config([:instance, :welcome_user_nickname], "LainChan")
  59. assert capture_log(fn ->
  60. DeprecationWarnings.check_welcome_message_config()
  61. end) =~ "Your config is using the old namespace for Welcome messages configuration."
  62. end
  63. test "check_hellthread_threshold/0" do
  64. clear_config([:mrf_hellthread, :threshold], 16)
  65. assert capture_log(fn ->
  66. DeprecationWarnings.check_hellthread_threshold()
  67. end) =~ "You are using the old configuration mechanism for the hellthread filter."
  68. end
  69. test "check_activity_expiration_config/0" do
  70. clear_config([Pleroma.ActivityExpiration], enabled: true)
  71. assert capture_log(fn ->
  72. DeprecationWarnings.check_activity_expiration_config()
  73. end) =~ "Your config is using old namespace for activity expiration configuration."
  74. end
  75. test "check_uploders_s3_public_endpoint/0" do
  76. clear_config([Pleroma.Uploaders.S3], public_endpoint: "https://fake.amazonaws.com/bucket/")
  77. assert capture_log(fn ->
  78. DeprecationWarnings.check_uploders_s3_public_endpoint()
  79. end) =~
  80. "Your config is using the old setting for controlling the URL of media uploaded to your S3 bucket."
  81. end
  82. describe "check_gun_pool_options/0" do
  83. test "await_up_timeout" do
  84. config = Config.get(:connections_pool)
  85. clear_config(:connections_pool, Keyword.put(config, :await_up_timeout, 5_000))
  86. assert capture_log(fn ->
  87. DeprecationWarnings.check_gun_pool_options()
  88. end) =~
  89. "Your config is using old setting `config :pleroma, :connections_pool, await_up_timeout`."
  90. end
  91. test "pool timeout" do
  92. old_config = [
  93. federation: [
  94. size: 50,
  95. max_waiting: 10,
  96. timeout: 10_000
  97. ],
  98. media: [
  99. size: 50,
  100. max_waiting: 10,
  101. timeout: 10_000
  102. ],
  103. upload: [
  104. size: 25,
  105. max_waiting: 5,
  106. timeout: 15_000
  107. ],
  108. default: [
  109. size: 10,
  110. max_waiting: 2,
  111. timeout: 5_000
  112. ]
  113. ]
  114. clear_config(:pools, old_config)
  115. assert capture_log(fn ->
  116. DeprecationWarnings.check_gun_pool_options()
  117. end) =~
  118. "Your config is using old setting name `timeout` instead of `recv_timeout` in pool settings"
  119. end
  120. end
  121. test "check_old_chat_shoutbox/0" do
  122. clear_config([:instance, :chat_limit], 1_000)
  123. clear_config([:chat, :enabled], true)
  124. assert capture_log(fn ->
  125. DeprecationWarnings.check_old_chat_shoutbox()
  126. end) =~
  127. "Your config is using the old namespace for the Shoutbox configuration."
  128. end
  129. end