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, async: true
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 error", %{conn: conn} do
168 |> put_req_header("content-type", "application/json")
169 |> post("/api/pleroma/admin/config", %{"configs" => []})
171 assert json_response_and_validate_schema(conn, 400) ==
172 %{"error" => "To use this endpoint you need to enable configuration from database."}
175 describe "POST /api/pleroma/admin/config" do
177 http = Application.get_env(:pleroma, :http)
180 Application.delete_env(:pleroma, :key1)
181 Application.delete_env(:pleroma, :key2)
182 Application.delete_env(:pleroma, :key3)
183 Application.delete_env(:pleroma, :key4)
184 Application.delete_env(:pleroma, :keyaa1)
185 Application.delete_env(:pleroma, :keyaa2)
186 Application.delete_env(:pleroma, Pleroma.Web.Endpoint.NotReal)
187 Application.delete_env(:pleroma, Pleroma.Captcha.NotReal)
188 Application.put_env(:pleroma, :http, http)
189 Application.put_env(:tesla, :adapter, Tesla.Mock)
190 Restarter.Pleroma.refresh()
194 setup do: clear_config(:configurable_from_database, true)
196 @tag capture_log: true
197 test "create new config setting in db", %{conn: conn} do
198 ueberauth = Application.get_env(:ueberauth, Ueberauth)
199 on_exit(fn -> Application.put_env(:ueberauth, Ueberauth, ueberauth) end)
203 |> put_req_header("content-type", "application/json")
204 |> post("/api/pleroma/admin/config", %{
206 %{group: ":pleroma", key: ":key1", value: "value1"},
210 value: [%{"tuple" => [":consumer_secret", "aaaa"]}]
216 ":nested_1" => "nested_value1",
218 %{":nested_22" => "nested_value222"},
219 %{":nested_33" => %{":nested_44" => "nested_444"}}
227 %{"nested_3" => ":nested_3", "nested_33" => "nested_33"},
228 %{"nested_4" => true}
234 value: %{":nested_5" => ":upload", "endpoint" => "https://example.com"}
239 value: %{"tuple" => ["string", "Pleroma.Captcha.NotReal", []]}
244 assert json_response_and_validate_schema(conn, 200) == %{
247 "group" => ":pleroma",
253 "group" => ":ueberauth",
254 "key" => "Ueberauth",
255 "value" => [%{"tuple" => [":consumer_secret", "aaaa"]}],
256 "db" => [":consumer_secret"]
259 "group" => ":pleroma",
262 ":nested_1" => "nested_value1",
264 %{":nested_22" => "nested_value222"},
265 %{":nested_33" => %{":nested_44" => "nested_444"}}
271 "group" => ":pleroma",
274 %{"nested_3" => ":nested_3", "nested_33" => "nested_33"},
275 %{"nested_4" => true}
280 "group" => ":pleroma",
282 "value" => %{"endpoint" => "https://example.com", ":nested_5" => ":upload"},
288 "value" => %{"tuple" => ["string", "Pleroma.Captcha.NotReal", []]},
292 "need_reboot" => false
295 assert Application.get_env(:pleroma, :key1) == "value1"
297 assert Application.get_env(:pleroma, :key2) == %{
298 nested_1: "nested_value1",
300 %{nested_22: "nested_value222"},
301 %{nested_33: %{nested_44: "nested_444"}}
305 assert Application.get_env(:pleroma, :key3) == [
306 %{"nested_3" => :nested_3, "nested_33" => "nested_33"},
307 %{"nested_4" => true}
310 assert Application.get_env(:pleroma, :key4) == %{
311 "endpoint" => "https://example.com",
315 assert Application.get_env(:idna, :key5) == {"string", Pleroma.Captcha.NotReal, []}
318 test "save configs setting without explicit key", %{conn: conn} do
319 level = Application.get_env(:quack, :level)
320 meta = Application.get_env(:quack, :meta)
321 webhook_url = Application.get_env(:quack, :webhook_url)
324 Application.put_env(:quack, :level, level)
325 Application.put_env(:quack, :meta, meta)
326 Application.put_env(:quack, :webhook_url, webhook_url)
331 |> put_req_header("content-type", "application/json")
332 |> post("/api/pleroma/admin/config", %{
347 value: "https://hooks.slack.com/services/KEY"
352 assert json_response_and_validate_schema(conn, 200) == %{
363 "value" => [":none"],
368 "key" => ":webhook_url",
369 "value" => "https://hooks.slack.com/services/KEY",
370 "db" => [":webhook_url"]
373 "need_reboot" => false
376 assert Application.get_env(:quack, :level) == :info
377 assert Application.get_env(:quack, :meta) == [:none]
378 assert Application.get_env(:quack, :webhook_url) == "https://hooks.slack.com/services/KEY"
381 test "saving config with partial update", %{conn: conn} do
382 insert(:config, key: ":key1", value: :erlang.term_to_binary(key1: 1, key2: 2))
386 |> put_req_header("content-type", "application/json")
387 |> post("/api/pleroma/admin/config", %{
389 %{group: ":pleroma", key: ":key1", value: [%{"tuple" => [":key3", 3]}]}
393 assert json_response_and_validate_schema(conn, 200) == %{
396 "group" => ":pleroma",
399 %{"tuple" => [":key1", 1]},
400 %{"tuple" => [":key2", 2]},
401 %{"tuple" => [":key3", 3]}
403 "db" => [":key1", ":key2", ":key3"]
406 "need_reboot" => false
410 test "saving config which need pleroma reboot", %{conn: conn} do
411 chat = Config.get(:chat)
412 on_exit(fn -> Config.put(:chat, chat) end)
415 |> put_req_header("content-type", "application/json")
417 "/api/pleroma/admin/config",
420 %{group: ":pleroma", key: ":chat", value: [%{"tuple" => [":enabled", true]}]}
424 |> json_response_and_validate_schema(200) == %{
427 "db" => [":enabled"],
428 "group" => ":pleroma",
430 "value" => [%{"tuple" => [":enabled", true]}]
433 "need_reboot" => true
438 |> get("/api/pleroma/admin/config")
439 |> json_response_and_validate_schema(200)
441 assert configs["need_reboot"]
444 assert conn |> get("/api/pleroma/admin/restart") |> json_response(200) ==
446 end) =~ "pleroma restarted"
450 |> get("/api/pleroma/admin/config")
451 |> json_response_and_validate_schema(200)
453 assert configs["need_reboot"] == false
456 test "update setting which need reboot, don't change reboot flag until reboot", %{conn: conn} do
457 chat = Config.get(:chat)
458 on_exit(fn -> Config.put(:chat, chat) end)
461 |> put_req_header("content-type", "application/json")
463 "/api/pleroma/admin/config",
466 %{group: ":pleroma", key: ":chat", value: [%{"tuple" => [":enabled", true]}]}
470 |> json_response_and_validate_schema(200) == %{
473 "db" => [":enabled"],
474 "group" => ":pleroma",
476 "value" => [%{"tuple" => [":enabled", true]}]
479 "need_reboot" => true
483 |> put_req_header("content-type", "application/json")
484 |> post("/api/pleroma/admin/config", %{
486 %{group: ":pleroma", key: ":key1", value: [%{"tuple" => [":key3", 3]}]}
489 |> json_response_and_validate_schema(200) == %{
492 "group" => ":pleroma",
495 %{"tuple" => [":key3", 3]}
500 "need_reboot" => true
504 assert conn |> get("/api/pleroma/admin/restart") |> json_response(200) ==
506 end) =~ "pleroma restarted"
510 |> get("/api/pleroma/admin/config")
511 |> json_response_and_validate_schema(200)
513 assert configs["need_reboot"] == false
516 test "saving config with nested merge", %{conn: conn} do
517 insert(:config, key: :key1, value: [key1: 1, key2: [k1: 1, k2: 2]])
521 |> put_req_header("content-type", "application/json")
522 |> post("/api/pleroma/admin/config", %{
528 %{"tuple" => [":key3", 3]},
533 %{"tuple" => [":k2", 1]},
534 %{"tuple" => [":k3", 3]}
543 assert json_response_and_validate_schema(conn, 200) == %{
546 "group" => ":pleroma",
549 %{"tuple" => [":key1", 1]},
550 %{"tuple" => [":key3", 3]},
555 %{"tuple" => [":k1", 1]},
556 %{"tuple" => [":k2", 1]},
557 %{"tuple" => [":k3", 3]}
562 "db" => [":key1", ":key3", ":key2"]
565 "need_reboot" => false
569 test "saving special atoms", %{conn: conn} do
572 |> put_req_header("content-type", "application/json")
573 |> post("/api/pleroma/admin/config", %{
576 "group" => ":pleroma",
582 [%{"tuple" => [":versions", [":tlsv1", ":tlsv1.1", ":tlsv1.2"]]}]
590 assert json_response_and_validate_schema(conn, 200) == %{
593 "group" => ":pleroma",
599 [%{"tuple" => [":versions", [":tlsv1", ":tlsv1.1", ":tlsv1.2"]]}]
603 "db" => [":ssl_options"]
606 "need_reboot" => false
609 assert Application.get_env(:pleroma, :key1) == [
610 ssl_options: [versions: [:tlsv1, :"tlsv1.1", :"tlsv1.2"]]
614 test "saving full setting if value is in full_key_update list", %{conn: conn} do
615 backends = Application.get_env(:logger, :backends)
616 on_exit(fn -> Application.put_env(:logger, :backends, backends) end)
624 Pleroma.Config.TransferTask.load_and_update_env([], false)
626 assert Application.get_env(:logger, :backends) == []
630 |> put_req_header("content-type", "application/json")
631 |> post("/api/pleroma/admin/config", %{
641 assert json_response_and_validate_schema(conn, 200) == %{
644 "group" => ":logger",
645 "key" => ":backends",
649 "db" => [":backends"]
652 "need_reboot" => false
655 assert Application.get_env(:logger, :backends) == [
660 test "saving full setting if value is not keyword", %{conn: conn} do
664 value: Tesla.Adapter.Hackey
669 |> put_req_header("content-type", "application/json")
670 |> post("/api/pleroma/admin/config", %{
672 %{group: ":tesla", key: ":adapter", value: "Tesla.Adapter.Httpc"}
676 assert json_response_and_validate_schema(conn, 200) == %{
681 "value" => "Tesla.Adapter.Httpc",
685 "need_reboot" => false
689 test "update config setting & delete with fallback to default value", %{
694 ueberauth = Application.get_env(:ueberauth, Ueberauth)
695 insert(:config, key: :keyaa1)
696 insert(:config, key: :keyaa2)
706 |> put_req_header("content-type", "application/json")
707 |> post("/api/pleroma/admin/config", %{
709 %{group: ":pleroma", key: ":keyaa1", value: "another_value"},
710 %{group: ":pleroma", key: ":keyaa2", value: "another_value"}
714 assert json_response_and_validate_schema(conn, 200) == %{
717 "group" => ":pleroma",
719 "value" => "another_value",
723 "group" => ":pleroma",
725 "value" => "another_value",
729 "need_reboot" => false
732 assert Application.get_env(:pleroma, :keyaa1) == "another_value"
733 assert Application.get_env(:pleroma, :keyaa2) == "another_value"
734 assert Application.get_env(:ueberauth, Ueberauth) == config3.value
738 |> assign(:user, admin)
739 |> assign(:token, token)
740 |> put_req_header("content-type", "application/json")
741 |> post("/api/pleroma/admin/config", %{
743 %{group: ":pleroma", key: ":keyaa2", delete: true},
752 assert json_response_and_validate_schema(conn, 200) == %{
754 "need_reboot" => false
757 assert Application.get_env(:ueberauth, Ueberauth) == ueberauth
758 refute Keyword.has_key?(Application.get_all_env(:pleroma), :keyaa2)
761 test "common config example", %{conn: conn} do
764 |> put_req_header("content-type", "application/json")
765 |> post("/api/pleroma/admin/config", %{
768 "group" => ":pleroma",
769 "key" => "Pleroma.Captcha.NotReal",
771 %{"tuple" => [":enabled", false]},
772 %{"tuple" => [":method", "Pleroma.Captcha.Kocaptcha"]},
773 %{"tuple" => [":seconds_valid", 60]},
774 %{"tuple" => [":path", ""]},
775 %{"tuple" => [":key1", nil]},
776 %{"tuple" => [":partial_chain", "&:hackney_connect.partial_chain/1"]},
777 %{"tuple" => [":regex1", "~r/https:\/\/example.com/"]},
778 %{"tuple" => [":regex2", "~r/https:\/\/example.com/u"]},
779 %{"tuple" => [":regex3", "~r/https:\/\/example.com/i"]},
780 %{"tuple" => [":regex4", "~r/https:\/\/example.com/s"]},
781 %{"tuple" => [":name", "Pleroma"]}
787 assert Config.get([Pleroma.Captcha.NotReal, :name]) == "Pleroma"
789 assert json_response_and_validate_schema(conn, 200) == %{
792 "group" => ":pleroma",
793 "key" => "Pleroma.Captcha.NotReal",
795 %{"tuple" => [":enabled", false]},
796 %{"tuple" => [":method", "Pleroma.Captcha.Kocaptcha"]},
797 %{"tuple" => [":seconds_valid", 60]},
798 %{"tuple" => [":path", ""]},
799 %{"tuple" => [":key1", nil]},
800 %{"tuple" => [":partial_chain", "&:hackney_connect.partial_chain/1"]},
801 %{"tuple" => [":regex1", "~r/https:\\/\\/example.com/"]},
802 %{"tuple" => [":regex2", "~r/https:\\/\\/example.com/u"]},
803 %{"tuple" => [":regex3", "~r/https:\\/\\/example.com/i"]},
804 %{"tuple" => [":regex4", "~r/https:\\/\\/example.com/s"]},
805 %{"tuple" => [":name", "Pleroma"]}
822 "need_reboot" => false
826 test "tuples with more than two values", %{conn: conn} do
829 |> put_req_header("content-type", "application/json")
830 |> post("/api/pleroma/admin/config", %{
833 "group" => ":pleroma",
834 "key" => "Pleroma.Web.Endpoint.NotReal",
851 "Pleroma.Web.MastodonAPI.WebsocketHandler",
858 "Phoenix.Endpoint.CowboyWebSocket",
861 "Phoenix.Transports.WebSocket",
864 "Pleroma.Web.Endpoint",
865 "Pleroma.Web.UserSocket",
876 "Phoenix.Endpoint.Cowboy2Handler",
877 %{"tuple" => ["Pleroma.Web.Endpoint", []]}
894 assert json_response_and_validate_schema(conn, 200) == %{
897 "group" => ":pleroma",
898 "key" => "Pleroma.Web.Endpoint.NotReal",
915 "Pleroma.Web.MastodonAPI.WebsocketHandler",
922 "Phoenix.Endpoint.CowboyWebSocket",
925 "Phoenix.Transports.WebSocket",
928 "Pleroma.Web.Endpoint",
929 "Pleroma.Web.UserSocket",
940 "Phoenix.Endpoint.Cowboy2Handler",
941 %{"tuple" => ["Pleroma.Web.Endpoint", []]}
957 "need_reboot" => false
961 test "settings with nesting map", %{conn: conn} do
964 |> put_req_header("content-type", "application/json")
965 |> post("/api/pleroma/admin/config", %{
968 "group" => ":pleroma",
971 %{"tuple" => [":key2", "some_val"]},
976 ":max_options" => 20,
977 ":max_option_chars" => 200,
978 ":min_expiration" => 0,
979 ":max_expiration" => 31_536_000,
981 ":max_options" => 20,
982 ":max_option_chars" => 200,
983 ":min_expiration" => 0,
984 ":max_expiration" => 31_536_000
994 assert json_response_and_validate_schema(conn, 200) ==
998 "group" => ":pleroma",
1001 %{"tuple" => [":key2", "some_val"]},
1006 ":max_expiration" => 31_536_000,
1007 ":max_option_chars" => 200,
1008 ":max_options" => 20,
1009 ":min_expiration" => 0,
1011 ":max_expiration" => 31_536_000,
1012 ":max_option_chars" => 200,
1013 ":max_options" => 20,
1014 ":min_expiration" => 0
1020 "db" => [":key2", ":key3"]
1023 "need_reboot" => false
1027 test "value as map", %{conn: conn} do
1030 |> put_req_header("content-type", "application/json")
1031 |> post("/api/pleroma/admin/config", %{
1034 "group" => ":pleroma",
1036 "value" => %{"key" => "some_val"}
1041 assert json_response_and_validate_schema(conn, 200) ==
1045 "group" => ":pleroma",
1047 "value" => %{"key" => "some_val"},
1051 "need_reboot" => false
1055 test "queues key as atom", %{conn: conn} do
1058 |> put_req_header("content-type", "application/json")
1059 |> post("/api/pleroma/admin/config", %{
1065 %{"tuple" => [":federator_incoming", 50]},
1066 %{"tuple" => [":federator_outgoing", 50]},
1067 %{"tuple" => [":web_push", 50]},
1068 %{"tuple" => [":mailer", 10]},
1069 %{"tuple" => [":transmogrifier", 20]},
1070 %{"tuple" => [":scheduled_activities", 10]},
1071 %{"tuple" => [":background", 5]}
1077 assert json_response_and_validate_schema(conn, 200) == %{
1083 %{"tuple" => [":federator_incoming", 50]},
1084 %{"tuple" => [":federator_outgoing", 50]},
1085 %{"tuple" => [":web_push", 50]},
1086 %{"tuple" => [":mailer", 10]},
1087 %{"tuple" => [":transmogrifier", 20]},
1088 %{"tuple" => [":scheduled_activities", 10]},
1089 %{"tuple" => [":background", 5]}
1092 ":federator_incoming",
1093 ":federator_outgoing",
1097 ":scheduled_activities",
1102 "need_reboot" => false
1106 test "delete part of settings by atom subkeys", %{conn: conn} do
1109 value: [subkey1: "val1", subkey2: "val2", subkey3: "val3"]
1114 |> put_req_header("content-type", "application/json")
1115 |> post("/api/pleroma/admin/config", %{
1120 subkeys: [":subkey1", ":subkey3"],
1126 assert json_response_and_validate_schema(conn, 200) == %{
1129 "group" => ":pleroma",
1131 "value" => [%{"tuple" => [":subkey2", "val2"]}],
1132 "db" => [":subkey2"]
1135 "need_reboot" => false
1139 test "proxy tuple localhost", %{conn: conn} do
1142 |> put_req_header("content-type", "application/json")
1143 |> post("/api/pleroma/admin/config", %{
1149 %{"tuple" => [":proxy_url", %{"tuple" => [":socks5", "localhost", 1234]}]}
1158 "group" => ":pleroma",
1164 } = json_response_and_validate_schema(conn, 200)
1166 assert %{"tuple" => [":proxy_url", %{"tuple" => [":socks5", "localhost", 1234]}]} in value
1167 assert ":proxy_url" in db
1170 test "proxy tuple domain", %{conn: conn} do
1173 |> put_req_header("content-type", "application/json")
1174 |> post("/api/pleroma/admin/config", %{
1180 %{"tuple" => [":proxy_url", %{"tuple" => [":socks5", "domain.com", 1234]}]}
1189 "group" => ":pleroma",
1195 } = json_response_and_validate_schema(conn, 200)
1197 assert %{"tuple" => [":proxy_url", %{"tuple" => [":socks5", "domain.com", 1234]}]} in value
1198 assert ":proxy_url" in db
1201 test "proxy tuple ip", %{conn: conn} do
1204 |> put_req_header("content-type", "application/json")
1205 |> post("/api/pleroma/admin/config", %{
1211 %{"tuple" => [":proxy_url", %{"tuple" => [":socks5", "127.0.0.1", 1234]}]}
1220 "group" => ":pleroma",
1226 } = json_response_and_validate_schema(conn, 200)
1228 assert %{"tuple" => [":proxy_url", %{"tuple" => [":socks5", "127.0.0.1", 1234]}]} in value
1229 assert ":proxy_url" in db
1232 @tag capture_log: true
1233 test "doesn't set keys not in the whitelist", %{conn: conn} do
1234 clear_config(:database_config_whitelist, [
1237 {:pleroma, Pleroma.Captcha.NotReal},
1242 |> put_req_header("content-type", "application/json")
1243 |> post("/api/pleroma/admin/config", %{
1245 %{group: ":pleroma", key: ":key1", value: "value1"},
1246 %{group: ":pleroma", key: ":key2", value: "value2"},
1247 %{group: ":pleroma", key: ":key3", value: "value3"},
1248 %{group: ":pleroma", key: "Pleroma.Web.Endpoint.NotReal", value: "value4"},
1249 %{group: ":pleroma", key: "Pleroma.Captcha.NotReal", value: "value5"},
1250 %{group: ":not_real", key: ":anything", value: "value6"}
1254 assert Application.get_env(:pleroma, :key1) == "value1"
1255 assert Application.get_env(:pleroma, :key2) == "value2"
1256 assert Application.get_env(:pleroma, :key3) == nil
1257 assert Application.get_env(:pleroma, Pleroma.Web.Endpoint.NotReal) == nil
1258 assert Application.get_env(:pleroma, Pleroma.Captcha.NotReal) == "value5"
1259 assert Application.get_env(:not_real, :anything) == "value6"
1262 test "args for Pleroma.Upload.Filter.Mogrify with custom tuples", %{conn: conn} do
1263 clear_config(Pleroma.Upload.Filter.Mogrify)
1266 |> put_req_header("content-type", "application/json")
1267 |> post("/api/pleroma/admin/config", %{
1271 key: "Pleroma.Upload.Filter.Mogrify",
1273 %{"tuple" => [":args", ["auto-orient", "strip"]]}
1278 |> json_response_and_validate_schema(200) == %{
1281 "group" => ":pleroma",
1282 "key" => "Pleroma.Upload.Filter.Mogrify",
1284 %{"tuple" => [":args", ["auto-orient", "strip"]]}
1289 "need_reboot" => false
1292 assert Config.get(Pleroma.Upload.Filter.Mogrify) == [args: ["auto-orient", "strip"]]
1295 |> put_req_header("content-type", "application/json")
1296 |> post("/api/pleroma/admin/config", %{
1300 key: "Pleroma.Upload.Filter.Mogrify",
1308 "{\"implode\", \"1\"}",
1309 "{\"resize\", \"3840x1080>\"}"
1317 |> json_response(200) == %{
1320 "group" => ":pleroma",
1321 "key" => "Pleroma.Upload.Filter.Mogrify",
1329 "{\"implode\", \"1\"}",
1330 "{\"resize\", \"3840x1080>\"}"
1338 "need_reboot" => false
1341 assert Config.get(Pleroma.Upload.Filter.Mogrify) == [
1342 args: ["auto-orient", "strip", {"implode", "1"}, {"resize", "3840x1080>"}]
1347 describe "GET /api/pleroma/admin/config/descriptions" do
1348 test "structure", %{conn: conn} do
1349 admin = insert(:user, is_admin: true)
1352 assign(conn, :user, admin)
1353 |> get("/api/pleroma/admin/config/descriptions")
1355 assert [child | _others] = json_response_and_validate_schema(conn, 200)
1357 assert child["children"]
1359 assert String.starts_with?(child["group"], ":")
1360 assert child["description"]
1363 test "filters by database configuration whitelist", %{conn: conn} do
1364 clear_config(:database_config_whitelist, [
1365 {:pleroma, :instance},
1366 {:pleroma, :activitypub},
1367 {:pleroma, Pleroma.Upload},
1371 admin = insert(:user, is_admin: true)
1374 assign(conn, :user, admin)
1375 |> get("/api/pleroma/admin/config/descriptions")
1377 children = json_response_and_validate_schema(conn, 200)
1379 assert length(children) == 4
1381 assert Enum.count(children, fn c -> c["group"] == ":pleroma" end) == 3
1383 instance = Enum.find(children, fn c -> c["key"] == ":instance" end)
1384 assert instance["children"]
1386 activitypub = Enum.find(children, fn c -> c["key"] == ":activitypub" end)
1387 assert activitypub["children"]
1389 web_endpoint = Enum.find(children, fn c -> c["key"] == "Pleroma.Upload" end)
1390 assert web_endpoint["children"]
1392 esshd = Enum.find(children, fn c -> c["group"] == ":esshd" end)
1393 assert esshd["children"]