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.Web.AdminAPI.ConfigControllerTest do
6 use Pleroma.Web.ConnCase
8 import ExUnit.CaptureLog
12 alias Pleroma.ConfigDB
15 admin = insert(:user, is_admin: true)
16 token = insert(:oauth_admin_token, user: admin)
20 |> assign(:user, admin)
21 |> assign(:token, token)
23 {:ok, %{admin: admin, token: token, conn: conn}}
26 describe "GET /api/pleroma/admin/config" do
27 setup do: clear_config(:configurable_from_database, true)
29 test "when configuration from database is off", %{conn: conn} do
30 Config.put(:configurable_from_database, false)
31 conn = get(conn, "/api/pleroma/admin/config")
33 assert json_response_and_validate_schema(conn, 400) ==
35 "error" => "To use this endpoint you need to enable configuration from database."
39 test "with settings only in db", %{conn: conn} do
40 config1 = insert(:config)
41 config2 = insert(:config)
43 conn = get(conn, "/api/pleroma/admin/config?only_db=true")
48 "group" => ":pleroma",
53 "group" => ":pleroma",
58 } = json_response_and_validate_schema(conn, 200)
60 assert key1 == inspect(config1.key)
61 assert key2 == inspect(config2.key)
64 test "db is added to settings that are in db", %{conn: conn} do
65 _config = insert(:config, key: ":instance", value: [name: "Some name"])
67 %{"configs" => configs} =
69 |> get("/api/pleroma/admin/config")
70 |> json_response_and_validate_schema(200)
73 Enum.filter(configs, fn %{"group" => group, "key" => key} ->
74 group == ":pleroma" and key == ":instance"
77 assert instance_config["db"] == [":name"]
80 test "merged default setting with db settings", %{conn: conn} do
81 config1 = insert(:config)
82 config2 = insert(:config)
86 value: [k1: :v1, k2: :v2]
89 %{"configs" => configs} =
91 |> get("/api/pleroma/admin/config")
92 |> json_response_and_validate_schema(200)
94 assert length(configs) > 3
96 saved_configs = [config1, config2, config3]
97 keys = Enum.map(saved_configs, &inspect(&1.key))
100 Enum.filter(configs, fn %{"group" => group, "key" => key} ->
101 group == ":pleroma" and key in keys
104 assert length(received_configs) == 3
109 |> ConfigDB.to_json_types()
111 keys = Enum.map(saved_configs -- [config3], &inspect(&1.key))
113 values = Enum.map(saved_configs, &ConfigDB.to_json_types(&1.value))
115 mapset_keys = MapSet.new(keys ++ db_keys)
117 Enum.each(received_configs, fn %{"value" => value, "db" => db} ->
119 assert MapSet.subset?(db, mapset_keys)
121 assert value in values
125 test "subkeys with full update right merge", %{conn: conn} do
128 value: [groups: [a: 1, b: 2], key: [a: 1]]
133 value: [mascots: [a: 1, b: 2], key: [a: 1]]
136 %{"configs" => configs} =
138 |> get("/api/pleroma/admin/config")
139 |> json_response_and_validate_schema(200)
142 Enum.filter(configs, fn %{"group" => group, "key" => key} ->
143 group == ":pleroma" and key in [":emoji", ":assets"]
146 emoji = Enum.find(vals, fn %{"key" => key} -> key == ":emoji" end)
147 assets = Enum.find(vals, fn %{"key" => key} -> key == ":assets" end)
149 emoji_val = ConfigDB.to_elixir_types(emoji["value"])
150 assets_val = ConfigDB.to_elixir_types(assets["value"])
152 assert emoji_val[:groups] == [a: 1, b: 2]
153 assert assets_val[:mascots] == [a: 1, b: 2]
156 test "with valid `admin_token` query parameter, skips OAuth scopes check" do
157 clear_config([:admin_token], "password123")
160 |> get("/api/pleroma/admin/config?admin_token=password123")
161 |> json_response_and_validate_schema(200)
165 test "POST /api/pleroma/admin/config with configdb disabled", %{conn: conn} do
166 clear_config(:configurable_from_database, false)
170 |> put_req_header("content-type", "application/json")
171 |> post("/api/pleroma/admin/config", %{"configs" => []})
173 assert json_response_and_validate_schema(conn, 400) ==
174 %{"error" => "To use this endpoint you need to enable configuration from database."}
177 describe "POST /api/pleroma/admin/config" do
179 http = Application.get_env(:pleroma, :http)
182 Application.delete_env(:pleroma, :key1)
183 Application.delete_env(:pleroma, :key2)
184 Application.delete_env(:pleroma, :key3)
185 Application.delete_env(:pleroma, :key4)
186 Application.delete_env(:pleroma, :keyaa1)
187 Application.delete_env(:pleroma, :keyaa2)
188 Application.delete_env(:pleroma, Pleroma.Web.Endpoint.NotReal)
189 Application.delete_env(:pleroma, Pleroma.Captcha.NotReal)
190 Application.put_env(:pleroma, :http, http)
191 Application.put_env(:tesla, :adapter, Tesla.Mock)
192 Restarter.Pleroma.refresh()
196 setup do: clear_config(:configurable_from_database, true)
198 @tag capture_log: true
199 test "create new config setting in db", %{conn: conn} do
200 ueberauth = Application.get_env(:ueberauth, Ueberauth)
201 on_exit(fn -> Application.put_env(:ueberauth, Ueberauth, ueberauth) end)
205 |> put_req_header("content-type", "application/json")
206 |> post("/api/pleroma/admin/config", %{
208 %{group: ":pleroma", key: ":key1", value: "value1"},
212 value: [%{"tuple" => [":consumer_secret", "aaaa"]}]
218 ":nested_1" => "nested_value1",
220 %{":nested_22" => "nested_value222"},
221 %{":nested_33" => %{":nested_44" => "nested_444"}}
229 %{"nested_3" => ":nested_3", "nested_33" => "nested_33"},
230 %{"nested_4" => true}
236 value: %{":nested_5" => ":upload", "endpoint" => "https://example.com"}
241 value: %{"tuple" => ["string", "Pleroma.Captcha.NotReal", []]}
246 assert json_response_and_validate_schema(conn, 200) == %{
249 "group" => ":pleroma",
255 "group" => ":ueberauth",
256 "key" => "Ueberauth",
257 "value" => [%{"tuple" => [":consumer_secret", "aaaa"]}],
258 "db" => [":consumer_secret"]
261 "group" => ":pleroma",
264 ":nested_1" => "nested_value1",
266 %{":nested_22" => "nested_value222"},
267 %{":nested_33" => %{":nested_44" => "nested_444"}}
273 "group" => ":pleroma",
276 %{"nested_3" => ":nested_3", "nested_33" => "nested_33"},
277 %{"nested_4" => true}
282 "group" => ":pleroma",
284 "value" => %{"endpoint" => "https://example.com", ":nested_5" => ":upload"},
290 "value" => %{"tuple" => ["string", "Pleroma.Captcha.NotReal", []]},
294 "need_reboot" => false
297 assert Application.get_env(:pleroma, :key1) == "value1"
299 assert Application.get_env(:pleroma, :key2) == %{
300 nested_1: "nested_value1",
302 %{nested_22: "nested_value222"},
303 %{nested_33: %{nested_44: "nested_444"}}
307 assert Application.get_env(:pleroma, :key3) == [
308 %{"nested_3" => :nested_3, "nested_33" => "nested_33"},
309 %{"nested_4" => true}
312 assert Application.get_env(:pleroma, :key4) == %{
313 "endpoint" => "https://example.com",
317 assert Application.get_env(:idna, :key5) == {"string", Pleroma.Captcha.NotReal, []}
320 test "save configs setting without explicit key", %{conn: conn} do
321 level = Application.get_env(:quack, :level)
322 meta = Application.get_env(:quack, :meta)
323 webhook_url = Application.get_env(:quack, :webhook_url)
326 Application.put_env(:quack, :level, level)
327 Application.put_env(:quack, :meta, meta)
328 Application.put_env(:quack, :webhook_url, webhook_url)
333 |> put_req_header("content-type", "application/json")
334 |> post("/api/pleroma/admin/config", %{
349 value: "https://hooks.slack.com/services/KEY"
354 assert json_response_and_validate_schema(conn, 200) == %{
365 "value" => [":none"],
370 "key" => ":webhook_url",
371 "value" => "https://hooks.slack.com/services/KEY",
372 "db" => [":webhook_url"]
375 "need_reboot" => false
378 assert Application.get_env(:quack, :level) == :info
379 assert Application.get_env(:quack, :meta) == [:none]
380 assert Application.get_env(:quack, :webhook_url) == "https://hooks.slack.com/services/KEY"
383 test "saving config with partial update", %{conn: conn} do
384 insert(:config, key: ":key1", value: :erlang.term_to_binary(key1: 1, key2: 2))
388 |> put_req_header("content-type", "application/json")
389 |> post("/api/pleroma/admin/config", %{
391 %{group: ":pleroma", key: ":key1", value: [%{"tuple" => [":key3", 3]}]}
395 assert json_response_and_validate_schema(conn, 200) == %{
398 "group" => ":pleroma",
401 %{"tuple" => [":key1", 1]},
402 %{"tuple" => [":key2", 2]},
403 %{"tuple" => [":key3", 3]}
405 "db" => [":key1", ":key2", ":key3"]
408 "need_reboot" => false
412 test "saving config which need pleroma reboot", %{conn: conn} do
413 chat = Config.get(:chat)
414 on_exit(fn -> Config.put(:chat, chat) end)
417 |> put_req_header("content-type", "application/json")
419 "/api/pleroma/admin/config",
422 %{group: ":pleroma", key: ":chat", value: [%{"tuple" => [":enabled", true]}]}
426 |> json_response_and_validate_schema(200) == %{
429 "db" => [":enabled"],
430 "group" => ":pleroma",
432 "value" => [%{"tuple" => [":enabled", true]}]
435 "need_reboot" => true
440 |> get("/api/pleroma/admin/config")
441 |> json_response_and_validate_schema(200)
443 assert configs["need_reboot"]
446 assert conn |> get("/api/pleroma/admin/restart") |> json_response(200) ==
448 end) =~ "pleroma restarted"
452 |> get("/api/pleroma/admin/config")
453 |> json_response_and_validate_schema(200)
455 assert configs["need_reboot"] == false
458 test "update setting which need reboot, don't change reboot flag until reboot", %{conn: conn} do
459 chat = Config.get(:chat)
460 on_exit(fn -> Config.put(:chat, chat) end)
463 |> put_req_header("content-type", "application/json")
465 "/api/pleroma/admin/config",
468 %{group: ":pleroma", key: ":chat", value: [%{"tuple" => [":enabled", true]}]}
472 |> json_response_and_validate_schema(200) == %{
475 "db" => [":enabled"],
476 "group" => ":pleroma",
478 "value" => [%{"tuple" => [":enabled", true]}]
481 "need_reboot" => true
485 |> put_req_header("content-type", "application/json")
486 |> post("/api/pleroma/admin/config", %{
488 %{group: ":pleroma", key: ":key1", value: [%{"tuple" => [":key3", 3]}]}
491 |> json_response_and_validate_schema(200) == %{
494 "group" => ":pleroma",
497 %{"tuple" => [":key3", 3]}
502 "need_reboot" => true
506 assert conn |> get("/api/pleroma/admin/restart") |> json_response(200) ==
508 end) =~ "pleroma restarted"
512 |> get("/api/pleroma/admin/config")
513 |> json_response_and_validate_schema(200)
515 assert configs["need_reboot"] == false
518 test "saving config with nested merge", %{conn: conn} do
519 insert(:config, key: :key1, value: [key1: 1, key2: [k1: 1, k2: 2]])
523 |> put_req_header("content-type", "application/json")
524 |> post("/api/pleroma/admin/config", %{
530 %{"tuple" => [":key3", 3]},
535 %{"tuple" => [":k2", 1]},
536 %{"tuple" => [":k3", 3]}
545 assert json_response_and_validate_schema(conn, 200) == %{
548 "group" => ":pleroma",
551 %{"tuple" => [":key1", 1]},
552 %{"tuple" => [":key3", 3]},
557 %{"tuple" => [":k1", 1]},
558 %{"tuple" => [":k2", 1]},
559 %{"tuple" => [":k3", 3]}
564 "db" => [":key1", ":key3", ":key2"]
567 "need_reboot" => false
571 test "saving special atoms", %{conn: conn} do
574 |> put_req_header("content-type", "application/json")
575 |> post("/api/pleroma/admin/config", %{
578 "group" => ":pleroma",
584 [%{"tuple" => [":versions", [":tlsv1", ":tlsv1.1", ":tlsv1.2"]]}]
592 assert json_response_and_validate_schema(conn, 200) == %{
595 "group" => ":pleroma",
601 [%{"tuple" => [":versions", [":tlsv1", ":tlsv1.1", ":tlsv1.2"]]}]
605 "db" => [":ssl_options"]
608 "need_reboot" => false
611 assert Application.get_env(:pleroma, :key1) == [
612 ssl_options: [versions: [:tlsv1, :"tlsv1.1", :"tlsv1.2"]]
616 test "saving full setting if value is in full_key_update list", %{conn: conn} do
617 backends = Application.get_env(:logger, :backends)
618 on_exit(fn -> Application.put_env(:logger, :backends, backends) end)
626 Pleroma.Config.TransferTask.load_and_update_env([], false)
628 assert Application.get_env(:logger, :backends) == []
632 |> put_req_header("content-type", "application/json")
633 |> post("/api/pleroma/admin/config", %{
643 assert json_response_and_validate_schema(conn, 200) == %{
646 "group" => ":logger",
647 "key" => ":backends",
651 "db" => [":backends"]
654 "need_reboot" => false
657 assert Application.get_env(:logger, :backends) == [
662 test "saving full setting if value is not keyword", %{conn: conn} do
666 value: Tesla.Adapter.Hackey
671 |> put_req_header("content-type", "application/json")
672 |> post("/api/pleroma/admin/config", %{
674 %{group: ":tesla", key: ":adapter", value: "Tesla.Adapter.Httpc"}
678 assert json_response_and_validate_schema(conn, 200) == %{
683 "value" => "Tesla.Adapter.Httpc",
687 "need_reboot" => false
691 test "update config setting & delete with fallback to default value", %{
696 ueberauth = Application.get_env(:ueberauth, Ueberauth)
697 insert(:config, key: :keyaa1)
698 insert(:config, key: :keyaa2)
708 |> put_req_header("content-type", "application/json")
709 |> post("/api/pleroma/admin/config", %{
711 %{group: ":pleroma", key: ":keyaa1", value: "another_value"},
712 %{group: ":pleroma", key: ":keyaa2", value: "another_value"}
716 assert json_response_and_validate_schema(conn, 200) == %{
719 "group" => ":pleroma",
721 "value" => "another_value",
725 "group" => ":pleroma",
727 "value" => "another_value",
731 "need_reboot" => false
734 assert Application.get_env(:pleroma, :keyaa1) == "another_value"
735 assert Application.get_env(:pleroma, :keyaa2) == "another_value"
736 assert Application.get_env(:ueberauth, Ueberauth) == config3.value
740 |> assign(:user, admin)
741 |> assign(:token, token)
742 |> put_req_header("content-type", "application/json")
743 |> post("/api/pleroma/admin/config", %{
745 %{group: ":pleroma", key: ":keyaa2", delete: true},
754 assert json_response_and_validate_schema(conn, 200) == %{
756 "need_reboot" => false
759 assert Application.get_env(:ueberauth, Ueberauth) == ueberauth
760 refute Keyword.has_key?(Application.get_all_env(:pleroma), :keyaa2)
763 test "common config example", %{conn: conn} do
766 |> put_req_header("content-type", "application/json")
767 |> post("/api/pleroma/admin/config", %{
770 "group" => ":pleroma",
771 "key" => "Pleroma.Captcha.NotReal",
773 %{"tuple" => [":enabled", false]},
774 %{"tuple" => [":method", "Pleroma.Captcha.Kocaptcha"]},
775 %{"tuple" => [":seconds_valid", 60]},
776 %{"tuple" => [":path", ""]},
777 %{"tuple" => [":key1", nil]},
778 %{"tuple" => [":partial_chain", "&:hackney_connect.partial_chain/1"]},
779 %{"tuple" => [":regex1", "~r/https:\/\/example.com/"]},
780 %{"tuple" => [":regex2", "~r/https:\/\/example.com/u"]},
781 %{"tuple" => [":regex3", "~r/https:\/\/example.com/i"]},
782 %{"tuple" => [":regex4", "~r/https:\/\/example.com/s"]},
783 %{"tuple" => [":name", "Pleroma"]}
789 assert Config.get([Pleroma.Captcha.NotReal, :name]) == "Pleroma"
791 assert json_response_and_validate_schema(conn, 200) == %{
794 "group" => ":pleroma",
795 "key" => "Pleroma.Captcha.NotReal",
797 %{"tuple" => [":enabled", false]},
798 %{"tuple" => [":method", "Pleroma.Captcha.Kocaptcha"]},
799 %{"tuple" => [":seconds_valid", 60]},
800 %{"tuple" => [":path", ""]},
801 %{"tuple" => [":key1", nil]},
802 %{"tuple" => [":partial_chain", "&:hackney_connect.partial_chain/1"]},
803 %{"tuple" => [":regex1", "~r/https:\\/\\/example.com/"]},
804 %{"tuple" => [":regex2", "~r/https:\\/\\/example.com/u"]},
805 %{"tuple" => [":regex3", "~r/https:\\/\\/example.com/i"]},
806 %{"tuple" => [":regex4", "~r/https:\\/\\/example.com/s"]},
807 %{"tuple" => [":name", "Pleroma"]}
824 "need_reboot" => false
828 test "tuples with more than two values", %{conn: conn} do
831 |> put_req_header("content-type", "application/json")
832 |> post("/api/pleroma/admin/config", %{
835 "group" => ":pleroma",
836 "key" => "Pleroma.Web.Endpoint.NotReal",
853 "Pleroma.Web.MastodonAPI.WebsocketHandler",
860 "Phoenix.Endpoint.CowboyWebSocket",
863 "Phoenix.Transports.WebSocket",
866 "Pleroma.Web.Endpoint",
867 "Pleroma.Web.UserSocket",
878 "Phoenix.Endpoint.Cowboy2Handler",
879 %{"tuple" => ["Pleroma.Web.Endpoint", []]}
896 assert json_response_and_validate_schema(conn, 200) == %{
899 "group" => ":pleroma",
900 "key" => "Pleroma.Web.Endpoint.NotReal",
917 "Pleroma.Web.MastodonAPI.WebsocketHandler",
924 "Phoenix.Endpoint.CowboyWebSocket",
927 "Phoenix.Transports.WebSocket",
930 "Pleroma.Web.Endpoint",
931 "Pleroma.Web.UserSocket",
942 "Phoenix.Endpoint.Cowboy2Handler",
943 %{"tuple" => ["Pleroma.Web.Endpoint", []]}
959 "need_reboot" => false
963 test "settings with nesting map", %{conn: conn} do
966 |> put_req_header("content-type", "application/json")
967 |> post("/api/pleroma/admin/config", %{
970 "group" => ":pleroma",
973 %{"tuple" => [":key2", "some_val"]},
978 ":max_options" => 20,
979 ":max_option_chars" => 200,
980 ":min_expiration" => 0,
981 ":max_expiration" => 31_536_000,
983 ":max_options" => 20,
984 ":max_option_chars" => 200,
985 ":min_expiration" => 0,
986 ":max_expiration" => 31_536_000
996 assert json_response_and_validate_schema(conn, 200) ==
1000 "group" => ":pleroma",
1003 %{"tuple" => [":key2", "some_val"]},
1008 ":max_expiration" => 31_536_000,
1009 ":max_option_chars" => 200,
1010 ":max_options" => 20,
1011 ":min_expiration" => 0,
1013 ":max_expiration" => 31_536_000,
1014 ":max_option_chars" => 200,
1015 ":max_options" => 20,
1016 ":min_expiration" => 0
1022 "db" => [":key2", ":key3"]
1025 "need_reboot" => false
1029 test "value as map", %{conn: conn} do
1032 |> put_req_header("content-type", "application/json")
1033 |> post("/api/pleroma/admin/config", %{
1036 "group" => ":pleroma",
1038 "value" => %{"key" => "some_val"}
1043 assert json_response_and_validate_schema(conn, 200) ==
1047 "group" => ":pleroma",
1049 "value" => %{"key" => "some_val"},
1053 "need_reboot" => false
1057 test "queues key as atom", %{conn: conn} do
1060 |> put_req_header("content-type", "application/json")
1061 |> post("/api/pleroma/admin/config", %{
1067 %{"tuple" => [":federator_incoming", 50]},
1068 %{"tuple" => [":federator_outgoing", 50]},
1069 %{"tuple" => [":web_push", 50]},
1070 %{"tuple" => [":mailer", 10]},
1071 %{"tuple" => [":transmogrifier", 20]},
1072 %{"tuple" => [":scheduled_activities", 10]},
1073 %{"tuple" => [":background", 5]}
1079 assert json_response_and_validate_schema(conn, 200) == %{
1085 %{"tuple" => [":federator_incoming", 50]},
1086 %{"tuple" => [":federator_outgoing", 50]},
1087 %{"tuple" => [":web_push", 50]},
1088 %{"tuple" => [":mailer", 10]},
1089 %{"tuple" => [":transmogrifier", 20]},
1090 %{"tuple" => [":scheduled_activities", 10]},
1091 %{"tuple" => [":background", 5]}
1094 ":federator_incoming",
1095 ":federator_outgoing",
1099 ":scheduled_activities",
1104 "need_reboot" => false
1108 test "delete part of settings by atom subkeys", %{conn: conn} do
1111 value: [subkey1: "val1", subkey2: "val2", subkey3: "val3"]
1116 |> put_req_header("content-type", "application/json")
1117 |> post("/api/pleroma/admin/config", %{
1122 subkeys: [":subkey1", ":subkey3"],
1128 assert json_response_and_validate_schema(conn, 200) == %{
1131 "group" => ":pleroma",
1133 "value" => [%{"tuple" => [":subkey2", "val2"]}],
1134 "db" => [":subkey2"]
1137 "need_reboot" => false
1141 test "proxy tuple localhost", %{conn: conn} do
1144 |> put_req_header("content-type", "application/json")
1145 |> post("/api/pleroma/admin/config", %{
1151 %{"tuple" => [":proxy_url", %{"tuple" => [":socks5", "localhost", 1234]}]}
1160 "group" => ":pleroma",
1166 } = json_response_and_validate_schema(conn, 200)
1168 assert %{"tuple" => [":proxy_url", %{"tuple" => [":socks5", "localhost", 1234]}]} in value
1169 assert ":proxy_url" in db
1172 test "proxy tuple domain", %{conn: conn} do
1175 |> put_req_header("content-type", "application/json")
1176 |> post("/api/pleroma/admin/config", %{
1182 %{"tuple" => [":proxy_url", %{"tuple" => [":socks5", "domain.com", 1234]}]}
1191 "group" => ":pleroma",
1197 } = json_response_and_validate_schema(conn, 200)
1199 assert %{"tuple" => [":proxy_url", %{"tuple" => [":socks5", "domain.com", 1234]}]} in value
1200 assert ":proxy_url" in db
1203 test "proxy tuple ip", %{conn: conn} do
1206 |> put_req_header("content-type", "application/json")
1207 |> post("/api/pleroma/admin/config", %{
1213 %{"tuple" => [":proxy_url", %{"tuple" => [":socks5", "127.0.0.1", 1234]}]}
1222 "group" => ":pleroma",
1228 } = json_response_and_validate_schema(conn, 200)
1230 assert %{"tuple" => [":proxy_url", %{"tuple" => [":socks5", "127.0.0.1", 1234]}]} in value
1231 assert ":proxy_url" in db
1234 @tag capture_log: true
1235 test "doesn't set keys not in the whitelist", %{conn: conn} do
1236 clear_config(:database_config_whitelist, [
1239 {:pleroma, Pleroma.Captcha.NotReal},
1244 |> put_req_header("content-type", "application/json")
1245 |> post("/api/pleroma/admin/config", %{
1247 %{group: ":pleroma", key: ":key1", value: "value1"},
1248 %{group: ":pleroma", key: ":key2", value: "value2"},
1249 %{group: ":pleroma", key: ":key3", value: "value3"},
1250 %{group: ":pleroma", key: "Pleroma.Web.Endpoint.NotReal", value: "value4"},
1251 %{group: ":pleroma", key: "Pleroma.Captcha.NotReal", value: "value5"},
1252 %{group: ":not_real", key: ":anything", value: "value6"}
1256 assert Application.get_env(:pleroma, :key1) == "value1"
1257 assert Application.get_env(:pleroma, :key2) == "value2"
1258 assert Application.get_env(:pleroma, :key3) == nil
1259 assert Application.get_env(:pleroma, Pleroma.Web.Endpoint.NotReal) == nil
1260 assert Application.get_env(:pleroma, Pleroma.Captcha.NotReal) == "value5"
1261 assert Application.get_env(:not_real, :anything) == "value6"
1264 test "args for Pleroma.Upload.Filter.Mogrify with custom tuples", %{conn: conn} do
1265 clear_config(Pleroma.Upload.Filter.Mogrify)
1268 |> put_req_header("content-type", "application/json")
1269 |> post("/api/pleroma/admin/config", %{
1273 key: "Pleroma.Upload.Filter.Mogrify",
1275 %{"tuple" => [":args", ["auto-orient", "strip"]]}
1280 |> json_response_and_validate_schema(200) == %{
1283 "group" => ":pleroma",
1284 "key" => "Pleroma.Upload.Filter.Mogrify",
1286 %{"tuple" => [":args", ["auto-orient", "strip"]]}
1291 "need_reboot" => false
1294 assert Config.get(Pleroma.Upload.Filter.Mogrify) == [args: ["auto-orient", "strip"]]
1297 |> put_req_header("content-type", "application/json")
1298 |> post("/api/pleroma/admin/config", %{
1302 key: "Pleroma.Upload.Filter.Mogrify",
1310 "{\"implode\", \"1\"}",
1311 "{\"resize\", \"3840x1080>\"}"
1319 |> json_response(200) == %{
1322 "group" => ":pleroma",
1323 "key" => "Pleroma.Upload.Filter.Mogrify",
1331 "{\"implode\", \"1\"}",
1332 "{\"resize\", \"3840x1080>\"}"
1340 "need_reboot" => false
1343 assert Config.get(Pleroma.Upload.Filter.Mogrify) == [
1344 args: ["auto-orient", "strip", {"implode", "1"}, {"resize", "3840x1080>"}]
1348 test "enables the welcome messages", %{conn: conn} do
1349 clear_config([:welcome])
1352 "group" => ":pleroma",
1353 "key" => ":welcome",
1359 %{"tuple" => [":enabled", true]},
1360 %{"tuple" => [":message", "Welcome to Pleroma!"]},
1361 %{"tuple" => [":sender_nickname", "pleroma"]}
1369 %{"tuple" => [":enabled", true]},
1370 %{"tuple" => [":message", "Welcome to Pleroma!"]},
1371 %{"tuple" => [":sender_nickname", "pleroma"]}
1379 %{"tuple" => [":enabled", true]},
1380 %{"tuple" => [":sender", %{"tuple" => ["pleroma@dev.dev", "Pleroma"]}]},
1381 %{"tuple" => [":subject", "Welcome to <%= instance_name %>!"]},
1382 %{"tuple" => [":html", "Welcome to <%= instance_name %>!"]},
1383 %{"tuple" => [":text", "Welcome to <%= instance_name %>!"]}
1390 refute Pleroma.User.WelcomeEmail.enabled?()
1391 refute Pleroma.User.WelcomeMessage.enabled?()
1392 refute Pleroma.User.WelcomeChatMessage.enabled?()
1396 |> put_req_header("content-type", "application/json")
1397 |> post("/api/pleroma/admin/config", %{"configs" => [params]})
1398 |> json_response_and_validate_schema(200)
1400 assert Pleroma.User.WelcomeEmail.enabled?()
1401 assert Pleroma.User.WelcomeMessage.enabled?()
1402 assert Pleroma.User.WelcomeChatMessage.enabled?()
1407 "db" => [":direct_message", ":chat_message", ":email"],
1408 "group" => ":pleroma",
1409 "key" => ":welcome",
1410 "value" => params["value"]
1413 "need_reboot" => false
1418 describe "GET /api/pleroma/admin/config/descriptions" do
1419 test "structure", %{conn: conn} do
1420 conn = get(conn, "/api/pleroma/admin/config/descriptions")
1422 assert [child | _others] = json_response_and_validate_schema(conn, 200)
1424 assert child["children"]
1426 assert String.starts_with?(child["group"], ":")
1427 assert child["description"]
1430 test "filters by database configuration whitelist", %{conn: conn} do
1431 clear_config(:database_config_whitelist, [
1432 {:pleroma, :instance},
1433 {:pleroma, :activitypub},
1434 {:pleroma, Pleroma.Upload},
1438 conn = get(conn, "/api/pleroma/admin/config/descriptions")
1440 children = json_response_and_validate_schema(conn, 200)
1442 assert length(children) == 4
1444 assert Enum.count(children, fn c -> c["group"] == ":pleroma" end) == 3
1446 instance = Enum.find(children, fn c -> c["key"] == ":instance" end)
1447 assert instance["children"]
1449 activitypub = Enum.find(children, fn c -> c["key"] == ":activitypub" end)
1450 assert activitypub["children"]
1452 web_endpoint = Enum.find(children, fn c -> c["key"] == "Pleroma.Upload" end)
1453 assert web_endpoint["children"]
1455 esshd = Enum.find(children, fn c -> c["group"] == ":esshd" end)
1456 assert esshd["children"]