Remove vapidPublicKey from Nodeinfo
[akkoma] / test / config / transfer_task_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Config.TransferTaskTest do
6 use Pleroma.DataCase
7
8 import ExUnit.CaptureLog
9
10 alias Pleroma.Config.TransferTask
11 alias Pleroma.ConfigDB
12
13 setup do: clear_config(:configurable_from_database, true)
14
15 test "transfer config values from db to env" do
16 refute Application.get_env(:pleroma, :test_key)
17 refute Application.get_env(:idna, :test_key)
18 refute Application.get_env(:quack, :test_key)
19
20 ConfigDB.create(%{
21 group: ":pleroma",
22 key: ":test_key",
23 value: [live: 2, com: 3]
24 })
25
26 ConfigDB.create(%{
27 group: ":idna",
28 key: ":test_key",
29 value: [live: 15, com: 35]
30 })
31
32 ConfigDB.create(%{
33 group: ":quack",
34 key: ":test_key",
35 value: [:test_value1, :test_value2]
36 })
37
38 TransferTask.start_link([])
39
40 assert Application.get_env(:pleroma, :test_key) == [live: 2, com: 3]
41 assert Application.get_env(:idna, :test_key) == [live: 15, com: 35]
42 assert Application.get_env(:quack, :test_key) == [:test_value1, :test_value2]
43
44 on_exit(fn ->
45 Application.delete_env(:pleroma, :test_key)
46 Application.delete_env(:idna, :test_key)
47 Application.delete_env(:quack, :test_key)
48 end)
49 end
50
51 test "transfer config values for 1 group and some keys" do
52 level = Application.get_env(:quack, :level)
53 meta = Application.get_env(:quack, :meta)
54
55 ConfigDB.create(%{
56 group: ":quack",
57 key: ":level",
58 value: :info
59 })
60
61 ConfigDB.create(%{
62 group: ":quack",
63 key: ":meta",
64 value: [:none]
65 })
66
67 TransferTask.start_link([])
68
69 assert Application.get_env(:quack, :level) == :info
70 assert Application.get_env(:quack, :meta) == [:none]
71 default = Pleroma.Config.Holder.default_config(:quack, :webhook_url)
72 assert Application.get_env(:quack, :webhook_url) == default
73
74 on_exit(fn ->
75 Application.put_env(:quack, :level, level)
76 Application.put_env(:quack, :meta, meta)
77 end)
78 end
79
80 test "transfer config values with full subkey update" do
81 emoji = Application.get_env(:pleroma, :emoji)
82 assets = Application.get_env(:pleroma, :assets)
83
84 ConfigDB.create(%{
85 group: ":pleroma",
86 key: ":emoji",
87 value: [groups: [a: 1, b: 2]]
88 })
89
90 ConfigDB.create(%{
91 group: ":pleroma",
92 key: ":assets",
93 value: [mascots: [a: 1, b: 2]]
94 })
95
96 TransferTask.start_link([])
97
98 emoji_env = Application.get_env(:pleroma, :emoji)
99 assert emoji_env[:groups] == [a: 1, b: 2]
100 assets_env = Application.get_env(:pleroma, :assets)
101 assert assets_env[:mascots] == [a: 1, b: 2]
102
103 on_exit(fn ->
104 Application.put_env(:pleroma, :emoji, emoji)
105 Application.put_env(:pleroma, :assets, assets)
106 end)
107 end
108
109 describe "pleroma restart" do
110 setup do
111 on_exit(fn -> Restarter.Pleroma.refresh() end)
112 end
113
114 test "don't restart if no reboot time settings were changed" do
115 emoji = Application.get_env(:pleroma, :emoji)
116 on_exit(fn -> Application.put_env(:pleroma, :emoji, emoji) end)
117
118 ConfigDB.create(%{
119 group: ":pleroma",
120 key: ":emoji",
121 value: [groups: [a: 1, b: 2]]
122 })
123
124 refute String.contains?(
125 capture_log(fn -> TransferTask.start_link([]) end),
126 "pleroma restarted"
127 )
128 end
129
130 test "on reboot time key" do
131 chat = Application.get_env(:pleroma, :chat)
132 on_exit(fn -> Application.put_env(:pleroma, :chat, chat) end)
133
134 ConfigDB.create(%{
135 group: ":pleroma",
136 key: ":chat",
137 value: [enabled: false]
138 })
139
140 assert capture_log(fn -> TransferTask.start_link([]) end) =~ "pleroma restarted"
141 end
142
143 test "on reboot time subkey" do
144 captcha = Application.get_env(:pleroma, Pleroma.Captcha)
145 on_exit(fn -> Application.put_env(:pleroma, Pleroma.Captcha, captcha) end)
146
147 ConfigDB.create(%{
148 group: ":pleroma",
149 key: "Pleroma.Captcha",
150 value: [seconds_valid: 60]
151 })
152
153 assert capture_log(fn -> TransferTask.start_link([]) end) =~ "pleroma restarted"
154 end
155
156 test "don't restart pleroma on reboot time key and subkey if there is false flag" do
157 chat = Application.get_env(:pleroma, :chat)
158 captcha = Application.get_env(:pleroma, Pleroma.Captcha)
159
160 on_exit(fn ->
161 Application.put_env(:pleroma, :chat, chat)
162 Application.put_env(:pleroma, Pleroma.Captcha, captcha)
163 end)
164
165 ConfigDB.create(%{
166 group: ":pleroma",
167 key: ":chat",
168 value: [enabled: false]
169 })
170
171 ConfigDB.create(%{
172 group: ":pleroma",
173 key: "Pleroma.Captcha",
174 value: [seconds_valid: 60]
175 })
176
177 refute String.contains?(
178 capture_log(fn -> TransferTask.load_and_update_env([], false) end),
179 "pleroma restarted"
180 )
181 end
182 end
183 end