Merge branch 'develop' of git.pleroma.social:pleroma/pleroma into update-validator
[akkoma] / test / web / admin_api / controllers / config_controller_test.exs
index 9bc6fd91c786b284a5fb3c631beb32d7109814c1..064ef9bc7cb82224d6b4b5188602d5b2e9f21348 100644 (file)
@@ -30,7 +30,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
       Config.put(:configurable_from_database, false)
       conn = get(conn, "/api/pleroma/admin/config")
 
-      assert json_response(conn, 400) ==
+      assert json_response_and_validate_schema(conn, 400) ==
                %{
                  "error" => "To use this endpoint you need to enable configuration from database."
                }
@@ -40,7 +40,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
       config1 = insert(:config)
       config2 = insert(:config)
 
-      conn = get(conn, "/api/pleroma/admin/config", %{"only_db" => true})
+      conn = get(conn, "/api/pleroma/admin/config?only_db=true")
 
       %{
         "configs" => [
@@ -55,19 +55,19 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
             "value" => _
           }
         ]
-      } = json_response(conn, 200)
+      } = json_response_and_validate_schema(conn, 200)
 
-      assert key1 == config1.key
-      assert key2 == config2.key
+      assert key1 == inspect(config1.key)
+      assert key2 == inspect(config2.key)
     end
 
     test "db is added to settings that are in db", %{conn: conn} do
-      _config = insert(:config, key: ":instance", value: ConfigDB.to_binary(name: "Some name"))
+      _config = insert(:config, key: ":instance", value: [name: "Some name"])
 
       %{"configs" => configs} =
         conn
         |> get("/api/pleroma/admin/config")
-        |> json_response(200)
+        |> json_response_and_validate_schema(200)
 
       [instance_config] =
         Enum.filter(configs, fn %{"group" => group, "key" => key} ->
@@ -83,68 +83,71 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
 
       config3 =
         insert(:config,
-          value: ConfigDB.to_binary(k1: :v1, k2: :v2)
+          value: [k1: :v1, k2: :v2]
         )
 
       %{"configs" => configs} =
         conn
         |> get("/api/pleroma/admin/config")
-        |> json_response(200)
+        |> json_response_and_validate_schema(200)
 
       assert length(configs) > 3
 
+      saved_configs = [config1, config2, config3]
+      keys = Enum.map(saved_configs, &inspect(&1.key))
+
       received_configs =
         Enum.filter(configs, fn %{"group" => group, "key" => key} ->
-          group == ":pleroma" and key in [config1.key, config2.key, config3.key]
+          group == ":pleroma" and key in keys
         end)
 
       assert length(received_configs) == 3
 
       db_keys =
         config3.value
-        |> ConfigDB.from_binary()
         |> Keyword.keys()
-        |> ConfigDB.convert()
+        |> ConfigDB.to_json_types()
+
+      keys = Enum.map(saved_configs -- [config3], &inspect(&1.key))
+
+      values = Enum.map(saved_configs, &ConfigDB.to_json_types(&1.value))
+
+      mapset_keys = MapSet.new(keys ++ db_keys)
 
       Enum.each(received_configs, fn %{"value" => value, "db" => db} ->
-        assert db in [[config1.key], [config2.key], db_keys]
+        db = MapSet.new(db)
+        assert MapSet.subset?(db, mapset_keys)
 
-        assert value in [
-                 ConfigDB.from_binary_with_convert(config1.value),
-                 ConfigDB.from_binary_with_convert(config2.value),
-                 ConfigDB.from_binary_with_convert(config3.value)
-               ]
+        assert value in values
       end)
     end
 
     test "subkeys with full update right merge", %{conn: conn} do
-      config1 =
-        insert(:config,
-          key: ":emoji",
-          value: ConfigDB.to_binary(groups: [a: 1, b: 2], key: [a: 1])
-        )
+      insert(:config,
+        key: ":emoji",
+        value: [groups: [a: 1, b: 2], key: [a: 1]]
+      )
 
-      config2 =
-        insert(:config,
-          key: ":assets",
-          value: ConfigDB.to_binary(mascots: [a: 1, b: 2], key: [a: 1])
-        )
+      insert(:config,
+        key: ":assets",
+        value: [mascots: [a: 1, b: 2], key: [a: 1]]
+      )
 
       %{"configs" => configs} =
         conn
         |> get("/api/pleroma/admin/config")
-        |> json_response(200)
+        |> json_response_and_validate_schema(200)
 
       vals =
         Enum.filter(configs, fn %{"group" => group, "key" => key} ->
-          group == ":pleroma" and key in [config1.key, config2.key]
+          group == ":pleroma" and key in [":emoji", ":assets"]
         end)
 
       emoji = Enum.find(vals, fn %{"key" => key} -> key == ":emoji" end)
       assets = Enum.find(vals, fn %{"key" => key} -> key == ":assets" end)
 
-      emoji_val = ConfigDB.transform_with_out_binary(emoji["value"])
-      assets_val = ConfigDB.transform_with_out_binary(assets["value"])
+      emoji_val = ConfigDB.to_elixir_types(emoji["value"])
+      assets_val = ConfigDB.to_elixir_types(assets["value"])
 
       assert emoji_val[:groups] == [a: 1, b: 2]
       assert assets_val[:mascots] == [a: 1, b: 2]
@@ -152,9 +155,12 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
   end
 
   test "POST /api/pleroma/admin/config error", %{conn: conn} do
-    conn = post(conn, "/api/pleroma/admin/config", %{"configs" => []})
+    conn =
+      conn
+      |> put_req_header("content-type", "application/json")
+      |> post("/api/pleroma/admin/config", %{"configs" => []})
 
-    assert json_response(conn, 400) ==
+    assert json_response_and_validate_schema(conn, 400) ==
              %{"error" => "To use this endpoint you need to enable configuration from database."}
   end
 
@@ -185,7 +191,9 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
       on_exit(fn -> Application.put_env(:ueberauth, Ueberauth, ueberauth) end)
 
       conn =
-        post(conn, "/api/pleroma/admin/config", %{
+        conn
+        |> put_req_header("content-type", "application/json")
+        |> post("/api/pleroma/admin/config", %{
           configs: [
             %{group: ":pleroma", key: ":key1", value: "value1"},
             %{
@@ -225,7 +233,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
           ]
         })
 
-      assert json_response(conn, 200) == %{
+      assert json_response_and_validate_schema(conn, 200) == %{
                "configs" => [
                  %{
                    "group" => ":pleroma",
@@ -272,7 +280,8 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
                    "value" => %{"tuple" => ["string", "Pleroma.Captcha.NotReal", []]},
                    "db" => [":key5"]
                  }
-               ]
+               ],
+               "need_reboot" => false
              }
 
       assert Application.get_env(:pleroma, :key1) == "value1"
@@ -310,7 +319,9 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
       end)
 
       conn =
-        post(conn, "/api/pleroma/admin/config", %{
+        conn
+        |> put_req_header("content-type", "application/json")
+        |> post("/api/pleroma/admin/config", %{
           configs: [
             %{
               group: ":quack",
@@ -330,7 +341,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
           ]
         })
 
-      assert json_response(conn, 200) == %{
+      assert json_response_and_validate_schema(conn, 200) == %{
                "configs" => [
                  %{
                    "group" => ":quack",
@@ -350,7 +361,8 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
                    "value" => "https://hooks.slack.com/services/KEY",
                    "db" => [":webhook_url"]
                  }
-               ]
+               ],
+               "need_reboot" => false
              }
 
       assert Application.get_env(:quack, :level) == :info
@@ -359,16 +371,18 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
     end
 
     test "saving config with partial update", %{conn: conn} do
-      config = insert(:config, key: ":key1", value: :erlang.term_to_binary(key1: 1, key2: 2))
+      insert(:config, key: ":key1", value: :erlang.term_to_binary(key1: 1, key2: 2))
 
       conn =
-        post(conn, "/api/pleroma/admin/config", %{
+        conn
+        |> put_req_header("content-type", "application/json")
+        |> post("/api/pleroma/admin/config", %{
           configs: [
-            %{group: config.group, key: config.key, value: [%{"tuple" => [":key3", 3]}]}
+            %{group: ":pleroma", key: ":key1", value: [%{"tuple" => [":key3", 3]}]}
           ]
         })
 
-      assert json_response(conn, 200) == %{
+      assert json_response_and_validate_schema(conn, 200) == %{
                "configs" => [
                  %{
                    "group" => ":pleroma",
@@ -380,7 +394,8 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
                    ],
                    "db" => [":key1", ":key2", ":key3"]
                  }
-               ]
+               ],
+               "need_reboot" => false
              }
     end
 
@@ -388,8 +403,9 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
       chat = Config.get(:chat)
       on_exit(fn -> Config.put(:chat, chat) end)
 
-      assert post(
-               conn,
+      assert conn
+             |> put_req_header("content-type", "application/json")
+             |> post(
                "/api/pleroma/admin/config",
                %{
                  configs: [
@@ -397,7 +413,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
                  ]
                }
              )
-             |> json_response(200) == %{
+             |> json_response_and_validate_schema(200) == %{
                "configs" => [
                  %{
                    "db" => [":enabled"],
@@ -412,18 +428,19 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
       configs =
         conn
         |> get("/api/pleroma/admin/config")
-        |> json_response(200)
+        |> json_response_and_validate_schema(200)
 
       assert configs["need_reboot"]
 
       capture_log(fn ->
-        assert conn |> get("/api/pleroma/admin/restart") |> json_response(200) == %{}
+        assert conn |> get("/api/pleroma/admin/restart") |> json_response(200) ==
+                 %{}
       end) =~ "pleroma restarted"
 
       configs =
         conn
         |> get("/api/pleroma/admin/config")
-        |> json_response(200)
+        |> json_response_and_validate_schema(200)
 
       assert configs["need_reboot"] == false
     end
@@ -432,8 +449,9 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
       chat = Config.get(:chat)
       on_exit(fn -> Config.put(:chat, chat) end)
 
-      assert post(
-               conn,
+      assert conn
+             |> put_req_header("content-type", "application/json")
+             |> post(
                "/api/pleroma/admin/config",
                %{
                  configs: [
@@ -441,7 +459,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
                  ]
                }
              )
-             |> json_response(200) == %{
+             |> json_response_and_validate_schema(200) == %{
                "configs" => [
                  %{
                    "db" => [":enabled"],
@@ -453,12 +471,14 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
                "need_reboot" => true
              }
 
-      assert post(conn, "/api/pleroma/admin/config", %{
+      assert conn
+             |> put_req_header("content-type", "application/json")
+             |> post("/api/pleroma/admin/config", %{
                configs: [
                  %{group: ":pleroma", key: ":key1", value: [%{"tuple" => [":key3", 3]}]}
                ]
              })
-             |> json_response(200) == %{
+             |> json_response_and_validate_schema(200) == %{
                "configs" => [
                  %{
                    "group" => ":pleroma",
@@ -473,27 +493,29 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
              }
 
       capture_log(fn ->
-        assert conn |> get("/api/pleroma/admin/restart") |> json_response(200) == %{}
+        assert conn |> get("/api/pleroma/admin/restart") |> json_response(200) ==
+                 %{}
       end) =~ "pleroma restarted"
 
       configs =
         conn
         |> get("/api/pleroma/admin/config")
-        |> json_response(200)
+        |> json_response_and_validate_schema(200)
 
       assert configs["need_reboot"] == false
     end
 
     test "saving config with nested merge", %{conn: conn} do
-      config =
-        insert(:config, key: ":key1", value: :erlang.term_to_binary(key1: 1, key2: [k1: 1, k2: 2]))
+      insert(:config, key: :key1, value: [key1: 1, key2: [k1: 1, k2: 2]])
 
       conn =
-        post(conn, "/api/pleroma/admin/config", %{
+        conn
+        |> put_req_header("content-type", "application/json")
+        |> post("/api/pleroma/admin/config", %{
           configs: [
             %{
-              group: config.group,
-              key: config.key,
+              group: ":pleroma",
+              key: ":key1",
               value: [
                 %{"tuple" => [":key3", 3]},
                 %{
@@ -510,7 +532,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
           ]
         })
 
-      assert json_response(conn, 200) == %{
+      assert json_response_and_validate_schema(conn, 200) == %{
                "configs" => [
                  %{
                    "group" => ":pleroma",
@@ -531,13 +553,16 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
                    ],
                    "db" => [":key1", ":key3", ":key2"]
                  }
-               ]
+               ],
+               "need_reboot" => false
              }
     end
 
     test "saving special atoms", %{conn: conn} do
       conn =
-        post(conn, "/api/pleroma/admin/config", %{
+        conn
+        |> put_req_header("content-type", "application/json")
+        |> post("/api/pleroma/admin/config", %{
           "configs" => [
             %{
               "group" => ":pleroma",
@@ -554,7 +579,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
           ]
         })
 
-      assert json_response(conn, 200) == %{
+      assert json_response_and_validate_schema(conn, 200) == %{
                "configs" => [
                  %{
                    "group" => ":pleroma",
@@ -569,7 +594,8 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
                    ],
                    "db" => [":ssl_options"]
                  }
-               ]
+               ],
+               "need_reboot" => false
              }
 
       assert Application.get_env(:pleroma, :key1) == [
@@ -581,29 +607,30 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
       backends = Application.get_env(:logger, :backends)
       on_exit(fn -> Application.put_env(:logger, :backends, backends) end)
 
-      config =
-        insert(:config,
-          group: ":logger",
-          key: ":backends",
-          value: :erlang.term_to_binary([])
-        )
+      insert(:config,
+        group: :logger,
+        key: :backends,
+        value: []
+      )
 
       Pleroma.Config.TransferTask.load_and_update_env([], false)
 
       assert Application.get_env(:logger, :backends) == []
 
       conn =
-        post(conn, "/api/pleroma/admin/config", %{
+        conn
+        |> put_req_header("content-type", "application/json")
+        |> post("/api/pleroma/admin/config", %{
           configs: [
             %{
-              group: config.group,
-              key: config.key,
+              group: ":logger",
+              key: ":backends",
               value: [":console"]
             }
           ]
         })
 
-      assert json_response(conn, 200) == %{
+      assert json_response_and_validate_schema(conn, 200) == %{
                "configs" => [
                  %{
                    "group" => ":logger",
@@ -613,7 +640,8 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
                    ],
                    "db" => [":backends"]
                  }
-               ]
+               ],
+               "need_reboot" => false
              }
 
       assert Application.get_env(:logger, :backends) == [
@@ -622,21 +650,22 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
     end
 
     test "saving full setting if value is not keyword", %{conn: conn} do
-      config =
-        insert(:config,
-          group: ":tesla",
-          key: ":adapter",
-          value: :erlang.term_to_binary(Tesla.Adapter.Hackey)
-        )
+      insert(:config,
+        group: :tesla,
+        key: :adapter,
+        value: Tesla.Adapter.Hackey
+      )
 
       conn =
-        post(conn, "/api/pleroma/admin/config", %{
+        conn
+        |> put_req_header("content-type", "application/json")
+        |> post("/api/pleroma/admin/config", %{
           configs: [
-            %{group: config.group, key: config.key, value: "Tesla.Adapter.Httpc"}
+            %{group: ":tesla", key: ":adapter", value: "Tesla.Adapter.Httpc"}
           ]
         })
 
-      assert json_response(conn, 200) == %{
+      assert json_response_and_validate_schema(conn, 200) == %{
                "configs" => [
                  %{
                    "group" => ":tesla",
@@ -644,7 +673,8 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
                    "value" => "Tesla.Adapter.Httpc",
                    "db" => [":adapter"]
                  }
-               ]
+               ],
+               "need_reboot" => false
              }
     end
 
@@ -654,51 +684,55 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
       token: token
     } do
       ueberauth = Application.get_env(:ueberauth, Ueberauth)
-      config1 = insert(:config, key: ":keyaa1")
-      config2 = insert(:config, key: ":keyaa2")
+      insert(:config, key: :keyaa1)
+      insert(:config, key: :keyaa2)
 
       config3 =
         insert(:config,
-          group: ":ueberauth",
-          key: "Ueberauth"
+          group: :ueberauth,
+          key: Ueberauth
         )
 
       conn =
-        post(conn, "/api/pleroma/admin/config", %{
+        conn
+        |> put_req_header("content-type", "application/json")
+        |> post("/api/pleroma/admin/config", %{
           configs: [
-            %{group: config1.group, key: config1.key, value: "another_value"},
-            %{group: config2.group, key: config2.key, value: "another_value"}
+            %{group: ":pleroma", key: ":keyaa1", value: "another_value"},
+            %{group: ":pleroma", key: ":keyaa2", value: "another_value"}
           ]
         })
 
-      assert json_response(conn, 200) == %{
+      assert json_response_and_validate_schema(conn, 200) == %{
                "configs" => [
                  %{
                    "group" => ":pleroma",
-                   "key" => config1.key,
+                   "key" => ":keyaa1",
                    "value" => "another_value",
                    "db" => [":keyaa1"]
                  },
                  %{
                    "group" => ":pleroma",
-                   "key" => config2.key,
+                   "key" => ":keyaa2",
                    "value" => "another_value",
                    "db" => [":keyaa2"]
                  }
-               ]
+               ],
+               "need_reboot" => false
              }
 
       assert Application.get_env(:pleroma, :keyaa1) == "another_value"
       assert Application.get_env(:pleroma, :keyaa2) == "another_value"
-      assert Application.get_env(:ueberauth, Ueberauth) == ConfigDB.from_binary(config3.value)
+      assert Application.get_env(:ueberauth, Ueberauth) == config3.value
 
       conn =
         build_conn()
         |> assign(:user, admin)
         |> assign(:token, token)
+        |> put_req_header("content-type", "application/json")
         |> post("/api/pleroma/admin/config", %{
           configs: [
-            %{group: config2.group, key: config2.key, delete: true},
+            %{group: ":pleroma", key: ":keyaa2", delete: true},
             %{
               group: ":ueberauth",
               key: "Ueberauth",
@@ -707,8 +741,9 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
           ]
         })
 
-      assert json_response(conn, 200) == %{
-               "configs" => []
+      assert json_response_and_validate_schema(conn, 200) == %{
+               "configs" => [],
+               "need_reboot" => false
              }
 
       assert Application.get_env(:ueberauth, Ueberauth) == ueberauth
@@ -717,7 +752,9 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
 
     test "common config example", %{conn: conn} do
       conn =
-        post(conn, "/api/pleroma/admin/config", %{
+        conn
+        |> put_req_header("content-type", "application/json")
+        |> post("/api/pleroma/admin/config", %{
           configs: [
             %{
               "group" => ":pleroma",
@@ -741,7 +778,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
 
       assert Config.get([Pleroma.Captcha.NotReal, :name]) == "Pleroma"
 
-      assert json_response(conn, 200) == %{
+      assert json_response_and_validate_schema(conn, 200) == %{
                "configs" => [
                  %{
                    "group" => ":pleroma",
@@ -773,13 +810,16 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
                      ":name"
                    ]
                  }
-               ]
+               ],
+               "need_reboot" => false
              }
     end
 
     test "tuples with more than two values", %{conn: conn} do
       conn =
-        post(conn, "/api/pleroma/admin/config", %{
+        conn
+        |> put_req_header("content-type", "application/json")
+        |> post("/api/pleroma/admin/config", %{
           configs: [
             %{
               "group" => ":pleroma",
@@ -843,7 +883,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
           ]
         })
 
-      assert json_response(conn, 200) == %{
+      assert json_response_and_validate_schema(conn, 200) == %{
                "configs" => [
                  %{
                    "group" => ":pleroma",
@@ -905,13 +945,16 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
                    ],
                    "db" => [":http"]
                  }
-               ]
+               ],
+               "need_reboot" => false
              }
     end
 
     test "settings with nesting map", %{conn: conn} do
       conn =
-        post(conn, "/api/pleroma/admin/config", %{
+        conn
+        |> put_req_header("content-type", "application/json")
+        |> post("/api/pleroma/admin/config", %{
           configs: [
             %{
               "group" => ":pleroma",
@@ -940,7 +983,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
           ]
         })
 
-      assert json_response(conn, 200) ==
+      assert json_response_and_validate_schema(conn, 200) ==
                %{
                  "configs" => [
                    %{
@@ -968,13 +1011,16 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
                      ],
                      "db" => [":key2", ":key3"]
                    }
-                 ]
+                 ],
+                 "need_reboot" => false
                }
     end
 
     test "value as map", %{conn: conn} do
       conn =
-        post(conn, "/api/pleroma/admin/config", %{
+        conn
+        |> put_req_header("content-type", "application/json")
+        |> post("/api/pleroma/admin/config", %{
           configs: [
             %{
               "group" => ":pleroma",
@@ -984,7 +1030,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
           ]
         })
 
-      assert json_response(conn, 200) ==
+      assert json_response_and_validate_schema(conn, 200) ==
                %{
                  "configs" => [
                    %{
@@ -993,13 +1039,16 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
                      "value" => %{"key" => "some_val"},
                      "db" => [":key1"]
                    }
-                 ]
+                 ],
+                 "need_reboot" => false
                }
     end
 
     test "queues key as atom", %{conn: conn} do
       conn =
-        post(conn, "/api/pleroma/admin/config", %{
+        conn
+        |> put_req_header("content-type", "application/json")
+        |> post("/api/pleroma/admin/config", %{
           configs: [
             %{
               "group" => ":oban",
@@ -1017,7 +1066,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
           ]
         })
 
-      assert json_response(conn, 200) == %{
+      assert json_response_and_validate_schema(conn, 200) == %{
                "configs" => [
                  %{
                    "group" => ":oban",
@@ -1041,30 +1090,32 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
                      ":background"
                    ]
                  }
-               ]
+               ],
+               "need_reboot" => false
              }
     end
 
     test "delete part of settings by atom subkeys", %{conn: conn} do
-      config =
-        insert(:config,
-          key: ":keyaa1",
-          value: :erlang.term_to_binary(subkey1: "val1", subkey2: "val2", subkey3: "val3")
-        )
+      insert(:config,
+        key: :keyaa1,
+        value: [subkey1: "val1", subkey2: "val2", subkey3: "val3"]
+      )
 
       conn =
-        post(conn, "/api/pleroma/admin/config", %{
+        conn
+        |> put_req_header("content-type", "application/json")
+        |> post("/api/pleroma/admin/config", %{
           configs: [
             %{
-              group: config.group,
-              key: config.key,
+              group: ":pleroma",
+              key: ":keyaa1",
               subkeys: [":subkey1", ":subkey3"],
               delete: true
             }
           ]
         })
 
-      assert json_response(conn, 200) == %{
+      assert json_response_and_validate_schema(conn, 200) == %{
                "configs" => [
                  %{
                    "group" => ":pleroma",
@@ -1072,13 +1123,16 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
                    "value" => [%{"tuple" => [":subkey2", "val2"]}],
                    "db" => [":subkey2"]
                  }
-               ]
+               ],
+               "need_reboot" => false
              }
     end
 
     test "proxy tuple localhost", %{conn: conn} do
       conn =
-        post(conn, "/api/pleroma/admin/config", %{
+        conn
+        |> put_req_header("content-type", "application/json")
+        |> post("/api/pleroma/admin/config", %{
           configs: [
             %{
               group: ":pleroma",
@@ -1099,7 +1153,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
                    "db" => db
                  }
                ]
-             } = json_response(conn, 200)
+             } = json_response_and_validate_schema(conn, 200)
 
       assert %{"tuple" => [":proxy_url", %{"tuple" => [":socks5", "localhost", 1234]}]} in value
       assert ":proxy_url" in db
@@ -1107,7 +1161,9 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
 
     test "proxy tuple domain", %{conn: conn} do
       conn =
-        post(conn, "/api/pleroma/admin/config", %{
+        conn
+        |> put_req_header("content-type", "application/json")
+        |> post("/api/pleroma/admin/config", %{
           configs: [
             %{
               group: ":pleroma",
@@ -1128,7 +1184,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
                    "db" => db
                  }
                ]
-             } = json_response(conn, 200)
+             } = json_response_and_validate_schema(conn, 200)
 
       assert %{"tuple" => [":proxy_url", %{"tuple" => [":socks5", "domain.com", 1234]}]} in value
       assert ":proxy_url" in db
@@ -1136,7 +1192,9 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
 
     test "proxy tuple ip", %{conn: conn} do
       conn =
-        post(conn, "/api/pleroma/admin/config", %{
+        conn
+        |> put_req_header("content-type", "application/json")
+        |> post("/api/pleroma/admin/config", %{
           configs: [
             %{
               group: ":pleroma",
@@ -1157,7 +1215,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
                    "db" => db
                  }
                ]
-             } = json_response(conn, 200)
+             } = json_response_and_validate_schema(conn, 200)
 
       assert %{"tuple" => [":proxy_url", %{"tuple" => [":socks5", "127.0.0.1", 1234]}]} in value
       assert ":proxy_url" in db
@@ -1172,7 +1230,9 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
         {:not_real}
       ])
 
-      post(conn, "/api/pleroma/admin/config", %{
+      conn
+      |> put_req_header("content-type", "application/json")
+      |> post("/api/pleroma/admin/config", %{
         configs: [
           %{group: ":pleroma", key: ":key1", value: "value1"},
           %{group: ":pleroma", key: ":key2", value: "value2"},
@@ -1190,6 +1250,90 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
       assert Application.get_env(:pleroma, Pleroma.Captcha.NotReal) == "value5"
       assert Application.get_env(:not_real, :anything) == "value6"
     end
+
+    test "args for Pleroma.Upload.Filter.Mogrify with custom tuples", %{conn: conn} do
+      clear_config(Pleroma.Upload.Filter.Mogrify)
+
+      assert conn
+             |> put_req_header("content-type", "application/json")
+             |> post("/api/pleroma/admin/config", %{
+               configs: [
+                 %{
+                   group: ":pleroma",
+                   key: "Pleroma.Upload.Filter.Mogrify",
+                   value: [
+                     %{"tuple" => [":args", ["auto-orient", "strip"]]}
+                   ]
+                 }
+               ]
+             })
+             |> json_response_and_validate_schema(200) == %{
+               "configs" => [
+                 %{
+                   "group" => ":pleroma",
+                   "key" => "Pleroma.Upload.Filter.Mogrify",
+                   "value" => [
+                     %{"tuple" => [":args", ["auto-orient", "strip"]]}
+                   ],
+                   "db" => [":args"]
+                 }
+               ],
+               "need_reboot" => false
+             }
+
+      assert Config.get(Pleroma.Upload.Filter.Mogrify) == [args: ["auto-orient", "strip"]]
+
+      assert conn
+             |> put_req_header("content-type", "application/json")
+             |> post("/api/pleroma/admin/config", %{
+               configs: [
+                 %{
+                   group: ":pleroma",
+                   key: "Pleroma.Upload.Filter.Mogrify",
+                   value: [
+                     %{
+                       "tuple" => [
+                         ":args",
+                         [
+                           "auto-orient",
+                           "strip",
+                           "{\"implode\", \"1\"}",
+                           "{\"resize\", \"3840x1080>\"}"
+                         ]
+                       ]
+                     }
+                   ]
+                 }
+               ]
+             })
+             |> json_response(200) == %{
+               "configs" => [
+                 %{
+                   "group" => ":pleroma",
+                   "key" => "Pleroma.Upload.Filter.Mogrify",
+                   "value" => [
+                     %{
+                       "tuple" => [
+                         ":args",
+                         [
+                           "auto-orient",
+                           "strip",
+                           "{\"implode\", \"1\"}",
+                           "{\"resize\", \"3840x1080>\"}"
+                         ]
+                       ]
+                     }
+                   ],
+                   "db" => [":args"]
+                 }
+               ],
+               "need_reboot" => false
+             }
+
+      assert Config.get(Pleroma.Upload.Filter.Mogrify) == [
+               args: ["auto-orient", "strip", {"implode", "1"}, {"resize", "3840x1080>"}]
+             ]
+    end
   end
 
   describe "GET /api/pleroma/admin/config/descriptions" do
@@ -1200,7 +1344,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
         assign(conn, :user, admin)
         |> get("/api/pleroma/admin/config/descriptions")
 
-      assert [child | _others] = json_response(conn, 200)
+      assert [child | _others] = json_response_and_validate_schema(conn, 200)
 
       assert child["children"]
       assert child["key"]
@@ -1222,7 +1366,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
         assign(conn, :user, admin)
         |> get("/api/pleroma/admin/config/descriptions")
 
-      children = json_response(conn, 200)
+      children = json_response_and_validate_schema(conn, 200)
 
       assert length(children) == 4