1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 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 test "save configs setting without explicit key", %{conn: conn} do
320 level = Application.get_env(:quack, :level)
321 meta = Application.get_env(:quack, :meta)
322 webhook_url = Application.get_env(:quack, :webhook_url)
325 Application.put_env(:quack, :level, level)
326 Application.put_env(:quack, :meta, meta)
327 Application.put_env(:quack, :webhook_url, webhook_url)
332 |> put_req_header("content-type", "application/json")
333 |> post("/api/pleroma/admin/config", %{
348 value: "https://hooks.slack.com/services/KEY"
353 assert json_response_and_validate_schema(conn, 200) == %{
364 "value" => [":none"],
369 "key" => ":webhook_url",
370 "value" => "https://hooks.slack.com/services/KEY",
371 "db" => [":webhook_url"]
374 "need_reboot" => false
377 assert Application.get_env(:quack, :level) == :info
378 assert Application.get_env(:quack, :meta) == [:none]
379 assert Application.get_env(:quack, :webhook_url) == "https://hooks.slack.com/services/KEY"
382 test "saving config with partial update", %{conn: conn} do
383 insert(:config, key: ":key1", value: :erlang.term_to_binary(key1: 1, key2: 2))
387 |> put_req_header("content-type", "application/json")
388 |> post("/api/pleroma/admin/config", %{
390 %{group: ":pleroma", key: ":key1", value: [%{"tuple" => [":key3", 3]}]}
394 assert json_response_and_validate_schema(conn, 200) == %{
397 "group" => ":pleroma",
400 %{"tuple" => [":key1", 1]},
401 %{"tuple" => [":key2", 2]},
402 %{"tuple" => [":key3", 3]}
404 "db" => [":key1", ":key2", ":key3"]
407 "need_reboot" => false
411 test "saving config which need pleroma reboot", %{conn: conn} do
412 clear_config([:chat, :enabled], true)
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 clear_config([:chat, :enabled], true)
460 |> put_req_header("content-type", "application/json")
462 "/api/pleroma/admin/config",
465 %{group: ":pleroma", key: ":chat", value: [%{"tuple" => [":enabled", true]}]}
469 |> json_response_and_validate_schema(200) == %{
472 "db" => [":enabled"],
473 "group" => ":pleroma",
475 "value" => [%{"tuple" => [":enabled", true]}]
478 "need_reboot" => true
482 |> put_req_header("content-type", "application/json")
483 |> post("/api/pleroma/admin/config", %{
485 %{group: ":pleroma", key: ":key1", value: [%{"tuple" => [":key3", 3]}]}
488 |> json_response_and_validate_schema(200) == %{
491 "group" => ":pleroma",
494 %{"tuple" => [":key3", 3]}
499 "need_reboot" => true
503 assert conn |> get("/api/pleroma/admin/restart") |> json_response(200) ==
505 end) =~ "pleroma restarted"
509 |> get("/api/pleroma/admin/config")
510 |> json_response_and_validate_schema(200)
512 assert configs["need_reboot"] == false
515 test "saving config with nested merge", %{conn: conn} do
516 insert(:config, key: :key1, value: [key1: 1, key2: [k1: 1, k2: 2]])
520 |> put_req_header("content-type", "application/json")
521 |> post("/api/pleroma/admin/config", %{
527 %{"tuple" => [":key3", 3]},
532 %{"tuple" => [":k2", 1]},
533 %{"tuple" => [":k3", 3]}
542 assert json_response_and_validate_schema(conn, 200) == %{
545 "group" => ":pleroma",
548 %{"tuple" => [":key1", 1]},
549 %{"tuple" => [":key3", 3]},
554 %{"tuple" => [":k1", 1]},
555 %{"tuple" => [":k2", 1]},
556 %{"tuple" => [":k3", 3]}
561 "db" => [":key1", ":key3", ":key2"]
564 "need_reboot" => false
568 test "saving special atoms", %{conn: conn} do
571 |> put_req_header("content-type", "application/json")
572 |> post("/api/pleroma/admin/config", %{
575 "group" => ":pleroma",
581 [%{"tuple" => [":versions", [":tlsv1", ":tlsv1.1", ":tlsv1.2"]]}]
589 assert json_response_and_validate_schema(conn, 200) == %{
592 "group" => ":pleroma",
598 [%{"tuple" => [":versions", [":tlsv1", ":tlsv1.1", ":tlsv1.2"]]}]
602 "db" => [":ssl_options"]
605 "need_reboot" => false
608 assert Application.get_env(:pleroma, :key1) == [
609 ssl_options: [versions: [:tlsv1, :"tlsv1.1", :"tlsv1.2"]]
613 test "saving full setting if value is in full_key_update list", %{conn: conn} do
614 backends = Application.get_env(:logger, :backends)
615 on_exit(fn -> Application.put_env(:logger, :backends, backends) end)
623 Pleroma.Config.TransferTask.load_and_update_env([], false)
625 assert Application.get_env(:logger, :backends) == []
629 |> put_req_header("content-type", "application/json")
630 |> post("/api/pleroma/admin/config", %{
640 assert json_response_and_validate_schema(conn, 200) == %{
643 "group" => ":logger",
644 "key" => ":backends",
648 "db" => [":backends"]
651 "need_reboot" => false
654 assert Application.get_env(:logger, :backends) == [
659 test "saving full setting if value is not keyword", %{conn: conn} do
663 value: Tesla.Adapter.Hackey
668 |> put_req_header("content-type", "application/json")
669 |> post("/api/pleroma/admin/config", %{
671 %{group: ":tesla", key: ":adapter", value: "Tesla.Adapter.Httpc"}
675 assert json_response_and_validate_schema(conn, 200) == %{
680 "value" => "Tesla.Adapter.Httpc",
684 "need_reboot" => false
688 test "update config setting & delete with fallback to default value", %{
693 ueberauth = Application.get_env(:ueberauth, Ueberauth)
694 insert(:config, key: :keyaa1)
695 insert(:config, key: :keyaa2)
705 |> put_req_header("content-type", "application/json")
706 |> post("/api/pleroma/admin/config", %{
708 %{group: ":pleroma", key: ":keyaa1", value: "another_value"},
709 %{group: ":pleroma", key: ":keyaa2", value: "another_value"}
713 assert json_response_and_validate_schema(conn, 200) == %{
716 "group" => ":pleroma",
718 "value" => "another_value",
722 "group" => ":pleroma",
724 "value" => "another_value",
728 "need_reboot" => false
731 assert Application.get_env(:pleroma, :keyaa1) == "another_value"
732 assert Application.get_env(:pleroma, :keyaa2) == "another_value"
733 assert Application.get_env(:ueberauth, Ueberauth) == config3.value
737 |> assign(:user, admin)
738 |> assign(:token, token)
739 |> put_req_header("content-type", "application/json")
740 |> post("/api/pleroma/admin/config", %{
742 %{group: ":pleroma", key: ":keyaa2", delete: true},
751 assert json_response_and_validate_schema(conn, 200) == %{
753 "need_reboot" => false
756 assert Application.get_env(:ueberauth, Ueberauth) == ueberauth
757 refute Keyword.has_key?(Application.get_all_env(:pleroma), :keyaa2)
760 test "common config example", %{conn: conn} do
763 |> put_req_header("content-type", "application/json")
764 |> post("/api/pleroma/admin/config", %{
767 "group" => ":pleroma",
768 "key" => "Pleroma.Captcha.NotReal",
770 %{"tuple" => [":enabled", false]},
771 %{"tuple" => [":method", "Pleroma.Captcha.Kocaptcha"]},
772 %{"tuple" => [":seconds_valid", 60]},
773 %{"tuple" => [":path", ""]},
774 %{"tuple" => [":key1", nil]},
775 %{"tuple" => [":partial_chain", "&:hackney_connect.partial_chain/1"]},
776 %{"tuple" => [":regex1", "~r/https:\/\/example.com/"]},
777 %{"tuple" => [":regex2", "~r/https:\/\/example.com/u"]},
778 %{"tuple" => [":regex3", "~r/https:\/\/example.com/i"]},
779 %{"tuple" => [":regex4", "~r/https:\/\/example.com/s"]},
780 %{"tuple" => [":name", "Pleroma"]}
786 assert Config.get([Pleroma.Captcha.NotReal, :name]) == "Pleroma"
788 assert json_response_and_validate_schema(conn, 200) == %{
791 "group" => ":pleroma",
792 "key" => "Pleroma.Captcha.NotReal",
794 %{"tuple" => [":enabled", false]},
795 %{"tuple" => [":method", "Pleroma.Captcha.Kocaptcha"]},
796 %{"tuple" => [":seconds_valid", 60]},
797 %{"tuple" => [":path", ""]},
798 %{"tuple" => [":key1", nil]},
799 %{"tuple" => [":partial_chain", "&:hackney_connect.partial_chain/1"]},
800 %{"tuple" => [":regex1", "~r/https:\\/\\/example.com/"]},
801 %{"tuple" => [":regex2", "~r/https:\\/\\/example.com/u"]},
802 %{"tuple" => [":regex3", "~r/https:\\/\\/example.com/i"]},
803 %{"tuple" => [":regex4", "~r/https:\\/\\/example.com/s"]},
804 %{"tuple" => [":name", "Pleroma"]}
821 "need_reboot" => false
825 test "tuples with more than two values", %{conn: conn} do
828 |> put_req_header("content-type", "application/json")
829 |> post("/api/pleroma/admin/config", %{
832 "group" => ":pleroma",
833 "key" => "Pleroma.Web.Endpoint.NotReal",
850 "Pleroma.Web.MastodonAPI.WebsocketHandler",
857 "Phoenix.Endpoint.CowboyWebSocket",
860 "Phoenix.Transports.WebSocket",
863 "Pleroma.Web.Endpoint",
864 "Pleroma.Web.UserSocket",
875 "Phoenix.Endpoint.Cowboy2Handler",
876 %{"tuple" => ["Pleroma.Web.Endpoint", []]}
893 assert json_response_and_validate_schema(conn, 200) == %{
896 "group" => ":pleroma",
897 "key" => "Pleroma.Web.Endpoint.NotReal",
914 "Pleroma.Web.MastodonAPI.WebsocketHandler",
921 "Phoenix.Endpoint.CowboyWebSocket",
924 "Phoenix.Transports.WebSocket",
927 "Pleroma.Web.Endpoint",
928 "Pleroma.Web.UserSocket",
939 "Phoenix.Endpoint.Cowboy2Handler",
940 %{"tuple" => ["Pleroma.Web.Endpoint", []]}
956 "need_reboot" => false
960 test "settings with nesting map", %{conn: conn} do
963 |> put_req_header("content-type", "application/json")
964 |> post("/api/pleroma/admin/config", %{
967 "group" => ":pleroma",
970 %{"tuple" => [":key2", "some_val"]},
975 ":max_options" => 20,
976 ":max_option_chars" => 200,
977 ":min_expiration" => 0,
978 ":max_expiration" => 31_536_000,
980 ":max_options" => 20,
981 ":max_option_chars" => 200,
982 ":min_expiration" => 0,
983 ":max_expiration" => 31_536_000
993 assert json_response_and_validate_schema(conn, 200) ==
997 "group" => ":pleroma",
1000 %{"tuple" => [":key2", "some_val"]},
1005 ":max_expiration" => 31_536_000,
1006 ":max_option_chars" => 200,
1007 ":max_options" => 20,
1008 ":min_expiration" => 0,
1010 ":max_expiration" => 31_536_000,
1011 ":max_option_chars" => 200,
1012 ":max_options" => 20,
1013 ":min_expiration" => 0
1019 "db" => [":key2", ":key3"]
1022 "need_reboot" => false
1026 test "value as map", %{conn: conn} do
1029 |> put_req_header("content-type", "application/json")
1030 |> post("/api/pleroma/admin/config", %{
1033 "group" => ":pleroma",
1035 "value" => %{"key" => "some_val"}
1040 assert json_response_and_validate_schema(conn, 200) ==
1044 "group" => ":pleroma",
1046 "value" => %{"key" => "some_val"},
1050 "need_reboot" => false
1054 test "queues key as atom", %{conn: conn} do
1057 |> put_req_header("content-type", "application/json")
1058 |> post("/api/pleroma/admin/config", %{
1064 %{"tuple" => [":federator_incoming", 50]},
1065 %{"tuple" => [":federator_outgoing", 50]},
1066 %{"tuple" => [":web_push", 50]},
1067 %{"tuple" => [":mailer", 10]},
1068 %{"tuple" => [":transmogrifier", 20]},
1069 %{"tuple" => [":scheduled_activities", 10]},
1070 %{"tuple" => [":background", 5]}
1076 assert json_response_and_validate_schema(conn, 200) == %{
1082 %{"tuple" => [":federator_incoming", 50]},
1083 %{"tuple" => [":federator_outgoing", 50]},
1084 %{"tuple" => [":web_push", 50]},
1085 %{"tuple" => [":mailer", 10]},
1086 %{"tuple" => [":transmogrifier", 20]},
1087 %{"tuple" => [":scheduled_activities", 10]},
1088 %{"tuple" => [":background", 5]}
1091 ":federator_incoming",
1092 ":federator_outgoing",
1096 ":scheduled_activities",
1101 "need_reboot" => false
1105 test "delete part of settings by atom subkeys", %{conn: conn} do
1108 value: [subkey1: "val1", subkey2: "val2", subkey3: "val3"]
1113 |> put_req_header("content-type", "application/json")
1114 |> post("/api/pleroma/admin/config", %{
1119 subkeys: [":subkey1", ":subkey3"],
1125 assert json_response_and_validate_schema(conn, 200) == %{
1128 "group" => ":pleroma",
1130 "value" => [%{"tuple" => [":subkey2", "val2"]}],
1131 "db" => [":subkey2"]
1134 "need_reboot" => false
1138 test "proxy tuple localhost", %{conn: conn} do
1141 |> put_req_header("content-type", "application/json")
1142 |> post("/api/pleroma/admin/config", %{
1148 %{"tuple" => [":proxy_url", %{"tuple" => [":socks5", "localhost", 1234]}]}
1157 "group" => ":pleroma",
1163 } = json_response_and_validate_schema(conn, 200)
1165 assert %{"tuple" => [":proxy_url", %{"tuple" => [":socks5", "localhost", 1234]}]} in value
1166 assert ":proxy_url" in db
1169 test "proxy tuple domain", %{conn: conn} do
1172 |> put_req_header("content-type", "application/json")
1173 |> post("/api/pleroma/admin/config", %{
1179 %{"tuple" => [":proxy_url", %{"tuple" => [":socks5", "domain.com", 1234]}]}
1188 "group" => ":pleroma",
1194 } = json_response_and_validate_schema(conn, 200)
1196 assert %{"tuple" => [":proxy_url", %{"tuple" => [":socks5", "domain.com", 1234]}]} in value
1197 assert ":proxy_url" in db
1200 test "proxy tuple ip", %{conn: conn} do
1203 |> put_req_header("content-type", "application/json")
1204 |> post("/api/pleroma/admin/config", %{
1210 %{"tuple" => [":proxy_url", %{"tuple" => [":socks5", "127.0.0.1", 1234]}]}
1219 "group" => ":pleroma",
1225 } = json_response_and_validate_schema(conn, 200)
1227 assert %{"tuple" => [":proxy_url", %{"tuple" => [":socks5", "127.0.0.1", 1234]}]} in value
1228 assert ":proxy_url" in db
1231 @tag capture_log: true
1232 test "doesn't set keys not in the whitelist", %{conn: conn} do
1233 clear_config(:database_config_whitelist, [
1236 {:pleroma, Pleroma.Captcha.NotReal},
1241 |> put_req_header("content-type", "application/json")
1242 |> post("/api/pleroma/admin/config", %{
1244 %{group: ":pleroma", key: ":key1", value: "value1"},
1245 %{group: ":pleroma", key: ":key2", value: "value2"},
1246 %{group: ":pleroma", key: ":key3", value: "value3"},
1247 %{group: ":pleroma", key: "Pleroma.Web.Endpoint.NotReal", value: "value4"},
1248 %{group: ":pleroma", key: "Pleroma.Captcha.NotReal", value: "value5"},
1249 %{group: ":not_real", key: ":anything", value: "value6"}
1253 assert Application.get_env(:pleroma, :key1) == "value1"
1254 assert Application.get_env(:pleroma, :key2) == "value2"
1255 assert Application.get_env(:pleroma, :key3) == nil
1256 assert Application.get_env(:pleroma, Pleroma.Web.Endpoint.NotReal) == nil
1257 assert Application.get_env(:pleroma, Pleroma.Captcha.NotReal) == "value5"
1258 assert Application.get_env(:not_real, :anything) == "value6"
1261 test "args for Pleroma.Upload.Filter.Mogrify with custom tuples", %{conn: conn} do
1262 clear_config(Pleroma.Upload.Filter.Mogrify)
1265 |> put_req_header("content-type", "application/json")
1266 |> post("/api/pleroma/admin/config", %{
1270 key: "Pleroma.Upload.Filter.Mogrify",
1272 %{"tuple" => [":args", ["auto-orient", "strip"]]}
1277 |> json_response_and_validate_schema(200) == %{
1280 "group" => ":pleroma",
1281 "key" => "Pleroma.Upload.Filter.Mogrify",
1283 %{"tuple" => [":args", ["auto-orient", "strip"]]}
1288 "need_reboot" => false
1291 assert Config.get(Pleroma.Upload.Filter.Mogrify) == [args: ["auto-orient", "strip"]]
1294 |> put_req_header("content-type", "application/json")
1295 |> post("/api/pleroma/admin/config", %{
1299 key: "Pleroma.Upload.Filter.Mogrify",
1307 "{\"implode\", \"1\"}",
1308 "{\"resize\", \"3840x1080>\"}"
1316 |> json_response(200) == %{
1319 "group" => ":pleroma",
1320 "key" => "Pleroma.Upload.Filter.Mogrify",
1328 "{\"implode\", \"1\"}",
1329 "{\"resize\", \"3840x1080>\"}"
1337 "need_reboot" => false
1340 assert Config.get(Pleroma.Upload.Filter.Mogrify) == [
1341 args: ["auto-orient", "strip", {"implode", "1"}, {"resize", "3840x1080>"}]
1345 test "enables the welcome messages", %{conn: conn} do
1346 clear_config([:welcome])
1349 "group" => ":pleroma",
1350 "key" => ":welcome",
1356 %{"tuple" => [":enabled", true]},
1357 %{"tuple" => [":message", "Welcome to Pleroma!"]},
1358 %{"tuple" => [":sender_nickname", "pleroma"]}
1366 %{"tuple" => [":enabled", true]},
1367 %{"tuple" => [":message", "Welcome to Pleroma!"]},
1368 %{"tuple" => [":sender_nickname", "pleroma"]}
1376 %{"tuple" => [":enabled", true]},
1377 %{"tuple" => [":sender", %{"tuple" => ["pleroma@dev.dev", "Pleroma"]}]},
1378 %{"tuple" => [":subject", "Welcome to <%= instance_name %>!"]},
1379 %{"tuple" => [":html", "Welcome to <%= instance_name %>!"]},
1380 %{"tuple" => [":text", "Welcome to <%= instance_name %>!"]}
1387 refute Pleroma.User.WelcomeEmail.enabled?()
1388 refute Pleroma.User.WelcomeMessage.enabled?()
1389 refute Pleroma.User.WelcomeChatMessage.enabled?()
1393 |> put_req_header("content-type", "application/json")
1394 |> post("/api/pleroma/admin/config", %{"configs" => [params]})
1395 |> json_response_and_validate_schema(200)
1397 assert Pleroma.User.WelcomeEmail.enabled?()
1398 assert Pleroma.User.WelcomeMessage.enabled?()
1399 assert Pleroma.User.WelcomeChatMessage.enabled?()
1404 "db" => [":direct_message", ":chat_message", ":email"],
1405 "group" => ":pleroma",
1406 "key" => ":welcome",
1407 "value" => params["value"]
1410 "need_reboot" => false
1415 describe "GET /api/pleroma/admin/config/descriptions" do
1416 test "structure", %{conn: conn} do
1417 conn = get(conn, "/api/pleroma/admin/config/descriptions")
1419 assert [child | _others] = json_response_and_validate_schema(conn, 200)
1421 assert child["children"]
1423 assert String.starts_with?(child["group"], ":")
1424 assert child["description"]
1427 test "filters by database configuration whitelist", %{conn: conn} do
1428 clear_config(:database_config_whitelist, [
1429 {:pleroma, :instance},
1430 {:pleroma, :activitypub},
1431 {:pleroma, Pleroma.Upload},
1435 conn = get(conn, "/api/pleroma/admin/config/descriptions")
1437 children = json_response_and_validate_schema(conn, 200)
1439 assert length(children) == 4
1441 assert Enum.count(children, fn c -> c["group"] == ":pleroma" end) == 3
1443 instance = Enum.find(children, fn c -> c["key"] == ":instance" end)
1444 assert instance["children"]
1446 activitypub = Enum.find(children, fn c -> c["key"] == ":activitypub" end)
1447 assert activitypub["children"]
1449 web_endpoint = Enum.find(children, fn c -> c["key"] == "Pleroma.Upload" end)
1450 assert web_endpoint["children"]
1452 esshd = Enum.find(children, fn c -> c["group"] == ":esshd" end)
1453 assert esshd["children"]