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"}]}
131 capture_log(fn -> DeprecationWarnings.warn() end)
133 assert expected_config in Config.get([:mrf_simple])
136 test "doesn't give a warning with correct config" do
137 clear_config([:mrf_simple],
138 media_removal: [{"some.removal", ""}, {"some.other.instance", "Some reason"}]
141 assert capture_log(fn -> DeprecationWarnings.check_simple_policy_tuples() end) == ""
145 describe "quarantined_instances tuples" do
146 test "gives warning when there are still strings" do
147 clear_config([:instance, :quarantined_instances], [
148 {"domain.com", "some reason"},
152 assert capture_log(fn -> DeprecationWarnings.check_quarantined_instances_tuples() end) =~
154 !!!DEPRECATION WARNING!!!
155 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:
158 config :pleroma, :instance,
159 quarantined_instances: ["instance.tld"]
166 config :pleroma, :instance,
167 quarantined_instances: [{"instance.tld", "Reason for quarantine"}]
172 test "transforms config to tuples" do
173 clear_config([:instance, :quarantined_instances], [
174 {"domain.com", "some reason"},
178 expected_config = [{"domain.com", "some reason"}, {"some.tld", ""}]
180 capture_log(fn -> DeprecationWarnings.warn() end)
182 assert Config.get([:instance, :quarantined_instances]) == expected_config
185 test "doesn't give a warning with correct config" do
186 clear_config([:instance, :quarantined_instances], [
187 {"domain.com", "some reason"},
191 assert capture_log(fn -> DeprecationWarnings.check_quarantined_instances_tuples() end) == ""
195 describe "transparency_exclusions tuples" do
196 test "gives warning when there are still strings" do
197 clear_config([:mrf, :transparency_exclusions], [
198 {"domain.com", "some reason"},
202 assert capture_log(fn -> DeprecationWarnings.check_transparency_exclusions_tuples() end) =~
204 !!!DEPRECATION WARNING!!!
205 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:
208 config :pleroma, :mrf,
209 transparency_exclusions: ["instance.tld"]
216 config :pleroma, :mrf,
217 transparency_exclusions: [{"instance.tld", "Reason to exclude transparency"}]
222 test "transforms config to tuples" do
223 clear_config([:mrf, :transparency_exclusions], [
224 {"domain.com", "some reason"},
228 expected_config = [{"domain.com", "some reason"}, {"some.tld", ""}]
230 capture_log(fn -> DeprecationWarnings.warn() end)
232 assert Config.get([:mrf, :transparency_exclusions]) == expected_config
235 test "doesn't give a warning with correct config" do
236 clear_config([:mrf, :transparency_exclusions], [
237 {"domain.com", "some reason"},
241 assert capture_log(fn -> DeprecationWarnings.check_transparency_exclusions_tuples() end) ==
246 test "check_old_mrf_config/0" do
247 clear_config([:instance, :rewrite_policy], [])
248 clear_config([:instance, :mrf_transparency], true)
249 clear_config([:instance, :mrf_transparency_exclusions], [])
251 assert capture_log(fn -> DeprecationWarnings.check_old_mrf_config() end) =~
253 !!!DEPRECATION WARNING!!!
254 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:
256 * `config :pleroma, :instance, rewrite_policy` is now `config :pleroma, :mrf, policies`
257 * `config :pleroma, :instance, mrf_transparency` is now `config :pleroma, :mrf, transparency`
258 * `config :pleroma, :instance, mrf_transparency_exclusions` is now `config :pleroma, :mrf, transparency_exclusions`
262 test "move_namespace_and_warn/2" do
263 old_group1 = [:group, :key]
264 old_group2 = [:group, :key2]
265 old_group3 = [:group, :key3]
267 new_group1 = [:another_group, :key4]
268 new_group2 = [:another_group, :key5]
269 new_group3 = [:another_group, :key6]
271 clear_config(old_group1, 1)
272 clear_config(old_group2, 2)
273 clear_config(old_group3, 3)
275 clear_config(new_group1)
276 clear_config(new_group2)
277 clear_config(new_group3)
280 {old_group1, new_group1, "\n error :key"},
281 {old_group2, new_group2, "\n error :key2"},
282 {old_group3, new_group3, "\n error :key3"}
285 assert capture_log(fn ->
286 DeprecationWarnings.move_namespace_and_warn(
290 end) =~ "Warning preface\n error :key\n error :key2\n error :key3"
292 assert Config.get(new_group1) == 1
293 assert Config.get(new_group2) == 2
294 assert Config.get(new_group3) == 3
297 test "check_media_proxy_whitelist_config/0" do
298 clear_config([:media_proxy, :whitelist], ["https://example.com", "example2.com"])
300 assert capture_log(fn ->
301 DeprecationWarnings.check_media_proxy_whitelist_config()
302 end) =~ "Your config is using old format (only domain) for MediaProxy whitelist option"
305 test "check_welcome_message_config/0" do
306 clear_config([:instance, :welcome_user_nickname], "LainChan")
308 assert capture_log(fn ->
309 DeprecationWarnings.check_welcome_message_config()
310 end) =~ "Your config is using the old namespace for Welcome messages configuration."
313 test "check_hellthread_threshold/0" do
314 clear_config([:mrf_hellthread, :threshold], 16)
316 assert capture_log(fn ->
317 DeprecationWarnings.check_hellthread_threshold()
318 end) =~ "You are using the old configuration mechanism for the hellthread filter."
321 test "check_activity_expiration_config/0" do
322 clear_config([Pleroma.ActivityExpiration], enabled: true)
324 assert capture_log(fn ->
325 DeprecationWarnings.check_activity_expiration_config()
326 end) =~ "Your config is using old namespace for activity expiration configuration."
329 test "check_uploaders_s3_public_endpoint/0" do
330 clear_config([Pleroma.Uploaders.S3], public_endpoint: "https://fake.amazonaws.com/bucket/")
332 assert capture_log(fn ->
333 DeprecationWarnings.check_uploaders_s3_public_endpoint()
335 "Your config is using the old setting for controlling the URL of media uploaded to your S3 bucket."
338 describe "check_gun_pool_options/0" do
339 test "await_up_timeout" do
340 config = Config.get(:connections_pool)
341 clear_config(:connections_pool, Keyword.put(config, :await_up_timeout, 5_000))
343 assert capture_log(fn ->
344 DeprecationWarnings.check_gun_pool_options()
346 "Your config is using old setting `config :pleroma, :connections_pool, await_up_timeout`."
349 test "pool timeout" do
373 clear_config(:pools, old_config)
375 assert capture_log(fn ->
376 DeprecationWarnings.check_gun_pool_options()
378 "Your config is using old setting name `timeout` instead of `recv_timeout` in pool settings"
382 test "check_old_chat_shoutbox/0" do
383 clear_config([:instance, :chat_limit], 1_000)
384 clear_config([:chat, :enabled], true)
386 assert capture_log(fn ->
387 DeprecationWarnings.check_old_chat_shoutbox()
389 "Your config is using the old namespace for the Shoutbox configuration."