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