Merge branch 'stable' into mergeback/2.2.2
[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 test "check_old_mrf_config/0" do
15 clear_config([:instance, :rewrite_policy], [])
16 clear_config([:instance, :mrf_transparency], true)
17 clear_config([:instance, :mrf_transparency_exclusions], [])
18
19 assert capture_log(fn -> DeprecationWarnings.check_old_mrf_config() end) =~
20 """
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:
23
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`
27 """
28 end
29
30 test "move_namespace_and_warn/2" do
31 old_group1 = [:group, :key]
32 old_group2 = [:group, :key2]
33 old_group3 = [:group, :key3]
34
35 new_group1 = [:another_group, :key4]
36 new_group2 = [:another_group, :key5]
37 new_group3 = [:another_group, :key6]
38
39 clear_config(old_group1, 1)
40 clear_config(old_group2, 2)
41 clear_config(old_group3, 3)
42
43 clear_config(new_group1)
44 clear_config(new_group2)
45 clear_config(new_group3)
46
47 config_map = [
48 {old_group1, new_group1, "\n error :key"},
49 {old_group2, new_group2, "\n error :key2"},
50 {old_group3, new_group3, "\n error :key3"}
51 ]
52
53 assert capture_log(fn ->
54 DeprecationWarnings.move_namespace_and_warn(
55 config_map,
56 "Warning preface"
57 )
58 end) =~ "Warning preface\n error :key\n error :key2\n error :key3"
59
60 assert Config.get(new_group1) == 1
61 assert Config.get(new_group2) == 2
62 assert Config.get(new_group3) == 3
63 end
64
65 test "check_media_proxy_whitelist_config/0" do
66 clear_config([:media_proxy, :whitelist], ["https://example.com", "example2.com"])
67
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"
71 end
72
73 test "check_welcome_message_config/0" do
74 clear_config([:instance, :welcome_user_nickname], "LainChan")
75
76 assert capture_log(fn ->
77 DeprecationWarnings.check_welcome_message_config()
78 end) =~ "Your config is using the old namespace for Welcome messages configuration."
79 end
80
81 test "check_hellthread_threshold/0" do
82 clear_config([:mrf_hellthread, :threshold], 16)
83
84 assert capture_log(fn ->
85 DeprecationWarnings.check_hellthread_threshold()
86 end) =~ "You are using the old configuration mechanism for the hellthread filter."
87 end
88
89 test "check_activity_expiration_config/0" do
90 clear_config(Pleroma.ActivityExpiration, enabled: true)
91
92 assert capture_log(fn ->
93 DeprecationWarnings.check_activity_expiration_config()
94 end) =~ "Your config is using old namespace for activity expiration configuration."
95 end
96
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))
101
102 assert capture_log(fn ->
103 DeprecationWarnings.check_gun_pool_options()
104 end) =~
105 "Your config is using old setting `config :pleroma, :connections_pool, await_up_timeout`."
106 end
107
108 test "pool timeout" do
109 old_config = [
110 federation: [
111 size: 50,
112 max_waiting: 10,
113 timeout: 10_000
114 ],
115 media: [
116 size: 50,
117 max_waiting: 10,
118 timeout: 10_000
119 ],
120 upload: [
121 size: 25,
122 max_waiting: 5,
123 timeout: 15_000
124 ],
125 default: [
126 size: 10,
127 max_waiting: 2,
128 timeout: 5_000
129 ]
130 ]
131
132 clear_config(:pools, old_config)
133
134 assert capture_log(fn ->
135 DeprecationWarnings.check_gun_pool_options()
136 end) =~
137 "Your config is using old setting name `timeout` instead of `recv_timeout` in pool settings"
138 end
139 end
140 end