Merge branch 'develop' into feature/1893-remote-emoji-packs-pagination
[akkoma] / test / config / deprecation_warnings_test.exs
1 defmodule Pleroma.Config.DeprecationWarningsTest do
2 use ExUnit.Case
3 use Pleroma.Tests.Helpers
4
5 import ExUnit.CaptureLog
6
7 alias Pleroma.Config
8 alias Pleroma.Config.DeprecationWarnings
9
10 test "check_old_mrf_config/0" do
11 clear_config([:instance, :rewrite_policy], Pleroma.Web.ActivityPub.MRF.NoOpPolicy)
12 clear_config([:instance, :mrf_transparency], true)
13 clear_config([:instance, :mrf_transparency_exclusions], [])
14
15 assert capture_log(fn -> DeprecationWarnings.check_old_mrf_config() end) =~
16 """
17 !!!DEPRECATION WARNING!!!
18 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:
19
20 * `config :pleroma, :instance, rewrite_policy` is now `config :pleroma, :mrf, policies`
21 * `config :pleroma, :instance, mrf_transparency` is now `config :pleroma, :mrf, transparency`
22 * `config :pleroma, :instance, mrf_transparency_exclusions` is now `config :pleroma, :mrf, transparency_exclusions`
23 """
24 end
25
26 test "move_namespace_and_warn/2" do
27 old_group1 = [:group, :key]
28 old_group2 = [:group, :key2]
29 old_group3 = [:group, :key3]
30
31 new_group1 = [:another_group, :key4]
32 new_group2 = [:another_group, :key5]
33 new_group3 = [:another_group, :key6]
34
35 clear_config(old_group1, 1)
36 clear_config(old_group2, 2)
37 clear_config(old_group3, 3)
38
39 clear_config(new_group1)
40 clear_config(new_group2)
41 clear_config(new_group3)
42
43 config_map = [
44 {old_group1, new_group1, "\n error :key"},
45 {old_group2, new_group2, "\n error :key2"},
46 {old_group3, new_group3, "\n error :key3"}
47 ]
48
49 assert capture_log(fn ->
50 DeprecationWarnings.move_namespace_and_warn(
51 config_map,
52 "Warning preface"
53 )
54 end) =~ "Warning preface\n error :key\n error :key2\n error :key3"
55
56 assert Config.get(new_group1) == 1
57 assert Config.get(new_group2) == 2
58 assert Config.get(new_group3) == 3
59 end
60
61 test "check_media_proxy_whitelist_config/0" do
62 clear_config([:media_proxy, :whitelist], ["https://example.com", "example2.com"])
63
64 assert capture_log(fn ->
65 DeprecationWarnings.check_media_proxy_whitelist_config()
66 end) =~ "Your config is using old format (only domain) for MediaProxy whitelist option"
67 end
68
69 test "check_welcome_message_config/0" do
70 clear_config([:instance, :welcome_user_nickname], "LainChan")
71
72 assert capture_log(fn ->
73 DeprecationWarnings.check_welcome_message_config()
74 end) =~ "Your config is using the old namespace for Welcome messages configuration."
75 end
76
77 test "check_hellthread_threshold/0" do
78 clear_config([:mrf_hellthread, :threshold], 16)
79
80 assert capture_log(fn ->
81 DeprecationWarnings.check_hellthread_threshold()
82 end) =~ "You are using the old configuration mechanism for the hellthread filter."
83 end
84
85 test "check_activity_expiration_config/0" do
86 clear_config([Pleroma.ActivityExpiration, :enabled], true)
87
88 assert capture_log(fn ->
89 DeprecationWarnings.check_activity_expiration_config()
90 end) =~ "Your config is using old namespace for activity expiration configuration."
91 end
92
93 describe "check_gun_pool_options/0" do
94 test "await_up_timeout" do
95 config = Config.get(:connections_pool)
96 clear_config(:connections_pool, Keyword.put(config, :await_up_timeout, 5_000))
97
98 assert capture_log(fn ->
99 DeprecationWarnings.check_gun_pool_options()
100 end) =~
101 "Your config is using old setting `config :pleroma, :connections_pool, await_up_timeout`."
102 end
103
104 test "pool timeout" do
105 old_config = [
106 federation: [
107 size: 50,
108 max_waiting: 10,
109 timeout: 10_000
110 ],
111 media: [
112 size: 50,
113 max_waiting: 10,
114 timeout: 10_000
115 ],
116 upload: [
117 size: 25,
118 max_waiting: 5,
119 timeout: 15_000
120 ],
121 default: [
122 size: 10,
123 max_waiting: 2,
124 timeout: 5_000
125 ]
126 ]
127
128 clear_config(:pools, old_config)
129
130 assert capture_log(fn ->
131 DeprecationWarnings.check_gun_pool_options()
132 end) =~
133 "Your config is using old setting name `timeout` instead of `recv_timeout` in pool settings"
134 end
135 end
136 end