X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=test%2Fpleroma%2Fweb%2Fadmin_api%2Fcontrollers%2Fconfig_controller_test.exs;h=7c786c389c248f333263e9982e0fcf532ba69204;hb=c45b3bde949bbbd6b8d6de30022c1d1e5b99dc44;hp=4e897455f03bbc0b241fa04052898def8556639e;hpb=8b6221d4ecd1d7e354e7de831dd46e285cb85077;p=akkoma
diff --git a/test/pleroma/web/admin_api/controllers/config_controller_test.exs b/test/pleroma/web/admin_api/controllers/config_controller_test.exs
index 4e897455f..7c786c389 100644
--- a/test/pleroma/web/admin_api/controllers/config_controller_test.exs
+++ b/test/pleroma/web/admin_api/controllers/config_controller_test.exs
@@ -1,14 +1,13 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors
+# Copyright © 2017-2021 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
- use Pleroma.Web.ConnCase, async: true
+ use Pleroma.Web.ConnCase
import ExUnit.CaptureLog
import Pleroma.Factory
- alias Pleroma.Config
alias Pleroma.ConfigDB
setup do
@@ -27,12 +26,12 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
setup do: clear_config(:configurable_from_database, true)
test "when configuration from database is off", %{conn: conn} do
- Config.put(:configurable_from_database, false)
+ clear_config(:configurable_from_database, false)
conn = get(conn, "/api/pleroma/admin/config")
assert json_response_and_validate_schema(conn, 400) ==
%{
- "error" => "To use this endpoint you need to enable configuration from database."
+ "error" => "You must enable configurable_from_database in your config file."
}
end
@@ -162,14 +161,16 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
end
end
- test "POST /api/pleroma/admin/config error", %{conn: conn} do
+ test "POST /api/pleroma/admin/config with configdb disabled", %{conn: conn} do
+ clear_config(:configurable_from_database, false)
+
conn =
conn
|> put_req_header("content-type", "application/json")
|> post("/api/pleroma/admin/config", %{"configs" => []})
assert json_response_and_validate_schema(conn, 400) ==
- %{"error" => "To use this endpoint you need to enable configuration from database."}
+ %{"error" => "You must enable configurable_from_database in your config file."}
end
describe "POST /api/pleroma/admin/config" do
@@ -408,8 +409,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
end
test "saving config which need pleroma reboot", %{conn: conn} do
- chat = Config.get(:chat)
- on_exit(fn -> Config.put(:chat, chat) end)
+ clear_config([:shout, :enabled], true)
assert conn
|> put_req_header("content-type", "application/json")
@@ -417,7 +417,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
"/api/pleroma/admin/config",
%{
configs: [
- %{group: ":pleroma", key: ":chat", value: [%{"tuple" => [":enabled", true]}]}
+ %{group: ":pleroma", key: ":shout", value: [%{"tuple" => [":enabled", true]}]}
]
}
)
@@ -426,7 +426,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
%{
"db" => [":enabled"],
"group" => ":pleroma",
- "key" => ":chat",
+ "key" => ":shout",
"value" => [%{"tuple" => [":enabled", true]}]
}
],
@@ -454,8 +454,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
end
test "update setting which need reboot, don't change reboot flag until reboot", %{conn: conn} do
- chat = Config.get(:chat)
- on_exit(fn -> Config.put(:chat, chat) end)
+ clear_config([:shout, :enabled], true)
assert conn
|> put_req_header("content-type", "application/json")
@@ -463,7 +462,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
"/api/pleroma/admin/config",
%{
configs: [
- %{group: ":pleroma", key: ":chat", value: [%{"tuple" => [":enabled", true]}]}
+ %{group: ":pleroma", key: ":shout", value: [%{"tuple" => [":enabled", true]}]}
]
}
)
@@ -472,7 +471,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
%{
"db" => [":enabled"],
"group" => ":pleroma",
- "key" => ":chat",
+ "key" => ":shout",
"value" => [%{"tuple" => [":enabled", true]}]
}
],
@@ -1411,15 +1410,84 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
"need_reboot" => false
}
end
+
+ test "custom instance thumbnail", %{conn: conn} do
+ clear_config([:instance])
+
+ params = %{
+ "group" => ":pleroma",
+ "key" => ":instance",
+ "value" => [
+ %{
+ "tuple" => [
+ ":instance_thumbnail",
+ "https://example.com/media/new_thumbnail.jpg"
+ ]
+ }
+ ]
+ }
+
+ assert conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/pleroma/admin/config", %{"configs" => [params]})
+ |> json_response_and_validate_schema(200) ==
+ %{
+ "configs" => [
+ %{
+ "db" => [":instance_thumbnail"],
+ "group" => ":pleroma",
+ "key" => ":instance",
+ "value" => params["value"]
+ }
+ ],
+ "need_reboot" => false
+ }
+
+ assert conn
+ |> get("/api/v1/instance")
+ |> json_response_and_validate_schema(200)
+ |> Map.take(["thumbnail"]) ==
+ %{"thumbnail" => "https://example.com/media/new_thumbnail.jpg"}
+ end
+
+ test "Concurrent Limiter", %{conn: conn} do
+ clear_config([ConcurrentLimiter])
+
+ params = %{
+ "group" => ":pleroma",
+ "key" => "ConcurrentLimiter",
+ "value" => [
+ %{
+ "tuple" => [
+ "Pleroma.Web.RichMedia.Helpers",
+ [
+ %{"tuple" => [":max_running", 6]},
+ %{"tuple" => [":max_waiting", 6]}
+ ]
+ ]
+ },
+ %{
+ "tuple" => [
+ "Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicy",
+ [
+ %{"tuple" => [":max_running", 7]},
+ %{"tuple" => [":max_waiting", 7]}
+ ]
+ ]
+ }
+ ]
+ }
+
+ assert conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/pleroma/admin/config", %{"configs" => [params]})
+ |> json_response_and_validate_schema(200)
+ end
end
describe "GET /api/pleroma/admin/config/descriptions" do
test "structure", %{conn: conn} do
- admin = insert(:user, is_admin: true)
-
- conn =
- assign(conn, :user, admin)
- |> get("/api/pleroma/admin/config/descriptions")
+ conn = get(conn, "/api/pleroma/admin/config/descriptions")
assert [child | _others] = json_response_and_validate_schema(conn, 200)
@@ -1437,11 +1505,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
{:esshd}
])
- admin = insert(:user, is_admin: true)
-
- conn =
- assign(conn, :user, admin)
- |> get("/api/pleroma/admin/config/descriptions")
+ conn = get(conn, "/api/pleroma/admin/config/descriptions")
children = json_response_and_validate_schema(conn, 200)