1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 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 "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"]
29 assert capture_log(fn -> DeprecationWarnings.check_simple_policy_tuples() end) =~
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:
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"]
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"}]
67 test "transforms config to tuples" do
68 clear_config([:mrf_simple],
69 media_removal: ["some.removal", {"some.other.instance", "Some reason"}]
73 {:media_removal, [{"some.removal", ""}, {"some.other.instance", "Some reason"}]}
76 capture_log(fn -> DeprecationWarnings.warn() end)
78 assert Config.get([:mrf_simple]) == expected_config
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"}]
86 assert capture_log(fn -> DeprecationWarnings.check_simple_policy_tuples() end) == ""
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"},
97 assert capture_log(fn -> DeprecationWarnings.check_quarantined_instances_tuples() end) =~
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:
103 config :pleroma, :instance,
104 quarantined_instances: ["instance.tld"]
111 config :pleroma, :instance,
112 quarantined_instances: [{"instance.tld", "Reason for quarantine"}]
117 test "transforms config to tuples" do
118 clear_config([:instance, :quarantined_instances], [
119 {"domain.com", "some reason"},
123 expected_config = [{"domain.com", "some reason"}, {"some.tld", ""}]
125 capture_log(fn -> DeprecationWarnings.warn() end)
127 assert Config.get([:instance, :quarantined_instances]) == expected_config
130 test "doesn't give a warning with correct config" do
131 clear_config([:instance, :quarantined_instances], [
132 {"domain.com", "some reason"},
136 assert capture_log(fn -> DeprecationWarnings.check_quarantined_instances_tuples() end) == ""
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"},
147 assert capture_log(fn -> DeprecationWarnings.check_transparency_exclusions_tuples() end) =~
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:
153 config :pleroma, :mrf,
154 transparency_exclusions: ["instance.tld"]
161 config :pleroma, :mrf,
162 transparency_exclusions: [{"instance.tld", "Reason to exlude transparency"}]
167 test "transforms config to tuples" do
168 clear_config([:mrf, :transparency_exclusions], [
169 {"domain.com", "some reason"},
173 expected_config = [{"domain.com", "some reason"}, {"some.tld", ""}]
175 capture_log(fn -> DeprecationWarnings.warn() end)
177 assert Config.get([:mrf, :transparency_exclusions]) == expected_config
180 test "doesn't give a warning with correct config" do
181 clear_config([:mrf, :transparency_exclusions], [
182 {"domain.com", "some reason"},
186 assert capture_log(fn -> DeprecationWarnings.check_transparency_exclusions_tuples() end) ==
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], [])
196 assert capture_log(fn -> DeprecationWarnings.check_old_mrf_config() end) =~
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:
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`
207 test "move_namespace_and_warn/2" do
208 old_group1 = [:group, :key]
209 old_group2 = [:group, :key2]
210 old_group3 = [:group, :key3]
212 new_group1 = [:another_group, :key4]
213 new_group2 = [:another_group, :key5]
214 new_group3 = [:another_group, :key6]
216 clear_config(old_group1, 1)
217 clear_config(old_group2, 2)
218 clear_config(old_group3, 3)
220 clear_config(new_group1)
221 clear_config(new_group2)
222 clear_config(new_group3)
225 {old_group1, new_group1, "\n error :key"},
226 {old_group2, new_group2, "\n error :key2"},
227 {old_group3, new_group3, "\n error :key3"}
230 assert capture_log(fn ->
231 DeprecationWarnings.move_namespace_and_warn(
235 end) =~ "Warning preface\n error :key\n error :key2\n error :key3"
237 assert Config.get(new_group1) == 1
238 assert Config.get(new_group2) == 2
239 assert Config.get(new_group3) == 3
242 test "check_media_proxy_whitelist_config/0" do
243 clear_config([:media_proxy, :whitelist], ["https://example.com", "example2.com"])
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"
250 test "check_welcome_message_config/0" do
251 clear_config([:instance, :welcome_user_nickname], "LainChan")
253 assert capture_log(fn ->
254 DeprecationWarnings.check_welcome_message_config()
255 end) =~ "Your config is using the old namespace for Welcome messages configuration."
258 test "check_hellthread_threshold/0" do
259 clear_config([:mrf_hellthread, :threshold], 16)
261 assert capture_log(fn ->
262 DeprecationWarnings.check_hellthread_threshold()
263 end) =~ "You are using the old configuration mechanism for the hellthread filter."
266 test "check_activity_expiration_config/0" do
267 clear_config([Pleroma.ActivityExpiration], enabled: true)
269 assert capture_log(fn ->
270 DeprecationWarnings.check_activity_expiration_config()
271 end) =~ "Your config is using old namespace for activity expiration configuration."
274 test "check_uploders_s3_public_endpoint/0" do
275 clear_config([Pleroma.Uploaders.S3], public_endpoint: "https://fake.amazonaws.com/bucket/")
277 assert capture_log(fn ->
278 DeprecationWarnings.check_uploders_s3_public_endpoint()
280 "Your config is using the old setting for controlling the URL of media uploaded to your S3 bucket."