Deprectate strings for SimplePolicy
[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.check_simple_policy_tuples() 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 test "check_old_mrf_config/0" do
91 clear_config([:instance, :rewrite_policy], [])
92 clear_config([:instance, :mrf_transparency], true)
93 clear_config([:instance, :mrf_transparency_exclusions], [])
94
95 assert capture_log(fn -> DeprecationWarnings.check_old_mrf_config() end) =~
96 """
97 !!!DEPRECATION WARNING!!!
98 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:
99
100 * `config :pleroma, :instance, rewrite_policy` is now `config :pleroma, :mrf, policies`
101 * `config :pleroma, :instance, mrf_transparency` is now `config :pleroma, :mrf, transparency`
102 * `config :pleroma, :instance, mrf_transparency_exclusions` is now `config :pleroma, :mrf, transparency_exclusions`
103 """
104 end
105
106 test "move_namespace_and_warn/2" do
107 old_group1 = [:group, :key]
108 old_group2 = [:group, :key2]
109 old_group3 = [:group, :key3]
110
111 new_group1 = [:another_group, :key4]
112 new_group2 = [:another_group, :key5]
113 new_group3 = [:another_group, :key6]
114
115 clear_config(old_group1, 1)
116 clear_config(old_group2, 2)
117 clear_config(old_group3, 3)
118
119 clear_config(new_group1)
120 clear_config(new_group2)
121 clear_config(new_group3)
122
123 config_map = [
124 {old_group1, new_group1, "\n error :key"},
125 {old_group2, new_group2, "\n error :key2"},
126 {old_group3, new_group3, "\n error :key3"}
127 ]
128
129 assert capture_log(fn ->
130 DeprecationWarnings.move_namespace_and_warn(
131 config_map,
132 "Warning preface"
133 )
134 end) =~ "Warning preface\n error :key\n error :key2\n error :key3"
135
136 assert Config.get(new_group1) == 1
137 assert Config.get(new_group2) == 2
138 assert Config.get(new_group3) == 3
139 end
140
141 test "check_media_proxy_whitelist_config/0" do
142 clear_config([:media_proxy, :whitelist], ["https://example.com", "example2.com"])
143
144 assert capture_log(fn ->
145 DeprecationWarnings.check_media_proxy_whitelist_config()
146 end) =~ "Your config is using old format (only domain) for MediaProxy whitelist option"
147 end
148
149 test "check_welcome_message_config/0" do
150 clear_config([:instance, :welcome_user_nickname], "LainChan")
151
152 assert capture_log(fn ->
153 DeprecationWarnings.check_welcome_message_config()
154 end) =~ "Your config is using the old namespace for Welcome messages configuration."
155 end
156
157 test "check_hellthread_threshold/0" do
158 clear_config([:mrf_hellthread, :threshold], 16)
159
160 assert capture_log(fn ->
161 DeprecationWarnings.check_hellthread_threshold()
162 end) =~ "You are using the old configuration mechanism for the hellthread filter."
163 end
164
165 test "check_activity_expiration_config/0" do
166 clear_config([Pleroma.ActivityExpiration], enabled: true)
167
168 assert capture_log(fn ->
169 DeprecationWarnings.check_activity_expiration_config()
170 end) =~ "Your config is using old namespace for activity expiration configuration."
171 end
172
173 test "check_uploders_s3_public_endpoint/0" do
174 clear_config([Pleroma.Uploaders.S3], public_endpoint: "https://fake.amazonaws.com/bucket/")
175
176 assert capture_log(fn ->
177 DeprecationWarnings.check_uploders_s3_public_endpoint()
178 end) =~
179 "Your config is using the old setting for controlling the URL of media uploaded to your S3 bucket."
180 end
181
182 describe "check_gun_pool_options/0" do
183 test "await_up_timeout" do
184 config = Config.get(:connections_pool)
185 clear_config(:connections_pool, Keyword.put(config, :await_up_timeout, 5_000))
186
187 assert capture_log(fn ->
188 DeprecationWarnings.check_gun_pool_options()
189 end) =~
190 "Your config is using old setting `config :pleroma, :connections_pool, await_up_timeout`."
191 end
192
193 test "pool timeout" do
194 old_config = [
195 federation: [
196 size: 50,
197 max_waiting: 10,
198 timeout: 10_000
199 ],
200 media: [
201 size: 50,
202 max_waiting: 10,
203 timeout: 10_000
204 ],
205 upload: [
206 size: 25,
207 max_waiting: 5,
208 timeout: 15_000
209 ],
210 default: [
211 size: 10,
212 max_waiting: 2,
213 timeout: 5_000
214 ]
215 ]
216
217 clear_config(:pools, old_config)
218
219 assert capture_log(fn ->
220 DeprecationWarnings.check_gun_pool_options()
221 end) =~
222 "Your config is using old setting name `timeout` instead of `recv_timeout` in pool settings"
223 end
224 end
225
226 test "check_old_chat_shoutbox/0" do
227 clear_config([:instance, :chat_limit], 1_000)
228 clear_config([:chat, :enabled], true)
229
230 assert capture_log(fn ->
231 DeprecationWarnings.check_old_chat_shoutbox()
232 end) =~
233 "Your config is using the old namespace for the Shoutbox configuration."
234 end
235 end