1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 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
11 alias Pleroma.ConfigDB
14 admin = insert(:user, is_admin: true)
15 token = insert(:oauth_admin_token, user: admin)
19 |> assign(:user, admin)
20 |> assign(:token, token)
22 {:ok, %{admin: admin, token: token, conn: conn}}
25 describe "GET /api/pleroma/admin/config" do
26 setup do: clear_config(:configurable_from_database, true)
28 test "when configuration from database is off", %{conn: conn} do
29 clear_config(:configurable_from_database, false)
30 conn = get(conn, "/api/pleroma/admin/config")
32 assert json_response_and_validate_schema(conn, 400) ==
34 "error" => "You must enable configurable_from_database in your config file."
38 test "with settings only in db", %{conn: conn} do
39 config1 = insert(:config)
40 config2 = insert(:config)
42 conn = get(conn, "/api/pleroma/admin/config?only_db=true")
47 "group" => ":pleroma",
52 "group" => ":pleroma",
57 } = json_response_and_validate_schema(conn, 200)
59 assert key1 == inspect(config1.key)
60 assert key2 == inspect(config2.key)
63 test "db is added to settings that are in db", %{conn: conn} do
64 _config = insert(:config, key: ":instance", value: [name: "Some name"])
66 %{"configs" => configs} =
68 |> get("/api/pleroma/admin/config")
69 |> json_response_and_validate_schema(200)
72 Enum.filter(configs, fn %{"group" => group, "key" => key} ->
73 group == ":pleroma" and key == ":instance"
76 assert instance_config["db"] == [":name"]
79 test "merged default setting with db settings", %{conn: conn} do
80 config1 = insert(:config)
81 config2 = insert(:config)
85 value: [k1: :v1, k2: :v2]
88 %{"configs" => configs} =
90 |> get("/api/pleroma/admin/config")
91 |> json_response_and_validate_schema(200)
93 assert length(configs) > 3
95 saved_configs = [config1, config2, config3]
96 keys = Enum.map(saved_configs, &inspect(&1.key))
99 Enum.filter(configs, fn %{"group" => group, "key" => key} ->
100 group == ":pleroma" and key in keys
103 assert length(received_configs) == 3
108 |> ConfigDB.to_json_types()
110 keys = Enum.map(saved_configs -- [config3], &inspect(&1.key))
112 values = Enum.map(saved_configs, &ConfigDB.to_json_types(&1.value))
114 mapset_keys = MapSet.new(keys ++ db_keys)
116 Enum.each(received_configs, fn %{"value" => value, "db" => db} ->
118 assert MapSet.subset?(db, mapset_keys)
120 assert value in values
124 test "subkeys with full update right merge", %{conn: conn} do
127 value: [groups: [a: 1, b: 2], key: [a: 1]]
132 value: [mascots: [a: 1, b: 2], key: [a: 1]]
135 %{"configs" => configs} =
137 |> get("/api/pleroma/admin/config")
138 |> json_response_and_validate_schema(200)
141 Enum.filter(configs, fn %{"group" => group, "key" => key} ->
142 group == ":pleroma" and key in [":emoji", ":assets"]
145 emoji = Enum.find(vals, fn %{"key" => key} -> key == ":emoji" end)
146 assets = Enum.find(vals, fn %{"key" => key} -> key == ":assets" end)
148 emoji_val = ConfigDB.to_elixir_types(emoji["value"])
149 assets_val = ConfigDB.to_elixir_types(assets["value"])
151 assert emoji_val[:groups] == [a: 1, b: 2]
152 assert assets_val[:mascots] == [a: 1, b: 2]
155 test "with valid `admin_token` query parameter, skips OAuth scopes check" do
156 clear_config([:admin_token], "password123")
159 |> get("/api/pleroma/admin/config?admin_token=password123")
160 |> json_response_and_validate_schema(200)
164 test "POST /api/pleroma/admin/config with configdb disabled", %{conn: conn} do
165 clear_config(:configurable_from_database, false)
169 |> put_req_header("content-type", "application/json")
170 |> post("/api/pleroma/admin/config", %{"configs" => []})
172 assert json_response_and_validate_schema(conn, 400) ==
173 %{"error" => "You must enable configurable_from_database in your config file."}
176 describe "POST /api/pleroma/admin/config" do
178 http = Application.get_env(:pleroma, :http)
181 Application.delete_env(:pleroma, :key1)
182 Application.delete_env(:pleroma, :key2)
183 Application.delete_env(:pleroma, :key3)
184 Application.delete_env(:pleroma, :key4)
185 Application.delete_env(:pleroma, :keyaa1)
186 Application.delete_env(:pleroma, :keyaa2)
187 Application.delete_env(:pleroma, Pleroma.Web.Endpoint.NotReal)
188 Application.delete_env(:pleroma, Pleroma.Captcha.NotReal)
189 Application.put_env(:pleroma, :http, http)
190 Application.put_env(:tesla, :adapter, Tesla.Mock)
191 Restarter.Pleroma.refresh()
195 setup do: clear_config(:configurable_from_database, true)
197 @tag capture_log: true
198 test "create new config setting in db", %{conn: conn} do
199 ueberauth = Application.get_env(:ueberauth, Ueberauth)
200 on_exit(fn -> Application.put_env(:ueberauth, Ueberauth, ueberauth) end)
204 |> put_req_header("content-type", "application/json")
205 |> post("/api/pleroma/admin/config", %{
207 %{group: ":pleroma", key: ":key1", value: "value1"},
211 value: [%{"tuple" => [":consumer_secret", "aaaa"]}]
217 ":nested_1" => "nested_value1",
219 %{":nested_22" => "nested_value222"},
220 %{":nested_33" => %{":nested_44" => "nested_444"}}
228 %{"nested_3" => ":nested_3", "nested_33" => "nested_33"},
229 %{"nested_4" => true}
235 value: %{":nested_5" => ":upload", "endpoint" => "https://example.com"}
240 value: %{"tuple" => ["string", "Pleroma.Captcha.NotReal", []]}
245 assert json_response_and_validate_schema(conn, 200) == %{
248 "group" => ":pleroma",
254 "group" => ":ueberauth",
255 "key" => "Ueberauth",
256 "value" => [%{"tuple" => [":consumer_secret", "aaaa"]}],
257 "db" => [":consumer_secret"]
260 "group" => ":pleroma",
263 ":nested_1" => "nested_value1",
265 %{":nested_22" => "nested_value222"},
266 %{":nested_33" => %{":nested_44" => "nested_444"}}
272 "group" => ":pleroma",
275 %{"nested_3" => ":nested_3", "nested_33" => "nested_33"},
276 %{"nested_4" => true}
281 "group" => ":pleroma",
283 "value" => %{"endpoint" => "https://example.com", ":nested_5" => ":upload"},
289 "value" => %{"tuple" => ["string", "Pleroma.Captcha.NotReal", []]},
293 "need_reboot" => false
296 assert Application.get_env(:pleroma, :key1) == "value1"
298 assert Application.get_env(:pleroma, :key2) == %{
299 nested_1: "nested_value1",
301 %{nested_22: "nested_value222"},
302 %{nested_33: %{nested_44: "nested_444"}}
306 assert Application.get_env(:pleroma, :key3) == [
307 %{"nested_3" => :nested_3, "nested_33" => "nested_33"},
308 %{"nested_4" => true}
311 assert Application.get_env(:pleroma, :key4) == %{
312 "endpoint" => "https://example.com",
316 assert Application.get_env(:idna, :key5) == {"string", Pleroma.Captcha.NotReal, []}
319 @tag capture_log: true
320 test "save configs setting without explicit key", %{conn: conn} do
321 adapter = Application.get_env(:http, :adapter)
322 send_user_agent = Application.get_env(:http, :send_user_agent)
323 user_agent = Application.get_env(:http, :user_agent)
326 Application.put_env(:http, :adapter, adapter)
327 Application.put_env(:http, :send_user_agent, send_user_agent)
328 Application.put_env(:http, :user_agent, user_agent)
333 |> put_req_header("content-type", "application/json")
334 |> post("/api/pleroma/admin/config", %{
343 key: ":send_user_agent",
354 assert json_response_and_validate_schema(conn, 200) == %{
359 "value" => [":someval"],
364 "key" => ":send_user_agent",
366 "db" => [":send_user_agent"]
370 "key" => ":user_agent",
371 "value" => [":default"],
372 "db" => [":user_agent"]
375 "need_reboot" => false
378 assert Application.get_env(:http, :adapter) == [:someval]
379 assert Application.get_env(:http, :send_user_agent) == true
380 assert Application.get_env(:http, :user_agent) == [:default]
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 clear_config([:shout, :enabled], true)
416 |> put_req_header("content-type", "application/json")
418 "/api/pleroma/admin/config",
421 %{group: ":pleroma", key: ":shout", value: [%{"tuple" => [":enabled", true]}]}
425 |> json_response_and_validate_schema(200) == %{
428 "db" => [":enabled"],
429 "group" => ":pleroma",
431 "value" => [%{"tuple" => [":enabled", true]}]
434 "need_reboot" => true
439 |> get("/api/pleroma/admin/config")
440 |> json_response_and_validate_schema(200)
442 assert configs["need_reboot"]
445 assert conn |> get("/api/pleroma/admin/restart") |> json_response(200) ==
447 end) =~ "pleroma restarted"
451 |> get("/api/pleroma/admin/config")
452 |> json_response_and_validate_schema(200)
454 assert configs["need_reboot"] == false
457 test "update setting which need reboot, don't change reboot flag until reboot", %{conn: conn} do
458 clear_config([:shout, :enabled], true)
461 |> put_req_header("content-type", "application/json")
463 "/api/pleroma/admin/config",
466 %{group: ":pleroma", key: ":shout", 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 "Plug.Cowboy.Handler",
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 "Plug.Cowboy.Handler",
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>"}]
1346 test "enables the welcome messages", %{conn: conn} do
1347 clear_config([:welcome])
1350 "group" => ":pleroma",
1351 "key" => ":welcome",
1357 %{"tuple" => [":enabled", true]},
1358 %{"tuple" => [":message", "Welcome to Pleroma!"]},
1359 %{"tuple" => [":sender_nickname", "pleroma"]}
1367 %{"tuple" => [":enabled", true]},
1368 %{"tuple" => [":message", "Welcome to Pleroma!"]},
1369 %{"tuple" => [":sender_nickname", "pleroma"]}
1377 %{"tuple" => [":enabled", true]},
1378 %{"tuple" => [":sender", %{"tuple" => ["pleroma@dev.dev", "Pleroma"]}]},
1379 %{"tuple" => [":subject", "Welcome to <%= instance_name %>!"]},
1380 %{"tuple" => [":html", "Welcome to <%= instance_name %>!"]},
1381 %{"tuple" => [":text", "Welcome to <%= instance_name %>!"]}
1388 refute Pleroma.User.WelcomeEmail.enabled?()
1389 refute Pleroma.User.WelcomeMessage.enabled?()
1390 refute Pleroma.User.WelcomeChatMessage.enabled?()
1394 |> put_req_header("content-type", "application/json")
1395 |> post("/api/pleroma/admin/config", %{"configs" => [params]})
1396 |> json_response_and_validate_schema(200)
1398 assert Pleroma.User.WelcomeEmail.enabled?()
1399 assert Pleroma.User.WelcomeMessage.enabled?()
1400 assert Pleroma.User.WelcomeChatMessage.enabled?()
1405 "db" => [":direct_message", ":chat_message", ":email"],
1406 "group" => ":pleroma",
1407 "key" => ":welcome",
1408 "value" => params["value"]
1411 "need_reboot" => false
1415 test "custom instance thumbnail", %{conn: conn} do
1416 clear_config([:instance])
1419 "group" => ":pleroma",
1420 "key" => ":instance",
1424 ":instance_thumbnail",
1425 "https://example.com/media/new_thumbnail.jpg"
1432 |> put_req_header("content-type", "application/json")
1433 |> post("/api/pleroma/admin/config", %{"configs" => [params]})
1434 |> json_response_and_validate_schema(200) ==
1438 "db" => [":instance_thumbnail"],
1439 "group" => ":pleroma",
1440 "key" => ":instance",
1441 "value" => params["value"]
1444 "need_reboot" => false
1448 |> get("/api/v1/instance")
1449 |> json_response_and_validate_schema(200)
1450 |> Map.take(["thumbnail"]) ==
1451 %{"thumbnail" => "https://example.com/media/new_thumbnail.jpg"}
1454 test "Concurrent Limiter", %{conn: conn} do
1455 clear_config([ConcurrentLimiter])
1458 "group" => ":pleroma",
1459 "key" => "ConcurrentLimiter",
1463 "Pleroma.Web.RichMedia.Helpers",
1465 %{"tuple" => [":max_running", 6]},
1466 %{"tuple" => [":max_waiting", 6]}
1472 "Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicy",
1474 %{"tuple" => [":max_running", 7]},
1475 %{"tuple" => [":max_waiting", 7]}
1483 |> put_req_header("content-type", "application/json")
1484 |> post("/api/pleroma/admin/config", %{"configs" => [params]})
1485 |> json_response_and_validate_schema(200)
1489 describe "GET /api/pleroma/admin/config/descriptions" do
1490 test "structure", %{conn: conn} do
1491 conn = get(conn, "/api/pleroma/admin/config/descriptions")
1493 assert [child | _others] = json_response_and_validate_schema(conn, 200)
1495 assert child["children"]
1497 assert String.starts_with?(child["group"], ":")
1498 assert child["description"]
1501 test "filters by database configuration whitelist", %{conn: conn} do
1502 clear_config(:database_config_whitelist, [
1503 {:pleroma, :instance},
1504 {:pleroma, :activitypub},
1505 {:pleroma, Pleroma.Upload}
1508 conn = get(conn, "/api/pleroma/admin/config/descriptions")
1510 children = json_response_and_validate_schema(conn, 200)
1512 assert length(children) == 3
1514 assert Enum.count(children, fn c -> c["group"] == ":pleroma" end) == 3
1516 instance = Enum.find(children, fn c -> c["key"] == ":instance" end)
1517 assert instance["children"]
1519 activitypub = Enum.find(children, fn c -> c["key"] == ":activitypub" end)
1520 assert activitypub["children"]
1522 web_endpoint = Enum.find(children, fn c -> c["key"] == "Pleroma.Upload" end)
1523 assert web_endpoint["children"]