Merge remote-tracking branch 'upstream/develop' into block-behavior
[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 test "check_uploders_s3_public_endpoint/0" do
98 clear_config([Pleroma.Uploaders.S3], public_endpoint: "https://fake.amazonaws.com/bucket/")
99
100 assert capture_log(fn ->
101 DeprecationWarnings.check_uploders_s3_public_endpoint()
102 end) =~
103 "Your config is using the old setting for controlling the URL of media uploaded to your S3 bucket."
104 end
105
106 describe "check_gun_pool_options/0" do
107 test "await_up_timeout" do
108 config = Config.get(:connections_pool)
109 clear_config(:connections_pool, Keyword.put(config, :await_up_timeout, 5_000))
110
111 assert capture_log(fn ->
112 DeprecationWarnings.check_gun_pool_options()
113 end) =~
114 "Your config is using old setting `config :pleroma, :connections_pool, await_up_timeout`."
115 end
116
117 test "pool timeout" do
118 old_config = [
119 federation: [
120 size: 50,
121 max_waiting: 10,
122 timeout: 10_000
123 ],
124 media: [
125 size: 50,
126 max_waiting: 10,
127 timeout: 10_000
128 ],
129 upload: [
130 size: 25,
131 max_waiting: 5,
132 timeout: 15_000
133 ],
134 default: [
135 size: 10,
136 max_waiting: 2,
137 timeout: 5_000
138 ]
139 ]
140
141 clear_config(:pools, old_config)
142
143 assert capture_log(fn ->
144 DeprecationWarnings.check_gun_pool_options()
145 end) =~
146 "Your config is using old setting name `timeout` instead of `recv_timeout` in pool settings"
147 end
148 end
149 end