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]
157 test "POST /api/pleroma/admin/config error", %{conn: conn} do
160 |> put_req_header("content-type", "application/json")
161 |> post("/api/pleroma/admin/config", %{"configs" => []})
163 assert json_response_and_validate_schema(conn, 400) ==
164 %{"error" => "To use this endpoint you need to enable configuration from database."}
167 describe "POST /api/pleroma/admin/config" do
169 http = Application.get_env(:pleroma, :http)
172 Application.delete_env(:pleroma, :key1)
173 Application.delete_env(:pleroma, :key2)
174 Application.delete_env(:pleroma, :key3)
175 Application.delete_env(:pleroma, :key4)
176 Application.delete_env(:pleroma, :keyaa1)
177 Application.delete_env(:pleroma, :keyaa2)
178 Application.delete_env(:pleroma, Pleroma.Web.Endpoint.NotReal)
179 Application.delete_env(:pleroma, Pleroma.Captcha.NotReal)
180 Application.put_env(:pleroma, :http, http)
181 Application.put_env(:tesla, :adapter, Tesla.Mock)
182 Restarter.Pleroma.refresh()
186 setup do: clear_config(:configurable_from_database, true)
188 @tag capture_log: true
189 test "create new config setting in db", %{conn: conn} do
190 ueberauth = Application.get_env(:ueberauth, Ueberauth)
191 on_exit(fn -> Application.put_env(:ueberauth, Ueberauth, ueberauth) end)
195 |> put_req_header("content-type", "application/json")
196 |> post("/api/pleroma/admin/config", %{
198 %{group: ":pleroma", key: ":key1", value: "value1"},
202 value: [%{"tuple" => [":consumer_secret", "aaaa"]}]
208 ":nested_1" => "nested_value1",
210 %{":nested_22" => "nested_value222"},
211 %{":nested_33" => %{":nested_44" => "nested_444"}}
219 %{"nested_3" => ":nested_3", "nested_33" => "nested_33"},
220 %{"nested_4" => true}
226 value: %{":nested_5" => ":upload", "endpoint" => "https://example.com"}
231 value: %{"tuple" => ["string", "Pleroma.Captcha.NotReal", []]}
236 assert json_response_and_validate_schema(conn, 200) == %{
239 "group" => ":pleroma",
245 "group" => ":ueberauth",
246 "key" => "Ueberauth",
247 "value" => [%{"tuple" => [":consumer_secret", "aaaa"]}],
248 "db" => [":consumer_secret"]
251 "group" => ":pleroma",
254 ":nested_1" => "nested_value1",
256 %{":nested_22" => "nested_value222"},
257 %{":nested_33" => %{":nested_44" => "nested_444"}}
263 "group" => ":pleroma",
266 %{"nested_3" => ":nested_3", "nested_33" => "nested_33"},
267 %{"nested_4" => true}
272 "group" => ":pleroma",
274 "value" => %{"endpoint" => "https://example.com", ":nested_5" => ":upload"},
280 "value" => %{"tuple" => ["string", "Pleroma.Captcha.NotReal", []]},
284 "need_reboot" => false
287 assert Application.get_env(:pleroma, :key1) == "value1"
289 assert Application.get_env(:pleroma, :key2) == %{
290 nested_1: "nested_value1",
292 %{nested_22: "nested_value222"},
293 %{nested_33: %{nested_44: "nested_444"}}
297 assert Application.get_env(:pleroma, :key3) == [
298 %{"nested_3" => :nested_3, "nested_33" => "nested_33"},
299 %{"nested_4" => true}
302 assert Application.get_env(:pleroma, :key4) == %{
303 "endpoint" => "https://example.com",
307 assert Application.get_env(:idna, :key5) == {"string", Pleroma.Captcha.NotReal, []}
310 test "save configs setting without explicit key", %{conn: conn} do
311 level = Application.get_env(:quack, :level)
312 meta = Application.get_env(:quack, :meta)
313 webhook_url = Application.get_env(:quack, :webhook_url)
316 Application.put_env(:quack, :level, level)
317 Application.put_env(:quack, :meta, meta)
318 Application.put_env(:quack, :webhook_url, webhook_url)
323 |> put_req_header("content-type", "application/json")
324 |> post("/api/pleroma/admin/config", %{
339 value: "https://hooks.slack.com/services/KEY"
344 assert json_response_and_validate_schema(conn, 200) == %{
355 "value" => [":none"],
360 "key" => ":webhook_url",
361 "value" => "https://hooks.slack.com/services/KEY",
362 "db" => [":webhook_url"]
365 "need_reboot" => false
368 assert Application.get_env(:quack, :level) == :info
369 assert Application.get_env(:quack, :meta) == [:none]
370 assert Application.get_env(:quack, :webhook_url) == "https://hooks.slack.com/services/KEY"
373 test "saving config with partial update", %{conn: conn} do
374 insert(:config, key: ":key1", value: :erlang.term_to_binary(key1: 1, key2: 2))
378 |> put_req_header("content-type", "application/json")
379 |> post("/api/pleroma/admin/config", %{
381 %{group: ":pleroma", key: ":key1", value: [%{"tuple" => [":key3", 3]}]}
385 assert json_response_and_validate_schema(conn, 200) == %{
388 "group" => ":pleroma",
391 %{"tuple" => [":key1", 1]},
392 %{"tuple" => [":key2", 2]},
393 %{"tuple" => [":key3", 3]}
395 "db" => [":key1", ":key2", ":key3"]
398 "need_reboot" => false
402 test "saving config which need pleroma reboot", %{conn: conn} do
403 chat = Config.get(:chat)
404 on_exit(fn -> Config.put(:chat, chat) end)
407 |> put_req_header("content-type", "application/json")
409 "/api/pleroma/admin/config",
412 %{group: ":pleroma", key: ":chat", value: [%{"tuple" => [":enabled", true]}]}
416 |> json_response_and_validate_schema(200) == %{
419 "db" => [":enabled"],
420 "group" => ":pleroma",
422 "value" => [%{"tuple" => [":enabled", true]}]
425 "need_reboot" => true
430 |> get("/api/pleroma/admin/config")
431 |> json_response_and_validate_schema(200)
433 assert configs["need_reboot"]
436 assert conn |> get("/api/pleroma/admin/restart") |> json_response(200) ==
438 end) =~ "pleroma restarted"
442 |> get("/api/pleroma/admin/config")
443 |> json_response_and_validate_schema(200)
445 assert configs["need_reboot"] == false
448 test "update setting which need reboot, don't change reboot flag until reboot", %{conn: conn} do
449 chat = Config.get(:chat)
450 on_exit(fn -> Config.put(:chat, chat) end)
453 |> put_req_header("content-type", "application/json")
455 "/api/pleroma/admin/config",
458 %{group: ":pleroma", key: ":chat", value: [%{"tuple" => [":enabled", true]}]}
462 |> json_response_and_validate_schema(200) == %{
465 "db" => [":enabled"],
466 "group" => ":pleroma",
468 "value" => [%{"tuple" => [":enabled", true]}]
471 "need_reboot" => true
475 |> put_req_header("content-type", "application/json")
476 |> post("/api/pleroma/admin/config", %{
478 %{group: ":pleroma", key: ":key1", value: [%{"tuple" => [":key3", 3]}]}
481 |> json_response_and_validate_schema(200) == %{
484 "group" => ":pleroma",
487 %{"tuple" => [":key3", 3]}
492 "need_reboot" => true
496 assert conn |> get("/api/pleroma/admin/restart") |> json_response(200) ==
498 end) =~ "pleroma restarted"
502 |> get("/api/pleroma/admin/config")
503 |> json_response_and_validate_schema(200)
505 assert configs["need_reboot"] == false
508 test "saving config with nested merge", %{conn: conn} do
509 insert(:config, key: :key1, value: [key1: 1, key2: [k1: 1, k2: 2]])
513 |> put_req_header("content-type", "application/json")
514 |> post("/api/pleroma/admin/config", %{
520 %{"tuple" => [":key3", 3]},
525 %{"tuple" => [":k2", 1]},
526 %{"tuple" => [":k3", 3]}
535 assert json_response_and_validate_schema(conn, 200) == %{
538 "group" => ":pleroma",
541 %{"tuple" => [":key1", 1]},
542 %{"tuple" => [":key3", 3]},
547 %{"tuple" => [":k1", 1]},
548 %{"tuple" => [":k2", 1]},
549 %{"tuple" => [":k3", 3]}
554 "db" => [":key1", ":key3", ":key2"]
557 "need_reboot" => false
561 test "saving special atoms", %{conn: conn} do
564 |> put_req_header("content-type", "application/json")
565 |> post("/api/pleroma/admin/config", %{
568 "group" => ":pleroma",
574 [%{"tuple" => [":versions", [":tlsv1", ":tlsv1.1", ":tlsv1.2"]]}]
582 assert json_response_and_validate_schema(conn, 200) == %{
585 "group" => ":pleroma",
591 [%{"tuple" => [":versions", [":tlsv1", ":tlsv1.1", ":tlsv1.2"]]}]
595 "db" => [":ssl_options"]
598 "need_reboot" => false
601 assert Application.get_env(:pleroma, :key1) == [
602 ssl_options: [versions: [:tlsv1, :"tlsv1.1", :"tlsv1.2"]]
606 test "saving full setting if value is in full_key_update list", %{conn: conn} do
607 backends = Application.get_env(:logger, :backends)
608 on_exit(fn -> Application.put_env(:logger, :backends, backends) end)
616 Pleroma.Config.TransferTask.load_and_update_env([], false)
618 assert Application.get_env(:logger, :backends) == []
622 |> put_req_header("content-type", "application/json")
623 |> post("/api/pleroma/admin/config", %{
633 assert json_response_and_validate_schema(conn, 200) == %{
636 "group" => ":logger",
637 "key" => ":backends",
641 "db" => [":backends"]
644 "need_reboot" => false
647 assert Application.get_env(:logger, :backends) == [
652 test "saving full setting if value is not keyword", %{conn: conn} do
656 value: Tesla.Adapter.Hackey
661 |> put_req_header("content-type", "application/json")
662 |> post("/api/pleroma/admin/config", %{
664 %{group: ":tesla", key: ":adapter", value: "Tesla.Adapter.Httpc"}
668 assert json_response_and_validate_schema(conn, 200) == %{
673 "value" => "Tesla.Adapter.Httpc",
677 "need_reboot" => false
681 test "update config setting & delete with fallback to default value", %{
686 ueberauth = Application.get_env(:ueberauth, Ueberauth)
687 insert(:config, key: :keyaa1)
688 insert(:config, key: :keyaa2)
698 |> put_req_header("content-type", "application/json")
699 |> post("/api/pleroma/admin/config", %{
701 %{group: ":pleroma", key: ":keyaa1", value: "another_value"},
702 %{group: ":pleroma", key: ":keyaa2", value: "another_value"}
706 assert json_response_and_validate_schema(conn, 200) == %{
709 "group" => ":pleroma",
711 "value" => "another_value",
715 "group" => ":pleroma",
717 "value" => "another_value",
721 "need_reboot" => false
724 assert Application.get_env(:pleroma, :keyaa1) == "another_value"
725 assert Application.get_env(:pleroma, :keyaa2) == "another_value"
726 assert Application.get_env(:ueberauth, Ueberauth) == config3.value
730 |> assign(:user, admin)
731 |> assign(:token, token)
732 |> put_req_header("content-type", "application/json")
733 |> post("/api/pleroma/admin/config", %{
735 %{group: ":pleroma", key: ":keyaa2", delete: true},
744 assert json_response_and_validate_schema(conn, 200) == %{
746 "need_reboot" => false
749 assert Application.get_env(:ueberauth, Ueberauth) == ueberauth
750 refute Keyword.has_key?(Application.get_all_env(:pleroma), :keyaa2)
753 test "common config example", %{conn: conn} do
756 |> put_req_header("content-type", "application/json")
757 |> post("/api/pleroma/admin/config", %{
760 "group" => ":pleroma",
761 "key" => "Pleroma.Captcha.NotReal",
763 %{"tuple" => [":enabled", false]},
764 %{"tuple" => [":method", "Pleroma.Captcha.Kocaptcha"]},
765 %{"tuple" => [":seconds_valid", 60]},
766 %{"tuple" => [":path", ""]},
767 %{"tuple" => [":key1", nil]},
768 %{"tuple" => [":partial_chain", "&:hackney_connect.partial_chain/1"]},
769 %{"tuple" => [":regex1", "~r/https:\/\/example.com/"]},
770 %{"tuple" => [":regex2", "~r/https:\/\/example.com/u"]},
771 %{"tuple" => [":regex3", "~r/https:\/\/example.com/i"]},
772 %{"tuple" => [":regex4", "~r/https:\/\/example.com/s"]},
773 %{"tuple" => [":name", "Pleroma"]}
779 assert Config.get([Pleroma.Captcha.NotReal, :name]) == "Pleroma"
781 assert json_response_and_validate_schema(conn, 200) == %{
784 "group" => ":pleroma",
785 "key" => "Pleroma.Captcha.NotReal",
787 %{"tuple" => [":enabled", false]},
788 %{"tuple" => [":method", "Pleroma.Captcha.Kocaptcha"]},
789 %{"tuple" => [":seconds_valid", 60]},
790 %{"tuple" => [":path", ""]},
791 %{"tuple" => [":key1", nil]},
792 %{"tuple" => [":partial_chain", "&:hackney_connect.partial_chain/1"]},
793 %{"tuple" => [":regex1", "~r/https:\\/\\/example.com/"]},
794 %{"tuple" => [":regex2", "~r/https:\\/\\/example.com/u"]},
795 %{"tuple" => [":regex3", "~r/https:\\/\\/example.com/i"]},
796 %{"tuple" => [":regex4", "~r/https:\\/\\/example.com/s"]},
797 %{"tuple" => [":name", "Pleroma"]}
814 "need_reboot" => false
818 test "tuples with more than two values", %{conn: conn} do
821 |> put_req_header("content-type", "application/json")
822 |> post("/api/pleroma/admin/config", %{
825 "group" => ":pleroma",
826 "key" => "Pleroma.Web.Endpoint.NotReal",
843 "Pleroma.Web.MastodonAPI.WebsocketHandler",
850 "Phoenix.Endpoint.CowboyWebSocket",
853 "Phoenix.Transports.WebSocket",
856 "Pleroma.Web.Endpoint",
857 "Pleroma.Web.UserSocket",
868 "Phoenix.Endpoint.Cowboy2Handler",
869 %{"tuple" => ["Pleroma.Web.Endpoint", []]}
886 assert json_response_and_validate_schema(conn, 200) == %{
889 "group" => ":pleroma",
890 "key" => "Pleroma.Web.Endpoint.NotReal",
907 "Pleroma.Web.MastodonAPI.WebsocketHandler",
914 "Phoenix.Endpoint.CowboyWebSocket",
917 "Phoenix.Transports.WebSocket",
920 "Pleroma.Web.Endpoint",
921 "Pleroma.Web.UserSocket",
932 "Phoenix.Endpoint.Cowboy2Handler",
933 %{"tuple" => ["Pleroma.Web.Endpoint", []]}
949 "need_reboot" => false
953 test "settings with nesting map", %{conn: conn} do
956 |> put_req_header("content-type", "application/json")
957 |> post("/api/pleroma/admin/config", %{
960 "group" => ":pleroma",
963 %{"tuple" => [":key2", "some_val"]},
968 ":max_options" => 20,
969 ":max_option_chars" => 200,
970 ":min_expiration" => 0,
971 ":max_expiration" => 31_536_000,
973 ":max_options" => 20,
974 ":max_option_chars" => 200,
975 ":min_expiration" => 0,
976 ":max_expiration" => 31_536_000
986 assert json_response_and_validate_schema(conn, 200) ==
990 "group" => ":pleroma",
993 %{"tuple" => [":key2", "some_val"]},
998 ":max_expiration" => 31_536_000,
999 ":max_option_chars" => 200,
1000 ":max_options" => 20,
1001 ":min_expiration" => 0,
1003 ":max_expiration" => 31_536_000,
1004 ":max_option_chars" => 200,
1005 ":max_options" => 20,
1006 ":min_expiration" => 0
1012 "db" => [":key2", ":key3"]
1015 "need_reboot" => false
1019 test "value as map", %{conn: conn} do
1022 |> put_req_header("content-type", "application/json")
1023 |> post("/api/pleroma/admin/config", %{
1026 "group" => ":pleroma",
1028 "value" => %{"key" => "some_val"}
1033 assert json_response_and_validate_schema(conn, 200) ==
1037 "group" => ":pleroma",
1039 "value" => %{"key" => "some_val"},
1043 "need_reboot" => false
1047 test "queues key as atom", %{conn: conn} do
1050 |> put_req_header("content-type", "application/json")
1051 |> post("/api/pleroma/admin/config", %{
1057 %{"tuple" => [":federator_incoming", 50]},
1058 %{"tuple" => [":federator_outgoing", 50]},
1059 %{"tuple" => [":web_push", 50]},
1060 %{"tuple" => [":mailer", 10]},
1061 %{"tuple" => [":transmogrifier", 20]},
1062 %{"tuple" => [":scheduled_activities", 10]},
1063 %{"tuple" => [":background", 5]}
1069 assert json_response_and_validate_schema(conn, 200) == %{
1075 %{"tuple" => [":federator_incoming", 50]},
1076 %{"tuple" => [":federator_outgoing", 50]},
1077 %{"tuple" => [":web_push", 50]},
1078 %{"tuple" => [":mailer", 10]},
1079 %{"tuple" => [":transmogrifier", 20]},
1080 %{"tuple" => [":scheduled_activities", 10]},
1081 %{"tuple" => [":background", 5]}
1084 ":federator_incoming",
1085 ":federator_outgoing",
1089 ":scheduled_activities",
1094 "need_reboot" => false
1098 test "delete part of settings by atom subkeys", %{conn: conn} do
1101 value: [subkey1: "val1", subkey2: "val2", subkey3: "val3"]
1106 |> put_req_header("content-type", "application/json")
1107 |> post("/api/pleroma/admin/config", %{
1112 subkeys: [":subkey1", ":subkey3"],
1118 assert json_response_and_validate_schema(conn, 200) == %{
1121 "group" => ":pleroma",
1123 "value" => [%{"tuple" => [":subkey2", "val2"]}],
1124 "db" => [":subkey2"]
1127 "need_reboot" => false
1131 test "proxy tuple localhost", %{conn: conn} do
1134 |> put_req_header("content-type", "application/json")
1135 |> post("/api/pleroma/admin/config", %{
1141 %{"tuple" => [":proxy_url", %{"tuple" => [":socks5", "localhost", 1234]}]}
1150 "group" => ":pleroma",
1156 } = json_response_and_validate_schema(conn, 200)
1158 assert %{"tuple" => [":proxy_url", %{"tuple" => [":socks5", "localhost", 1234]}]} in value
1159 assert ":proxy_url" in db
1162 test "proxy tuple domain", %{conn: conn} do
1165 |> put_req_header("content-type", "application/json")
1166 |> post("/api/pleroma/admin/config", %{
1172 %{"tuple" => [":proxy_url", %{"tuple" => [":socks5", "domain.com", 1234]}]}
1181 "group" => ":pleroma",
1187 } = json_response_and_validate_schema(conn, 200)
1189 assert %{"tuple" => [":proxy_url", %{"tuple" => [":socks5", "domain.com", 1234]}]} in value
1190 assert ":proxy_url" in db
1193 test "proxy tuple ip", %{conn: conn} do
1196 |> put_req_header("content-type", "application/json")
1197 |> post("/api/pleroma/admin/config", %{
1203 %{"tuple" => [":proxy_url", %{"tuple" => [":socks5", "127.0.0.1", 1234]}]}
1212 "group" => ":pleroma",
1218 } = json_response_and_validate_schema(conn, 200)
1220 assert %{"tuple" => [":proxy_url", %{"tuple" => [":socks5", "127.0.0.1", 1234]}]} in value
1221 assert ":proxy_url" in db
1224 @tag capture_log: true
1225 test "doesn't set keys not in the whitelist", %{conn: conn} do
1226 clear_config(:database_config_whitelist, [
1229 {:pleroma, Pleroma.Captcha.NotReal},
1234 |> put_req_header("content-type", "application/json")
1235 |> post("/api/pleroma/admin/config", %{
1237 %{group: ":pleroma", key: ":key1", value: "value1"},
1238 %{group: ":pleroma", key: ":key2", value: "value2"},
1239 %{group: ":pleroma", key: ":key3", value: "value3"},
1240 %{group: ":pleroma", key: "Pleroma.Web.Endpoint.NotReal", value: "value4"},
1241 %{group: ":pleroma", key: "Pleroma.Captcha.NotReal", value: "value5"},
1242 %{group: ":not_real", key: ":anything", value: "value6"}
1246 assert Application.get_env(:pleroma, :key1) == "value1"
1247 assert Application.get_env(:pleroma, :key2) == "value2"
1248 assert Application.get_env(:pleroma, :key3) == nil
1249 assert Application.get_env(:pleroma, Pleroma.Web.Endpoint.NotReal) == nil
1250 assert Application.get_env(:pleroma, Pleroma.Captcha.NotReal) == "value5"
1251 assert Application.get_env(:not_real, :anything) == "value6"
1254 test "args for Pleroma.Upload.Filter.Mogrify with custom tuples", %{conn: conn} do
1255 clear_config(Pleroma.Upload.Filter.Mogrify)
1258 |> put_req_header("content-type", "application/json")
1259 |> post("/api/pleroma/admin/config", %{
1263 key: "Pleroma.Upload.Filter.Mogrify",
1265 %{"tuple" => [":args", ["auto-orient", "strip"]]}
1270 |> json_response_and_validate_schema(200) == %{
1273 "group" => ":pleroma",
1274 "key" => "Pleroma.Upload.Filter.Mogrify",
1276 %{"tuple" => [":args", ["auto-orient", "strip"]]}
1281 "need_reboot" => false
1284 assert Config.get(Pleroma.Upload.Filter.Mogrify) == [args: ["auto-orient", "strip"]]
1287 |> put_req_header("content-type", "application/json")
1288 |> post("/api/pleroma/admin/config", %{
1292 key: "Pleroma.Upload.Filter.Mogrify",
1300 "{\"implode\", \"1\"}",
1301 "{\"resize\", \"3840x1080>\"}"
1309 |> json_response(200) == %{
1312 "group" => ":pleroma",
1313 "key" => "Pleroma.Upload.Filter.Mogrify",
1321 "{\"implode\", \"1\"}",
1322 "{\"resize\", \"3840x1080>\"}"
1330 "need_reboot" => false
1333 assert Config.get(Pleroma.Upload.Filter.Mogrify) == [
1334 args: ["auto-orient", "strip", {"implode", "1"}, {"resize", "3840x1080>"}]
1339 describe "GET /api/pleroma/admin/config/descriptions" do
1340 test "structure", %{conn: conn} do
1341 admin = insert(:user, is_admin: true)
1344 assign(conn, :user, admin)
1345 |> get("/api/pleroma/admin/config/descriptions")
1347 assert [child | _others] = json_response_and_validate_schema(conn, 200)
1349 assert child["children"]
1351 assert String.starts_with?(child["group"], ":")
1352 assert child["description"]
1355 test "filters by database configuration whitelist", %{conn: conn} do
1356 clear_config(:database_config_whitelist, [
1357 {:pleroma, :instance},
1358 {:pleroma, :activitypub},
1359 {:pleroma, Pleroma.Upload},
1363 admin = insert(:user, is_admin: true)
1366 assign(conn, :user, admin)
1367 |> get("/api/pleroma/admin/config/descriptions")
1369 children = json_response_and_validate_schema(conn, 200)
1371 assert length(children) == 4
1373 assert Enum.count(children, fn c -> c["group"] == ":pleroma" end) == 3
1375 instance = Enum.find(children, fn c -> c["key"] == ":instance" end)
1376 assert instance["children"]
1378 activitypub = Enum.find(children, fn c -> c["key"] == ":activitypub" end)
1379 assert activitypub["children"]
1381 web_endpoint = Enum.find(children, fn c -> c["key"] == "Pleroma.Upload" end)
1382 assert web_endpoint["children"]
1384 esshd = Enum.find(children, fn c -> c["group"] == ":esshd" end)
1385 assert esshd["children"]