1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Config.DeprecationWarningsTest do
7 use Pleroma.Tests.Helpers
9 import ExUnit.CaptureLog
12 alias Pleroma.Config.DeprecationWarnings
14 describe "filter exiftool" do
15 test "gives warning when still used" do
17 [Pleroma.Upload, :filters],
18 [Pleroma.Upload.Filter.Exiftool]
21 assert capture_log(fn -> DeprecationWarnings.check_exiftool_filter() end) =~
23 !!!DEPRECATION WARNING!!!
24 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:
27 config :pleroma, Pleroma.Upload,
28 filters: [Pleroma.Upload.Filter.Exiftool]
35 config :pleroma, Pleroma.Upload,
36 filters: [Pleroma.Upload.Filter.Exiftool.StripLocation]
41 test "changes setting to exiftool strip location" do
43 [Pleroma.Upload, :filters],
44 [Pleroma.Upload.Filter.Exiftool, Pleroma.Upload.Filter.Exiftool.ReadDescription]
48 Pleroma.Upload.Filter.Exiftool.StripLocation,
49 Pleroma.Upload.Filter.Exiftool.ReadDescription
52 capture_log(fn -> DeprecationWarnings.warn() end)
54 assert Config.get([Pleroma.Upload]) |> Keyword.get(:filters, []) == expected_config
57 test "doesn't give a warning with correct config" do
59 [Pleroma.Upload, :filters],
61 Pleroma.Upload.Filter.Exiftool.StripLocation,
62 Pleroma.Upload.Filter.Exiftool.ReadDescription
66 assert capture_log(fn -> DeprecationWarnings.check_exiftool_filter() end) == ""
70 describe "simple policy tuples" do
71 test "gives warning when there are still strings" do
72 clear_config([:mrf_simple],
73 media_removal: ["some.removal"],
74 media_nsfw: ["some.nsfw"],
75 federated_timeline_removal: ["some.tl.removal"],
76 report_removal: ["some.report.removal"],
77 reject: ["some.reject"],
78 followers_only: ["some.followers.only"],
79 accept: ["some.accept"],
80 avatar_removal: ["some.avatar.removal"],
81 banner_removal: ["some.banner.removal"],
82 reject_deletes: ["some.reject.deletes"]
85 assert capture_log(fn -> DeprecationWarnings.check_simple_policy_tuples() end) =~
87 !!!DEPRECATION WARNING!!!
88 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:
91 config :pleroma, :mrf_simple,
92 media_removal: ["instance.tld"],
93 media_nsfw: ["instance.tld"],
94 federated_timeline_removal: ["instance.tld"],
95 report_removal: ["instance.tld"],
96 reject: ["instance.tld"],
97 followers_only: ["instance.tld"],
98 accept: ["instance.tld"],
99 avatar_removal: ["instance.tld"],
100 banner_removal: ["instance.tld"],
101 reject_deletes: ["instance.tld"]
108 config :pleroma, :mrf_simple,
109 media_removal: [{"instance.tld", "Reason for media removal"}],
110 media_nsfw: [{"instance.tld", "Reason for media nsfw"}],
111 federated_timeline_removal: [{"instance.tld", "Reason for federated timeline removal"}],
112 report_removal: [{"instance.tld", "Reason for report removal"}],
113 reject: [{"instance.tld", "Reason for reject"}],
114 followers_only: [{"instance.tld", "Reason for followers only"}],
115 accept: [{"instance.tld", "Reason for accept"}],
116 avatar_removal: [{"instance.tld", "Reason for avatar removal"}],
117 banner_removal: [{"instance.tld", "Reason for banner removal"}],
118 reject_deletes: [{"instance.tld", "Reason for reject deletes"}]
123 test "transforms config to tuples" do
124 clear_config([:mrf_simple],
125 media_removal: ["some.removal", {"some.other.instance", "Some reason"}]
129 {:media_removal, [{"some.removal", ""}, {"some.other.instance", "Some reason"}]}
132 capture_log(fn -> DeprecationWarnings.warn() end)
134 assert Config.get([:mrf_simple]) == expected_config
137 test "doesn't give a warning with correct config" do
138 clear_config([:mrf_simple],
139 media_removal: [{"some.removal", ""}, {"some.other.instance", "Some reason"}]
142 assert capture_log(fn -> DeprecationWarnings.check_simple_policy_tuples() end) == ""
146 describe "quarantined_instances tuples" do
147 test "gives warning when there are still strings" do
148 clear_config([:instance, :quarantined_instances], [
149 {"domain.com", "some reason"},
153 assert capture_log(fn -> DeprecationWarnings.check_quarantined_instances_tuples() end) =~
155 !!!DEPRECATION WARNING!!!
156 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:
159 config :pleroma, :instance,
160 quarantined_instances: ["instance.tld"]
167 config :pleroma, :instance,
168 quarantined_instances: [{"instance.tld", "Reason for quarantine"}]
173 test "transforms config to tuples" do
174 clear_config([:instance, :quarantined_instances], [
175 {"domain.com", "some reason"},
179 expected_config = [{"domain.com", "some reason"}, {"some.tld", ""}]
181 capture_log(fn -> DeprecationWarnings.warn() end)
183 assert Config.get([:instance, :quarantined_instances]) == expected_config
186 test "doesn't give a warning with correct config" do
187 clear_config([:instance, :quarantined_instances], [
188 {"domain.com", "some reason"},
192 assert capture_log(fn -> DeprecationWarnings.check_quarantined_instances_tuples() end) == ""
196 describe "transparency_exclusions tuples" do
197 test "gives warning when there are still strings" do
198 clear_config([:mrf, :transparency_exclusions], [
199 {"domain.com", "some reason"},
203 assert capture_log(fn -> DeprecationWarnings.check_transparency_exclusions_tuples() end) =~
205 !!!DEPRECATION WARNING!!!
206 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:
209 config :pleroma, :mrf,
210 transparency_exclusions: ["instance.tld"]
217 config :pleroma, :mrf,
218 transparency_exclusions: [{"instance.tld", "Reason to exlude transparency"}]
223 test "transforms config to tuples" do
224 clear_config([:mrf, :transparency_exclusions], [
225 {"domain.com", "some reason"},
229 expected_config = [{"domain.com", "some reason"}, {"some.tld", ""}]
231 capture_log(fn -> DeprecationWarnings.warn() end)
233 assert Config.get([:mrf, :transparency_exclusions]) == expected_config
236 test "doesn't give a warning with correct config" do
237 clear_config([:mrf, :transparency_exclusions], [
238 {"domain.com", "some reason"},
242 assert capture_log(fn -> DeprecationWarnings.check_transparency_exclusions_tuples() end) ==
247 test "check_old_mrf_config/0" do
248 clear_config([:instance, :rewrite_policy], [])
249 clear_config([:instance, :mrf_transparency], true)
250 clear_config([:instance, :mrf_transparency_exclusions], [])
252 assert capture_log(fn -> DeprecationWarnings.check_old_mrf_config() end) =~
254 !!!DEPRECATION WARNING!!!
255 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:
257 * `config :pleroma, :instance, rewrite_policy` is now `config :pleroma, :mrf, policies`
258 * `config :pleroma, :instance, mrf_transparency` is now `config :pleroma, :mrf, transparency`
259 * `config :pleroma, :instance, mrf_transparency_exclusions` is now `config :pleroma, :mrf, transparency_exclusions`
263 test "move_namespace_and_warn/2" do
264 old_group1 = [:group, :key]
265 old_group2 = [:group, :key2]
266 old_group3 = [:group, :key3]
268 new_group1 = [:another_group, :key4]
269 new_group2 = [:another_group, :key5]
270 new_group3 = [:another_group, :key6]
272 clear_config(old_group1, 1)
273 clear_config(old_group2, 2)
274 clear_config(old_group3, 3)
276 clear_config(new_group1)
277 clear_config(new_group2)
278 clear_config(new_group3)
281 {old_group1, new_group1, "\n error :key"},
282 {old_group2, new_group2, "\n error :key2"},
283 {old_group3, new_group3, "\n error :key3"}
286 assert capture_log(fn ->
287 DeprecationWarnings.move_namespace_and_warn(
291 end) =~ "Warning preface\n error :key\n error :key2\n error :key3"
293 assert Config.get(new_group1) == 1
294 assert Config.get(new_group2) == 2
295 assert Config.get(new_group3) == 3
298 test "check_media_proxy_whitelist_config/0" do
299 clear_config([:media_proxy, :whitelist], ["https://example.com", "example2.com"])
301 assert capture_log(fn ->
302 DeprecationWarnings.check_media_proxy_whitelist_config()
303 end) =~ "Your config is using old format (only domain) for MediaProxy whitelist option"
306 test "check_welcome_message_config/0" do
307 clear_config([:instance, :welcome_user_nickname], "LainChan")
309 assert capture_log(fn ->
310 DeprecationWarnings.check_welcome_message_config()
311 end) =~ "Your config is using the old namespace for Welcome messages configuration."
314 test "check_hellthread_threshold/0" do
315 clear_config([:mrf_hellthread, :threshold], 16)
317 assert capture_log(fn ->
318 DeprecationWarnings.check_hellthread_threshold()
319 end) =~ "You are using the old configuration mechanism for the hellthread filter."
322 test "check_activity_expiration_config/0" do
323 clear_config([Pleroma.ActivityExpiration], enabled: true)
325 assert capture_log(fn ->
326 DeprecationWarnings.check_activity_expiration_config()
327 end) =~ "Your config is using old namespace for activity expiration configuration."
330 test "check_uploders_s3_public_endpoint/0" do
331 clear_config([Pleroma.Uploaders.S3], public_endpoint: "https://fake.amazonaws.com/bucket/")
333 assert capture_log(fn ->
334 DeprecationWarnings.check_uploders_s3_public_endpoint()
336 "Your config is using the old setting for controlling the URL of media uploaded to your S3 bucket."
339 describe "check_gun_pool_options/0" do
340 test "await_up_timeout" do
341 config = Config.get(:connections_pool)
342 clear_config(:connections_pool, Keyword.put(config, :await_up_timeout, 5_000))
344 assert capture_log(fn ->
345 DeprecationWarnings.check_gun_pool_options()
347 "Your config is using old setting `config :pleroma, :connections_pool, await_up_timeout`."
350 test "pool timeout" do
374 clear_config(:pools, old_config)
376 assert capture_log(fn ->
377 DeprecationWarnings.check_gun_pool_options()
379 "Your config is using old setting name `timeout` instead of `recv_timeout` in pool settings"
383 test "check_old_chat_shoutbox/0" do
384 clear_config([:instance, :chat_limit], 1_000)
385 clear_config([:chat, :enabled], true)
387 assert capture_log(fn ->
388 DeprecationWarnings.check_old_chat_shoutbox()
390 "Your config is using the old namespace for the Shoutbox configuration."