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.check_simple_policy_tuples() 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 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], [])
95 assert capture_log(fn -> DeprecationWarnings.check_old_mrf_config() end) =~
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:
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`
106 test "move_namespace_and_warn/2" do
107 old_group1 = [:group, :key]
108 old_group2 = [:group, :key2]
109 old_group3 = [:group, :key3]
111 new_group1 = [:another_group, :key4]
112 new_group2 = [:another_group, :key5]
113 new_group3 = [:another_group, :key6]
115 clear_config(old_group1, 1)
116 clear_config(old_group2, 2)
117 clear_config(old_group3, 3)
119 clear_config(new_group1)
120 clear_config(new_group2)
121 clear_config(new_group3)
124 {old_group1, new_group1, "\n error :key"},
125 {old_group2, new_group2, "\n error :key2"},
126 {old_group3, new_group3, "\n error :key3"}
129 assert capture_log(fn ->
130 DeprecationWarnings.move_namespace_and_warn(
134 end) =~ "Warning preface\n error :key\n error :key2\n error :key3"
136 assert Config.get(new_group1) == 1
137 assert Config.get(new_group2) == 2
138 assert Config.get(new_group3) == 3
141 test "check_media_proxy_whitelist_config/0" do
142 clear_config([:media_proxy, :whitelist], ["https://example.com", "example2.com"])
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"
149 test "check_welcome_message_config/0" do
150 clear_config([:instance, :welcome_user_nickname], "LainChan")
152 assert capture_log(fn ->
153 DeprecationWarnings.check_welcome_message_config()
154 end) =~ "Your config is using the old namespace for Welcome messages configuration."
157 test "check_hellthread_threshold/0" do
158 clear_config([:mrf_hellthread, :threshold], 16)
160 assert capture_log(fn ->
161 DeprecationWarnings.check_hellthread_threshold()
162 end) =~ "You are using the old configuration mechanism for the hellthread filter."
165 test "check_activity_expiration_config/0" do
166 clear_config([Pleroma.ActivityExpiration], enabled: true)
168 assert capture_log(fn ->
169 DeprecationWarnings.check_activity_expiration_config()
170 end) =~ "Your config is using old namespace for activity expiration configuration."
173 test "check_uploders_s3_public_endpoint/0" do
174 clear_config([Pleroma.Uploaders.S3], public_endpoint: "https://fake.amazonaws.com/bucket/")
176 assert capture_log(fn ->
177 DeprecationWarnings.check_uploders_s3_public_endpoint()
179 "Your config is using the old setting for controlling the URL of media uploaded to your S3 bucket."
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))
187 assert capture_log(fn ->
188 DeprecationWarnings.check_gun_pool_options()
190 "Your config is using old setting `config :pleroma, :connections_pool, await_up_timeout`."
193 test "pool timeout" do
217 clear_config(:pools, old_config)
219 assert capture_log(fn ->
220 DeprecationWarnings.check_gun_pool_options()
222 "Your config is using old setting name `timeout` instead of `recv_timeout` in pool settings"
226 test "check_old_chat_shoutbox/0" do
227 clear_config([:instance, :chat_limit], 1_000)
228 clear_config([:chat, :enabled], true)
230 assert capture_log(fn ->
231 DeprecationWarnings.check_old_chat_shoutbox()
233 "Your config is using the old namespace for the Shoutbox configuration."