1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 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 test "check_old_mrf_config/0" do
15 clear_config([:instance, :rewrite_policy], Pleroma.Web.ActivityPub.MRF.NoOpPolicy)
16 clear_config([:instance, :mrf_transparency], true)
17 clear_config([:instance, :mrf_transparency_exclusions], [])
19 assert capture_log(fn -> DeprecationWarnings.check_old_mrf_config() end) =~
21 !!!DEPRECATION WARNING!!!
22 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:
24 * `config :pleroma, :instance, rewrite_policy` is now `config :pleroma, :mrf, policies`
25 * `config :pleroma, :instance, mrf_transparency` is now `config :pleroma, :mrf, transparency`
26 * `config :pleroma, :instance, mrf_transparency_exclusions` is now `config :pleroma, :mrf, transparency_exclusions`
30 test "move_namespace_and_warn/2" do
31 old_group1 = [:group, :key]
32 old_group2 = [:group, :key2]
33 old_group3 = [:group, :key3]
35 new_group1 = [:another_group, :key4]
36 new_group2 = [:another_group, :key5]
37 new_group3 = [:another_group, :key6]
39 clear_config(old_group1, 1)
40 clear_config(old_group2, 2)
41 clear_config(old_group3, 3)
43 clear_config(new_group1)
44 clear_config(new_group2)
45 clear_config(new_group3)
48 {old_group1, new_group1, "\n error :key"},
49 {old_group2, new_group2, "\n error :key2"},
50 {old_group3, new_group3, "\n error :key3"}
53 assert capture_log(fn ->
54 DeprecationWarnings.move_namespace_and_warn(
58 end) =~ "Warning preface\n error :key\n error :key2\n error :key3"
60 assert Config.get(new_group1) == 1
61 assert Config.get(new_group2) == 2
62 assert Config.get(new_group3) == 3
65 test "check_media_proxy_whitelist_config/0" do
66 clear_config([:media_proxy, :whitelist], ["https://example.com", "example2.com"])
68 assert capture_log(fn ->
69 DeprecationWarnings.check_media_proxy_whitelist_config()
70 end) =~ "Your config is using old format (only domain) for MediaProxy whitelist option"
73 test "check_welcome_message_config/0" do
74 clear_config([:instance, :welcome_user_nickname], "LainChan")
76 assert capture_log(fn ->
77 DeprecationWarnings.check_welcome_message_config()
78 end) =~ "Your config is using the old namespace for Welcome messages configuration."
81 test "check_hellthread_threshold/0" do
82 clear_config([:mrf_hellthread, :threshold], 16)
84 assert capture_log(fn ->
85 DeprecationWarnings.check_hellthread_threshold()
86 end) =~ "You are using the old configuration mechanism for the hellthread filter."
89 test "check_activity_expiration_config/0" do
90 clear_config(Pleroma.ActivityExpiration, enabled: true)
92 assert capture_log(fn ->
93 DeprecationWarnings.check_activity_expiration_config()
94 end) =~ "Your config is using old namespace for activity expiration configuration."
97 describe "check_gun_pool_options/0" do
98 test "await_up_timeout" do
99 config = Config.get(:connections_pool)
100 clear_config(:connections_pool, Keyword.put(config, :await_up_timeout, 5_000))
102 assert capture_log(fn ->
103 DeprecationWarnings.check_gun_pool_options()
105 "Your config is using old setting `config :pleroma, :connections_pool, await_up_timeout`."
108 test "pool timeout" do
132 clear_config(:pools, old_config)
134 assert capture_log(fn ->
135 DeprecationWarnings.check_gun_pool_options()
137 "Your config is using old setting name `timeout` instead of `recv_timeout` in pool settings"