logo

pleroma

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

deprecation_warnings_test.exs (13599B)


  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.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. describe "filter exiftool" do
  11. test "gives warning when still used" do
  12. clear_config(
  13. [Pleroma.Upload, :filters],
  14. [Pleroma.Upload.Filter.Exiftool]
  15. )
  16. assert capture_log(fn -> DeprecationWarnings.check_exiftool_filter() end) =~
  17. """
  18. !!!DEPRECATION WARNING!!!
  19. Your config is using Exiftool as a filter instead of Exiftool.StripLocation. This should work for now, but you are advised to change to the new configuration to prevent possible issues later:
  20. ```
  21. config :pleroma, Pleroma.Upload,
  22. filters: [Pleroma.Upload.Filter.Exiftool]
  23. ```
  24. Is now
  25. ```
  26. config :pleroma, Pleroma.Upload,
  27. filters: [Pleroma.Upload.Filter.Exiftool.StripLocation]
  28. ```
  29. """
  30. end
  31. test "changes setting to exiftool strip location" do
  32. clear_config(
  33. [Pleroma.Upload, :filters],
  34. [Pleroma.Upload.Filter.Exiftool, Pleroma.Upload.Filter.Exiftool.ReadDescription]
  35. )
  36. expected_config = [
  37. Pleroma.Upload.Filter.Exiftool.StripLocation,
  38. Pleroma.Upload.Filter.Exiftool.ReadDescription
  39. ]
  40. capture_log(fn -> DeprecationWarnings.warn() end)
  41. assert Config.get([Pleroma.Upload]) |> Keyword.get(:filters, []) == expected_config
  42. end
  43. test "doesn't give a warning with correct config" do
  44. clear_config(
  45. [Pleroma.Upload, :filters],
  46. [
  47. Pleroma.Upload.Filter.Exiftool.StripLocation,
  48. Pleroma.Upload.Filter.Exiftool.ReadDescription
  49. ]
  50. )
  51. assert capture_log(fn -> DeprecationWarnings.check_exiftool_filter() end) == ""
  52. end
  53. end
  54. describe "simple policy tuples" do
  55. test "gives warning when there are still strings" do
  56. clear_config([:mrf_simple],
  57. media_removal: ["some.removal"],
  58. media_nsfw: ["some.nsfw"],
  59. federated_timeline_removal: ["some.tl.removal"],
  60. report_removal: ["some.report.removal"],
  61. reject: ["some.reject"],
  62. followers_only: ["some.followers.only"],
  63. accept: ["some.accept"],
  64. avatar_removal: ["some.avatar.removal"],
  65. banner_removal: ["some.banner.removal"],
  66. reject_deletes: ["some.reject.deletes"]
  67. )
  68. assert capture_log(fn -> DeprecationWarnings.check_simple_policy_tuples() end) =~
  69. """
  70. !!!DEPRECATION WARNING!!!
  71. Your config is using strings in the SimplePolicy configuration instead of tuples. They should work for now, but you are advised to change to the new configuration to prevent possible issues later:
  72. ```
  73. config :pleroma, :mrf_simple,
  74. media_removal: ["instance.tld"],
  75. media_nsfw: ["instance.tld"],
  76. federated_timeline_removal: ["instance.tld"],
  77. report_removal: ["instance.tld"],
  78. reject: ["instance.tld"],
  79. followers_only: ["instance.tld"],
  80. accept: ["instance.tld"],
  81. avatar_removal: ["instance.tld"],
  82. banner_removal: ["instance.tld"],
  83. reject_deletes: ["instance.tld"]
  84. ```
  85. Is now
  86. ```
  87. config :pleroma, :mrf_simple,
  88. media_removal: [{"instance.tld", "Reason for media removal"}],
  89. media_nsfw: [{"instance.tld", "Reason for media nsfw"}],
  90. federated_timeline_removal: [{"instance.tld", "Reason for federated timeline removal"}],
  91. report_removal: [{"instance.tld", "Reason for report removal"}],
  92. reject: [{"instance.tld", "Reason for reject"}],
  93. followers_only: [{"instance.tld", "Reason for followers only"}],
  94. accept: [{"instance.tld", "Reason for accept"}],
  95. avatar_removal: [{"instance.tld", "Reason for avatar removal"}],
  96. banner_removal: [{"instance.tld", "Reason for banner removal"}],
  97. reject_deletes: [{"instance.tld", "Reason for reject deletes"}]
  98. ```
  99. """
  100. end
  101. test "transforms config to tuples" do
  102. clear_config([:mrf_simple],
  103. media_removal: ["some.removal", {"some.other.instance", "Some reason"}]
  104. )
  105. expected_config =
  106. {:media_removal, [{"some.removal", ""}, {"some.other.instance", "Some reason"}]}
  107. capture_log(fn -> DeprecationWarnings.warn() end)
  108. assert expected_config in Config.get([:mrf_simple])
  109. end
  110. test "doesn't give a warning with correct config" do
  111. clear_config([:mrf_simple],
  112. media_removal: [{"some.removal", ""}, {"some.other.instance", "Some reason"}]
  113. )
  114. assert capture_log(fn -> DeprecationWarnings.check_simple_policy_tuples() end) == ""
  115. end
  116. end
  117. describe "quarantined_instances tuples" do
  118. test "gives warning when there are still strings" do
  119. clear_config([:instance, :quarantined_instances], [
  120. {"domain.com", "some reason"},
  121. "somedomain.tld"
  122. ])
  123. assert capture_log(fn -> DeprecationWarnings.check_quarantined_instances_tuples() end) =~
  124. """
  125. !!!DEPRECATION WARNING!!!
  126. Your config is using strings in the quarantined_instances configuration instead of tuples. They should work for now, but you are advised to change to the new configuration to prevent possible issues later:
  127. ```
  128. config :pleroma, :instance,
  129. quarantined_instances: ["instance.tld"]
  130. ```
  131. Is now
  132. ```
  133. config :pleroma, :instance,
  134. quarantined_instances: [{"instance.tld", "Reason for quarantine"}]
  135. ```
  136. """
  137. end
  138. test "transforms config to tuples" do
  139. clear_config([:instance, :quarantined_instances], [
  140. {"domain.com", "some reason"},
  141. "some.tld"
  142. ])
  143. expected_config = [{"domain.com", "some reason"}, {"some.tld", ""}]
  144. capture_log(fn -> DeprecationWarnings.warn() end)
  145. assert Config.get([:instance, :quarantined_instances]) == expected_config
  146. end
  147. test "doesn't give a warning with correct config" do
  148. clear_config([:instance, :quarantined_instances], [
  149. {"domain.com", "some reason"},
  150. {"some.tld", ""}
  151. ])
  152. assert capture_log(fn -> DeprecationWarnings.check_quarantined_instances_tuples() end) == ""
  153. end
  154. end
  155. describe "transparency_exclusions tuples" do
  156. test "gives warning when there are still strings" do
  157. clear_config([:mrf, :transparency_exclusions], [
  158. {"domain.com", "some reason"},
  159. "somedomain.tld"
  160. ])
  161. assert capture_log(fn -> DeprecationWarnings.check_transparency_exclusions_tuples() end) =~
  162. """
  163. !!!DEPRECATION WARNING!!!
  164. Your config is using strings in the transparency_exclusions configuration instead of tuples. They should work for now, but you are advised to change to the new configuration to prevent possible issues later:
  165. ```
  166. config :pleroma, :mrf,
  167. transparency_exclusions: ["instance.tld"]
  168. ```
  169. Is now
  170. ```
  171. config :pleroma, :mrf,
  172. transparency_exclusions: [{"instance.tld", "Reason to exclude transparency"}]
  173. ```
  174. """
  175. end
  176. test "transforms config to tuples" do
  177. clear_config([:mrf, :transparency_exclusions], [
  178. {"domain.com", "some reason"},
  179. "some.tld"
  180. ])
  181. expected_config = [{"domain.com", "some reason"}, {"some.tld", ""}]
  182. capture_log(fn -> DeprecationWarnings.warn() end)
  183. assert Config.get([:mrf, :transparency_exclusions]) == expected_config
  184. end
  185. test "doesn't give a warning with correct config" do
  186. clear_config([:mrf, :transparency_exclusions], [
  187. {"domain.com", "some reason"},
  188. {"some.tld", ""}
  189. ])
  190. assert capture_log(fn -> DeprecationWarnings.check_transparency_exclusions_tuples() end) ==
  191. ""
  192. end
  193. end
  194. test "check_old_mrf_config/0" do
  195. clear_config([:instance, :rewrite_policy], [])
  196. clear_config([:instance, :mrf_transparency], true)
  197. clear_config([:instance, :mrf_transparency_exclusions], [])
  198. assert capture_log(fn -> DeprecationWarnings.check_old_mrf_config() end) =~
  199. """
  200. !!!DEPRECATION WARNING!!!
  201. 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:
  202. * `config :pleroma, :instance, rewrite_policy` is now `config :pleroma, :mrf, policies`
  203. * `config :pleroma, :instance, mrf_transparency` is now `config :pleroma, :mrf, transparency`
  204. * `config :pleroma, :instance, mrf_transparency_exclusions` is now `config :pleroma, :mrf, transparency_exclusions`
  205. """
  206. end
  207. test "move_namespace_and_warn/2" do
  208. old_group1 = [:group, :key]
  209. old_group2 = [:group, :key2]
  210. old_group3 = [:group, :key3]
  211. new_group1 = [:another_group, :key4]
  212. new_group2 = [:another_group, :key5]
  213. new_group3 = [:another_group, :key6]
  214. clear_config(old_group1, 1)
  215. clear_config(old_group2, 2)
  216. clear_config(old_group3, 3)
  217. clear_config(new_group1)
  218. clear_config(new_group2)
  219. clear_config(new_group3)
  220. config_map = [
  221. {old_group1, new_group1, "\n error :key"},
  222. {old_group2, new_group2, "\n error :key2"},
  223. {old_group3, new_group3, "\n error :key3"}
  224. ]
  225. assert capture_log(fn ->
  226. DeprecationWarnings.move_namespace_and_warn(
  227. config_map,
  228. "Warning preface"
  229. )
  230. end) =~ "Warning preface\n error :key\n error :key2\n error :key3"
  231. assert Config.get(new_group1) == 1
  232. assert Config.get(new_group2) == 2
  233. assert Config.get(new_group3) == 3
  234. end
  235. test "check_media_proxy_whitelist_config/0" do
  236. clear_config([:media_proxy, :whitelist], ["https://example.com", "example2.com"])
  237. assert capture_log(fn ->
  238. DeprecationWarnings.check_media_proxy_whitelist_config()
  239. end) =~ "Your config is using old format (only domain) for MediaProxy whitelist option"
  240. end
  241. test "check_welcome_message_config/0" do
  242. clear_config([:instance, :welcome_user_nickname], "LainChan")
  243. assert capture_log(fn ->
  244. DeprecationWarnings.check_welcome_message_config()
  245. end) =~ "Your config is using the old namespace for Welcome messages configuration."
  246. end
  247. test "check_hellthread_threshold/0" do
  248. clear_config([:mrf_hellthread, :threshold], 16)
  249. assert capture_log(fn ->
  250. DeprecationWarnings.check_hellthread_threshold()
  251. end) =~ "You are using the old configuration mechanism for the hellthread filter."
  252. end
  253. test "check_activity_expiration_config/0" do
  254. clear_config([Pleroma.ActivityExpiration], enabled: true)
  255. assert capture_log(fn ->
  256. DeprecationWarnings.check_activity_expiration_config()
  257. end) =~ "Your config is using old namespace for activity expiration configuration."
  258. end
  259. test "check_uploaders_s3_public_endpoint/0" do
  260. clear_config([Pleroma.Uploaders.S3], public_endpoint: "https://fake.amazonaws.com/bucket/")
  261. assert capture_log(fn ->
  262. DeprecationWarnings.check_uploaders_s3_public_endpoint()
  263. end) =~
  264. "Your config is using the old setting for controlling the URL of media uploaded to your S3 bucket."
  265. end
  266. describe "check_gun_pool_options/0" do
  267. test "await_up_timeout" do
  268. config = Config.get(:connections_pool)
  269. clear_config(:connections_pool, Keyword.put(config, :await_up_timeout, 5_000))
  270. assert capture_log(fn ->
  271. DeprecationWarnings.check_gun_pool_options()
  272. end) =~
  273. "Your config is using old setting `config :pleroma, :connections_pool, await_up_timeout`."
  274. end
  275. test "pool timeout" do
  276. old_config = [
  277. federation: [
  278. size: 50,
  279. max_waiting: 10,
  280. timeout: 10_000
  281. ],
  282. media: [
  283. size: 50,
  284. max_waiting: 10,
  285. timeout: 10_000
  286. ],
  287. upload: [
  288. size: 25,
  289. max_waiting: 5,
  290. timeout: 15_000
  291. ],
  292. default: [
  293. size: 10,
  294. max_waiting: 2,
  295. timeout: 5_000
  296. ]
  297. ]
  298. clear_config(:pools, old_config)
  299. assert capture_log(fn ->
  300. DeprecationWarnings.check_gun_pool_options()
  301. end) =~
  302. "Your config is using old setting name `timeout` instead of `recv_timeout` in pool settings"
  303. end
  304. end
  305. test "check_old_chat_shoutbox/0" do
  306. clear_config([:instance, :chat_limit], 1_000)
  307. clear_config([:chat, :enabled], true)
  308. assert capture_log(fn ->
  309. DeprecationWarnings.check_old_chat_shoutbox()
  310. end) =~
  311. "Your config is using the old namespace for the Shoutbox configuration."
  312. end
  313. end