f3453ddb097ff01f881cd5d818cf69aa94f4234d
[anni] / test / pleroma / config / deprecation_warnings_test.exs
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
5 defmodule Pleroma.Config.DeprecationWarningsTest do
6   use ExUnit.Case
7   use Pleroma.Tests.Helpers
8
9   import ExUnit.CaptureLog
10
11   alias Pleroma.Config
12   alias Pleroma.Config.DeprecationWarnings
13
14   describe "filter exiftool" do
15     test "gives warning when still used" do
16       clear_config(
17         [Pleroma.Upload, :filters],
18         [Pleroma.Upload.Filter.Exiftool]
19       )
20
21       assert capture_log(fn -> DeprecationWarnings.check_exiftool_filter() end) =~
22                """
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:
25
26                ```
27                config :pleroma, Pleroma.Upload,
28                  filters: [Pleroma.Upload.Filter.Exiftool]
29                ```
30
31                Is now
32
33
34                ```
35                config :pleroma, Pleroma.Upload,
36                  filters: [Pleroma.Upload.Filter.Exiftool.StripLocation]
37                ```
38                """
39     end
40
41     test "changes setting to exiftool strip location" do
42       clear_config(
43         [Pleroma.Upload, :filters],
44         [Pleroma.Upload.Filter.Exiftool, Pleroma.Upload.Filter.Exiftool.ReadDescription]
45       )
46
47       expected_config = [
48         Pleroma.Upload.Filter.Exiftool.StripLocation,
49         Pleroma.Upload.Filter.Exiftool.ReadDescription
50       ]
51
52       capture_log(fn -> DeprecationWarnings.warn() end)
53
54       assert Config.get([Pleroma.Upload]) |> Keyword.get(:filters, []) == expected_config
55     end
56
57     test "doesn't give a warning with correct config" do
58       clear_config(
59         [Pleroma.Upload, :filters],
60         [
61           Pleroma.Upload.Filter.Exiftool.StripLocation,
62           Pleroma.Upload.Filter.Exiftool.ReadDescription
63         ]
64       )
65
66       assert capture_log(fn -> DeprecationWarnings.check_exiftool_filter() end) == ""
67     end
68   end
69
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"]
83       )
84
85       assert capture_log(fn -> DeprecationWarnings.check_simple_policy_tuples() end) =~
86                """
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:
89
90                ```
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"]
102                ```
103
104                Is now
105
106
107                ```
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"}]
119                ```
120                """
121     end
122
123     test "transforms config to tuples" do
124       clear_config([:mrf_simple],
125         media_removal: ["some.removal", {"some.other.instance", "Some reason"}]
126       )
127
128       expected_config = [
129         {:media_removal, [{"some.removal", ""}, {"some.other.instance", "Some reason"}]}
130       ]
131
132       capture_log(fn -> DeprecationWarnings.warn() end)
133
134       assert Config.get([:mrf_simple]) == expected_config
135     end
136
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"}]
140       )
141
142       assert capture_log(fn -> DeprecationWarnings.check_simple_policy_tuples() end) == ""
143     end
144   end
145
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"},
150         "somedomain.tld"
151       ])
152
153       assert capture_log(fn -> DeprecationWarnings.check_quarantined_instances_tuples() end) =~
154                """
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:
157
158                ```
159                config :pleroma, :instance,
160                  quarantined_instances: ["instance.tld"]
161                ```
162
163                Is now
164
165
166                ```
167                config :pleroma, :instance,
168                  quarantined_instances: [{"instance.tld", "Reason for quarantine"}]
169                ```
170                """
171     end
172
173     test "transforms config to tuples" do
174       clear_config([:instance, :quarantined_instances], [
175         {"domain.com", "some reason"},
176         "some.tld"
177       ])
178
179       expected_config = [{"domain.com", "some reason"}, {"some.tld", ""}]
180
181       capture_log(fn -> DeprecationWarnings.warn() end)
182
183       assert Config.get([:instance, :quarantined_instances]) == expected_config
184     end
185
186     test "doesn't give a warning with correct config" do
187       clear_config([:instance, :quarantined_instances], [
188         {"domain.com", "some reason"},
189         {"some.tld", ""}
190       ])
191
192       assert capture_log(fn -> DeprecationWarnings.check_quarantined_instances_tuples() end) == ""
193     end
194   end
195
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"},
200         "somedomain.tld"
201       ])
202
203       assert capture_log(fn -> DeprecationWarnings.check_transparency_exclusions_tuples() end) =~
204                """
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:
207
208                ```
209                config :pleroma, :mrf,
210                  transparency_exclusions: ["instance.tld"]
211                ```
212
213                Is now
214
215
216                ```
217                config :pleroma, :mrf,
218                  transparency_exclusions: [{"instance.tld", "Reason to exlude transparency"}]
219                ```
220                """
221     end
222
223     test "transforms config to tuples" do
224       clear_config([:mrf, :transparency_exclusions], [
225         {"domain.com", "some reason"},
226         "some.tld"
227       ])
228
229       expected_config = [{"domain.com", "some reason"}, {"some.tld", ""}]
230
231       capture_log(fn -> DeprecationWarnings.warn() end)
232
233       assert Config.get([:mrf, :transparency_exclusions]) == expected_config
234     end
235
236     test "doesn't give a warning with correct config" do
237       clear_config([:mrf, :transparency_exclusions], [
238         {"domain.com", "some reason"},
239         {"some.tld", ""}
240       ])
241
242       assert capture_log(fn -> DeprecationWarnings.check_transparency_exclusions_tuples() end) ==
243                ""
244     end
245   end
246
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], [])
251
252     assert capture_log(fn -> DeprecationWarnings.check_old_mrf_config() end) =~
253              """
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:
256
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`
260              """
261   end
262
263   test "move_namespace_and_warn/2" do
264     old_group1 = [:group, :key]
265     old_group2 = [:group, :key2]
266     old_group3 = [:group, :key3]
267
268     new_group1 = [:another_group, :key4]
269     new_group2 = [:another_group, :key5]
270     new_group3 = [:another_group, :key6]
271
272     clear_config(old_group1, 1)
273     clear_config(old_group2, 2)
274     clear_config(old_group3, 3)
275
276     clear_config(new_group1)
277     clear_config(new_group2)
278     clear_config(new_group3)
279
280     config_map = [
281       {old_group1, new_group1, "\n error :key"},
282       {old_group2, new_group2, "\n error :key2"},
283       {old_group3, new_group3, "\n error :key3"}
284     ]
285
286     assert capture_log(fn ->
287              DeprecationWarnings.move_namespace_and_warn(
288                config_map,
289                "Warning preface"
290              )
291            end) =~ "Warning preface\n error :key\n error :key2\n error :key3"
292
293     assert Config.get(new_group1) == 1
294     assert Config.get(new_group2) == 2
295     assert Config.get(new_group3) == 3
296   end
297
298   test "check_media_proxy_whitelist_config/0" do
299     clear_config([:media_proxy, :whitelist], ["https://example.com", "example2.com"])
300
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"
304   end
305
306   test "check_welcome_message_config/0" do
307     clear_config([:instance, :welcome_user_nickname], "LainChan")
308
309     assert capture_log(fn ->
310              DeprecationWarnings.check_welcome_message_config()
311            end) =~ "Your config is using the old namespace for Welcome messages configuration."
312   end
313
314   test "check_hellthread_threshold/0" do
315     clear_config([:mrf_hellthread, :threshold], 16)
316
317     assert capture_log(fn ->
318              DeprecationWarnings.check_hellthread_threshold()
319            end) =~ "You are using the old configuration mechanism for the hellthread filter."
320   end
321
322   test "check_activity_expiration_config/0" do
323     clear_config([Pleroma.ActivityExpiration], enabled: true)
324
325     assert capture_log(fn ->
326              DeprecationWarnings.check_activity_expiration_config()
327            end) =~ "Your config is using old namespace for activity expiration configuration."
328   end
329
330   test "check_uploders_s3_public_endpoint/0" do
331     clear_config([Pleroma.Uploaders.S3], public_endpoint: "https://fake.amazonaws.com/bucket/")
332
333     assert capture_log(fn ->
334              DeprecationWarnings.check_uploders_s3_public_endpoint()
335            end) =~
336              "Your config is using the old setting for controlling the URL of media uploaded to your S3 bucket."
337   end
338
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))
343
344       assert capture_log(fn ->
345                DeprecationWarnings.check_gun_pool_options()
346              end) =~
347                "Your config is using old setting `config :pleroma, :connections_pool, await_up_timeout`."
348     end
349
350     test "pool timeout" do
351       old_config = [
352         federation: [
353           size: 50,
354           max_waiting: 10,
355           timeout: 10_000
356         ],
357         media: [
358           size: 50,
359           max_waiting: 10,
360           timeout: 10_000
361         ],
362         upload: [
363           size: 25,
364           max_waiting: 5,
365           timeout: 15_000
366         ],
367         default: [
368           size: 10,
369           max_waiting: 2,
370           timeout: 5_000
371         ]
372       ]
373
374       clear_config(:pools, old_config)
375
376       assert capture_log(fn ->
377                DeprecationWarnings.check_gun_pool_options()
378              end) =~
379                "Your config is using old setting name `timeout` instead of `recv_timeout` in pool settings"
380     end
381   end
382
383   test "check_old_chat_shoutbox/0" do
384     clear_config([:instance, :chat_limit], 1_000)
385     clear_config([:chat, :enabled], true)
386
387     assert capture_log(fn ->
388              DeprecationWarnings.check_old_chat_shoutbox()
389            end) =~
390              "Your config is using the old namespace for the Shoutbox configuration."
391   end
392 end