mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2024-12-23 16:40:29 +00:00
Add OpenApi spec to AdminAPI.ConfigController
This commit is contained in:
parent
d1ee3527ef
commit
06f20e9181
3 changed files with 259 additions and 68 deletions
|
@ -11,23 +11,26 @@ defmodule Pleroma.Web.AdminAPI.ConfigController do
|
||||||
|
|
||||||
@descriptions Pleroma.Docs.JSON.compile()
|
@descriptions Pleroma.Docs.JSON.compile()
|
||||||
|
|
||||||
|
plug(Pleroma.Web.ApiSpec.CastAndValidate)
|
||||||
|
plug(OAuthScopesPlug, %{scopes: ["write"], admin: true} when action == :update)
|
||||||
|
|
||||||
plug(
|
plug(
|
||||||
OAuthScopesPlug,
|
OAuthScopesPlug,
|
||||||
%{scopes: ["read"], admin: true}
|
%{scopes: ["read"], admin: true}
|
||||||
when action in [:show, :descriptions]
|
when action in [:show, :descriptions]
|
||||||
)
|
)
|
||||||
|
|
||||||
plug(OAuthScopesPlug, %{scopes: ["write"], admin: true} when action == :update)
|
|
||||||
|
|
||||||
action_fallback(Pleroma.Web.AdminAPI.FallbackController)
|
action_fallback(Pleroma.Web.AdminAPI.FallbackController)
|
||||||
|
|
||||||
|
defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.Admin.ConfigOperation
|
||||||
|
|
||||||
def descriptions(conn, _params) do
|
def descriptions(conn, _params) do
|
||||||
descriptions = Enum.filter(@descriptions, &whitelisted_config?/1)
|
descriptions = Enum.filter(@descriptions, &whitelisted_config?/1)
|
||||||
|
|
||||||
json(conn, descriptions)
|
json(conn, descriptions)
|
||||||
end
|
end
|
||||||
|
|
||||||
def show(conn, %{"only_db" => true}) do
|
def show(conn, %{only_db: true}) do
|
||||||
with :ok <- configurable_from_database() do
|
with :ok <- configurable_from_database() do
|
||||||
configs = Pleroma.Repo.all(ConfigDB)
|
configs = Pleroma.Repo.all(ConfigDB)
|
||||||
render(conn, "index.json", %{configs: configs})
|
render(conn, "index.json", %{configs: configs})
|
||||||
|
@ -73,16 +76,16 @@ defmodule Pleroma.Web.AdminAPI.ConfigController do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def update(conn, %{"configs" => configs}) do
|
def update(%{body_params: %{configs: configs}} = conn, _) do
|
||||||
with :ok <- configurable_from_database() do
|
with :ok <- configurable_from_database() do
|
||||||
results =
|
results =
|
||||||
configs
|
configs
|
||||||
|> Enum.filter(&whitelisted_config?/1)
|
|> Enum.filter(&whitelisted_config?/1)
|
||||||
|> Enum.map(fn
|
|> Enum.map(fn
|
||||||
%{"group" => group, "key" => key, "delete" => true} = params ->
|
%{group: group, key: key, delete: true} = params ->
|
||||||
ConfigDB.delete(%{group: group, key: key, subkeys: params["subkeys"]})
|
ConfigDB.delete(%{group: group, key: key, subkeys: params[:subkeys]})
|
||||||
|
|
||||||
%{"group" => group, "key" => key, "value" => value} ->
|
%{group: group, key: key, value: value} ->
|
||||||
ConfigDB.update_or_create(%{group: group, key: key, value: value})
|
ConfigDB.update_or_create(%{group: group, key: key, value: value})
|
||||||
end)
|
end)
|
||||||
|> Enum.reject(fn {result, _} -> result == :error end)
|
|> Enum.reject(fn {result, _} -> result == :error end)
|
||||||
|
@ -140,11 +143,11 @@ defmodule Pleroma.Web.AdminAPI.ConfigController do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp whitelisted_config?(%{"group" => group, "key" => key}) do
|
defp whitelisted_config?(%{group: group, key: key}) do
|
||||||
whitelisted_config?(group, key)
|
whitelisted_config?(group, key)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp whitelisted_config?(%{:group => group} = config) do
|
defp whitelisted_config?(%{group: group} = config) do
|
||||||
whitelisted_config?(group, config[:key])
|
whitelisted_config?(group, config[:key])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
142
lib/pleroma/web/api_spec/operations/admin/config_operation.ex
Normal file
142
lib/pleroma/web/api_spec/operations/admin/config_operation.ex
Normal file
|
@ -0,0 +1,142 @@
|
||||||
|
# Pleroma: A lightweight social networking server
|
||||||
|
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||||
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
defmodule Pleroma.Web.ApiSpec.Admin.ConfigOperation do
|
||||||
|
alias OpenApiSpex.Operation
|
||||||
|
alias OpenApiSpex.Schema
|
||||||
|
alias Pleroma.Web.ApiSpec.Schemas.ApiError
|
||||||
|
|
||||||
|
import Pleroma.Web.ApiSpec.Helpers
|
||||||
|
|
||||||
|
def open_api_operation(action) do
|
||||||
|
operation = String.to_existing_atom("#{action}_operation")
|
||||||
|
apply(__MODULE__, operation, [])
|
||||||
|
end
|
||||||
|
|
||||||
|
def show_operation do
|
||||||
|
%Operation{
|
||||||
|
tags: ["Admin", "Config"],
|
||||||
|
summary: "Get list of merged default settings with saved in database",
|
||||||
|
operationId: "AdminAPI.ConfigController.show",
|
||||||
|
parameters: [
|
||||||
|
Operation.parameter(
|
||||||
|
:only_db,
|
||||||
|
:query,
|
||||||
|
%Schema{type: :boolean, default: false},
|
||||||
|
"Get only saved in database settings"
|
||||||
|
)
|
||||||
|
],
|
||||||
|
security: [%{"oAuth" => ["read"]}],
|
||||||
|
responses: %{
|
||||||
|
200 => Operation.response("Config", "application/json", config_response()),
|
||||||
|
400 => Operation.response("Bad Request", "application/json", ApiError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_operation do
|
||||||
|
%Operation{
|
||||||
|
tags: ["Admin", "Config"],
|
||||||
|
summary: "Update config settings",
|
||||||
|
operationId: "AdminAPI.ConfigController.update",
|
||||||
|
security: [%{"oAuth" => ["write"]}],
|
||||||
|
requestBody:
|
||||||
|
request_body("Parameters", %Schema{
|
||||||
|
type: :object,
|
||||||
|
properties: %{
|
||||||
|
configs: %Schema{
|
||||||
|
type: :array,
|
||||||
|
items: %Schema{
|
||||||
|
type: :object,
|
||||||
|
properties: %{
|
||||||
|
group: %Schema{type: :string},
|
||||||
|
key: %Schema{type: :string},
|
||||||
|
value: any(),
|
||||||
|
delete: %Schema{type: :boolean},
|
||||||
|
subkeys: %Schema{type: :array, items: %Schema{type: :string}}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
responses: %{
|
||||||
|
200 => Operation.response("Config", "application/json", config_response()),
|
||||||
|
400 => Operation.response("Bad Request", "application/json", ApiError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def descriptions_operation do
|
||||||
|
%Operation{
|
||||||
|
tags: ["Admin", "Config"],
|
||||||
|
summary: "Get JSON with config descriptions.",
|
||||||
|
operationId: "AdminAPI.ConfigController.descriptions",
|
||||||
|
security: [%{"oAuth" => ["read"]}],
|
||||||
|
responses: %{
|
||||||
|
200 =>
|
||||||
|
Operation.response("Config Descriptions", "application/json", %Schema{
|
||||||
|
type: :array,
|
||||||
|
items: %Schema{
|
||||||
|
type: :object,
|
||||||
|
properties: %{
|
||||||
|
group: %Schema{type: :string},
|
||||||
|
key: %Schema{type: :string},
|
||||||
|
type: %Schema{oneOf: [%Schema{type: :string}, %Schema{type: :array}]},
|
||||||
|
description: %Schema{type: :string},
|
||||||
|
children: %Schema{
|
||||||
|
type: :array,
|
||||||
|
items: %Schema{
|
||||||
|
type: :object,
|
||||||
|
properties: %{
|
||||||
|
key: %Schema{type: :string},
|
||||||
|
type: %Schema{oneOf: [%Schema{type: :string}, %Schema{type: :array}]},
|
||||||
|
description: %Schema{type: :string},
|
||||||
|
suggestions: %Schema{type: :array}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
400 => Operation.response("Bad Request", "application/json", ApiError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
defp any do
|
||||||
|
%Schema{
|
||||||
|
oneOf: [
|
||||||
|
%Schema{type: :array},
|
||||||
|
%Schema{type: :object},
|
||||||
|
%Schema{type: :string},
|
||||||
|
%Schema{type: :integer},
|
||||||
|
%Schema{type: :boolean}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
defp config_response do
|
||||||
|
%Schema{
|
||||||
|
type: :object,
|
||||||
|
properties: %{
|
||||||
|
configs: %Schema{
|
||||||
|
type: :array,
|
||||||
|
items: %Schema{
|
||||||
|
type: :object,
|
||||||
|
properties: %{
|
||||||
|
group: %Schema{type: :string},
|
||||||
|
key: %Schema{type: :string},
|
||||||
|
value: any()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
need_reboot: %Schema{
|
||||||
|
type: :boolean,
|
||||||
|
description:
|
||||||
|
"If `need_reboot` is `true`, instance must be restarted, so reboot time settings can take effect"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
|
@ -30,7 +30,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
||||||
Config.put(:configurable_from_database, false)
|
Config.put(:configurable_from_database, false)
|
||||||
conn = get(conn, "/api/pleroma/admin/config")
|
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."
|
"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)
|
config1 = insert(:config)
|
||||||
config2 = 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" => [
|
"configs" => [
|
||||||
|
@ -55,7 +55,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
||||||
"value" => _
|
"value" => _
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
} = json_response(conn, 200)
|
} = json_response_and_validate_schema(conn, 200)
|
||||||
|
|
||||||
assert key1 == config1.key
|
assert key1 == config1.key
|
||||||
assert key2 == config2.key
|
assert key2 == config2.key
|
||||||
|
@ -67,7 +67,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
||||||
%{"configs" => configs} =
|
%{"configs" => configs} =
|
||||||
conn
|
conn
|
||||||
|> get("/api/pleroma/admin/config")
|
|> get("/api/pleroma/admin/config")
|
||||||
|> json_response(200)
|
|> json_response_and_validate_schema(200)
|
||||||
|
|
||||||
[instance_config] =
|
[instance_config] =
|
||||||
Enum.filter(configs, fn %{"group" => group, "key" => key} ->
|
Enum.filter(configs, fn %{"group" => group, "key" => key} ->
|
||||||
|
@ -89,7 +89,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
||||||
%{"configs" => configs} =
|
%{"configs" => configs} =
|
||||||
conn
|
conn
|
||||||
|> get("/api/pleroma/admin/config")
|
|> get("/api/pleroma/admin/config")
|
||||||
|> json_response(200)
|
|> json_response_and_validate_schema(200)
|
||||||
|
|
||||||
assert length(configs) > 3
|
assert length(configs) > 3
|
||||||
|
|
||||||
|
@ -133,7 +133,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
||||||
%{"configs" => configs} =
|
%{"configs" => configs} =
|
||||||
conn
|
conn
|
||||||
|> get("/api/pleroma/admin/config")
|
|> get("/api/pleroma/admin/config")
|
||||||
|> json_response(200)
|
|> json_response_and_validate_schema(200)
|
||||||
|
|
||||||
vals =
|
vals =
|
||||||
Enum.filter(configs, fn %{"group" => group, "key" => key} ->
|
Enum.filter(configs, fn %{"group" => group, "key" => key} ->
|
||||||
|
@ -152,9 +152,12 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "POST /api/pleroma/admin/config error", %{conn: conn} do
|
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."}
|
%{"error" => "To use this endpoint you need to enable configuration from database."}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -185,7 +188,9 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
||||||
on_exit(fn -> Application.put_env(:ueberauth, Ueberauth, ueberauth) end)
|
on_exit(fn -> Application.put_env(:ueberauth, Ueberauth, ueberauth) end)
|
||||||
|
|
||||||
conn =
|
conn =
|
||||||
post(conn, "/api/pleroma/admin/config", %{
|
conn
|
||||||
|
|> put_req_header("content-type", "application/json")
|
||||||
|
|> post("/api/pleroma/admin/config", %{
|
||||||
configs: [
|
configs: [
|
||||||
%{group: ":pleroma", key: ":key1", value: "value1"},
|
%{group: ":pleroma", key: ":key1", value: "value1"},
|
||||||
%{
|
%{
|
||||||
|
@ -225,7 +230,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
assert json_response(conn, 200) == %{
|
assert json_response_and_validate_schema(conn, 200) == %{
|
||||||
"configs" => [
|
"configs" => [
|
||||||
%{
|
%{
|
||||||
"group" => ":pleroma",
|
"group" => ":pleroma",
|
||||||
|
@ -310,7 +315,9 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
||||||
end)
|
end)
|
||||||
|
|
||||||
conn =
|
conn =
|
||||||
post(conn, "/api/pleroma/admin/config", %{
|
conn
|
||||||
|
|> put_req_header("content-type", "application/json")
|
||||||
|
|> post("/api/pleroma/admin/config", %{
|
||||||
configs: [
|
configs: [
|
||||||
%{
|
%{
|
||||||
group: ":quack",
|
group: ":quack",
|
||||||
|
@ -330,7 +337,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
assert json_response(conn, 200) == %{
|
assert json_response_and_validate_schema(conn, 200) == %{
|
||||||
"configs" => [
|
"configs" => [
|
||||||
%{
|
%{
|
||||||
"group" => ":quack",
|
"group" => ":quack",
|
||||||
|
@ -362,13 +369,15 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
||||||
config = insert(:config, key: ":key1", value: :erlang.term_to_binary(key1: 1, key2: 2))
|
config = insert(:config, key: ":key1", value: :erlang.term_to_binary(key1: 1, key2: 2))
|
||||||
|
|
||||||
conn =
|
conn =
|
||||||
post(conn, "/api/pleroma/admin/config", %{
|
conn
|
||||||
|
|> put_req_header("content-type", "application/json")
|
||||||
|
|> post("/api/pleroma/admin/config", %{
|
||||||
configs: [
|
configs: [
|
||||||
%{group: config.group, key: config.key, value: [%{"tuple" => [":key3", 3]}]}
|
%{group: config.group, key: config.key, value: [%{"tuple" => [":key3", 3]}]}
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
assert json_response(conn, 200) == %{
|
assert json_response_and_validate_schema(conn, 200) == %{
|
||||||
"configs" => [
|
"configs" => [
|
||||||
%{
|
%{
|
||||||
"group" => ":pleroma",
|
"group" => ":pleroma",
|
||||||
|
@ -388,8 +397,9 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
||||||
chat = Config.get(:chat)
|
chat = Config.get(:chat)
|
||||||
on_exit(fn -> Config.put(:chat, chat) end)
|
on_exit(fn -> Config.put(:chat, chat) end)
|
||||||
|
|
||||||
assert post(
|
assert conn
|
||||||
conn,
|
|> put_req_header("content-type", "application/json")
|
||||||
|
|> post(
|
||||||
"/api/pleroma/admin/config",
|
"/api/pleroma/admin/config",
|
||||||
%{
|
%{
|
||||||
configs: [
|
configs: [
|
||||||
|
@ -397,7 +407,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|> json_response(200) == %{
|
|> json_response_and_validate_schema(200) == %{
|
||||||
"configs" => [
|
"configs" => [
|
||||||
%{
|
%{
|
||||||
"db" => [":enabled"],
|
"db" => [":enabled"],
|
||||||
|
@ -412,18 +422,19 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
||||||
configs =
|
configs =
|
||||||
conn
|
conn
|
||||||
|> get("/api/pleroma/admin/config")
|
|> get("/api/pleroma/admin/config")
|
||||||
|> json_response(200)
|
|> json_response_and_validate_schema(200)
|
||||||
|
|
||||||
assert configs["need_reboot"]
|
assert configs["need_reboot"]
|
||||||
|
|
||||||
capture_log(fn ->
|
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"
|
end) =~ "pleroma restarted"
|
||||||
|
|
||||||
configs =
|
configs =
|
||||||
conn
|
conn
|
||||||
|> get("/api/pleroma/admin/config")
|
|> get("/api/pleroma/admin/config")
|
||||||
|> json_response(200)
|
|> json_response_and_validate_schema(200)
|
||||||
|
|
||||||
assert configs["need_reboot"] == false
|
assert configs["need_reboot"] == false
|
||||||
end
|
end
|
||||||
|
@ -432,8 +443,9 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
||||||
chat = Config.get(:chat)
|
chat = Config.get(:chat)
|
||||||
on_exit(fn -> Config.put(:chat, chat) end)
|
on_exit(fn -> Config.put(:chat, chat) end)
|
||||||
|
|
||||||
assert post(
|
assert conn
|
||||||
conn,
|
|> put_req_header("content-type", "application/json")
|
||||||
|
|> post(
|
||||||
"/api/pleroma/admin/config",
|
"/api/pleroma/admin/config",
|
||||||
%{
|
%{
|
||||||
configs: [
|
configs: [
|
||||||
|
@ -441,7 +453,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|> json_response(200) == %{
|
|> json_response_and_validate_schema(200) == %{
|
||||||
"configs" => [
|
"configs" => [
|
||||||
%{
|
%{
|
||||||
"db" => [":enabled"],
|
"db" => [":enabled"],
|
||||||
|
@ -453,12 +465,14 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
||||||
"need_reboot" => true
|
"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: [
|
configs: [
|
||||||
%{group: ":pleroma", key: ":key1", value: [%{"tuple" => [":key3", 3]}]}
|
%{group: ":pleroma", key: ":key1", value: [%{"tuple" => [":key3", 3]}]}
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|> json_response(200) == %{
|
|> json_response_and_validate_schema(200) == %{
|
||||||
"configs" => [
|
"configs" => [
|
||||||
%{
|
%{
|
||||||
"group" => ":pleroma",
|
"group" => ":pleroma",
|
||||||
|
@ -473,13 +487,14 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
||||||
}
|
}
|
||||||
|
|
||||||
capture_log(fn ->
|
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"
|
end) =~ "pleroma restarted"
|
||||||
|
|
||||||
configs =
|
configs =
|
||||||
conn
|
conn
|
||||||
|> get("/api/pleroma/admin/config")
|
|> get("/api/pleroma/admin/config")
|
||||||
|> json_response(200)
|
|> json_response_and_validate_schema(200)
|
||||||
|
|
||||||
assert configs["need_reboot"] == false
|
assert configs["need_reboot"] == false
|
||||||
end
|
end
|
||||||
|
@ -489,7 +504,9 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
||||||
insert(:config, key: ":key1", value: :erlang.term_to_binary(key1: 1, key2: [k1: 1, k2: 2]))
|
insert(:config, key: ":key1", value: :erlang.term_to_binary(key1: 1, key2: [k1: 1, k2: 2]))
|
||||||
|
|
||||||
conn =
|
conn =
|
||||||
post(conn, "/api/pleroma/admin/config", %{
|
conn
|
||||||
|
|> put_req_header("content-type", "application/json")
|
||||||
|
|> post("/api/pleroma/admin/config", %{
|
||||||
configs: [
|
configs: [
|
||||||
%{
|
%{
|
||||||
group: config.group,
|
group: config.group,
|
||||||
|
@ -510,7 +527,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
assert json_response(conn, 200) == %{
|
assert json_response_and_validate_schema(conn, 200) == %{
|
||||||
"configs" => [
|
"configs" => [
|
||||||
%{
|
%{
|
||||||
"group" => ":pleroma",
|
"group" => ":pleroma",
|
||||||
|
@ -537,7 +554,9 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
||||||
|
|
||||||
test "saving special atoms", %{conn: conn} do
|
test "saving special atoms", %{conn: conn} do
|
||||||
conn =
|
conn =
|
||||||
post(conn, "/api/pleroma/admin/config", %{
|
conn
|
||||||
|
|> put_req_header("content-type", "application/json")
|
||||||
|
|> post("/api/pleroma/admin/config", %{
|
||||||
"configs" => [
|
"configs" => [
|
||||||
%{
|
%{
|
||||||
"group" => ":pleroma",
|
"group" => ":pleroma",
|
||||||
|
@ -554,7 +573,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
assert json_response(conn, 200) == %{
|
assert json_response_and_validate_schema(conn, 200) == %{
|
||||||
"configs" => [
|
"configs" => [
|
||||||
%{
|
%{
|
||||||
"group" => ":pleroma",
|
"group" => ":pleroma",
|
||||||
|
@ -593,7 +612,9 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
||||||
assert Application.get_env(:logger, :backends) == []
|
assert Application.get_env(:logger, :backends) == []
|
||||||
|
|
||||||
conn =
|
conn =
|
||||||
post(conn, "/api/pleroma/admin/config", %{
|
conn
|
||||||
|
|> put_req_header("content-type", "application/json")
|
||||||
|
|> post("/api/pleroma/admin/config", %{
|
||||||
configs: [
|
configs: [
|
||||||
%{
|
%{
|
||||||
group: config.group,
|
group: config.group,
|
||||||
|
@ -603,7 +624,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
assert json_response(conn, 200) == %{
|
assert json_response_and_validate_schema(conn, 200) == %{
|
||||||
"configs" => [
|
"configs" => [
|
||||||
%{
|
%{
|
||||||
"group" => ":logger",
|
"group" => ":logger",
|
||||||
|
@ -630,13 +651,15 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
||||||
)
|
)
|
||||||
|
|
||||||
conn =
|
conn =
|
||||||
post(conn, "/api/pleroma/admin/config", %{
|
conn
|
||||||
|
|> put_req_header("content-type", "application/json")
|
||||||
|
|> post("/api/pleroma/admin/config", %{
|
||||||
configs: [
|
configs: [
|
||||||
%{group: config.group, key: config.key, value: "Tesla.Adapter.Httpc"}
|
%{group: config.group, key: config.key, value: "Tesla.Adapter.Httpc"}
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
assert json_response(conn, 200) == %{
|
assert json_response_and_validate_schema(conn, 200) == %{
|
||||||
"configs" => [
|
"configs" => [
|
||||||
%{
|
%{
|
||||||
"group" => ":tesla",
|
"group" => ":tesla",
|
||||||
|
@ -664,14 +687,16 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
||||||
)
|
)
|
||||||
|
|
||||||
conn =
|
conn =
|
||||||
post(conn, "/api/pleroma/admin/config", %{
|
conn
|
||||||
|
|> put_req_header("content-type", "application/json")
|
||||||
|
|> post("/api/pleroma/admin/config", %{
|
||||||
configs: [
|
configs: [
|
||||||
%{group: config1.group, key: config1.key, value: "another_value"},
|
%{group: config1.group, key: config1.key, value: "another_value"},
|
||||||
%{group: config2.group, key: config2.key, value: "another_value"}
|
%{group: config2.group, key: config2.key, value: "another_value"}
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
assert json_response(conn, 200) == %{
|
assert json_response_and_validate_schema(conn, 200) == %{
|
||||||
"configs" => [
|
"configs" => [
|
||||||
%{
|
%{
|
||||||
"group" => ":pleroma",
|
"group" => ":pleroma",
|
||||||
|
@ -696,6 +721,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
||||||
build_conn()
|
build_conn()
|
||||||
|> assign(:user, admin)
|
|> assign(:user, admin)
|
||||||
|> assign(:token, token)
|
|> assign(:token, token)
|
||||||
|
|> put_req_header("content-type", "application/json")
|
||||||
|> post("/api/pleroma/admin/config", %{
|
|> post("/api/pleroma/admin/config", %{
|
||||||
configs: [
|
configs: [
|
||||||
%{group: config2.group, key: config2.key, delete: true},
|
%{group: config2.group, key: config2.key, delete: true},
|
||||||
|
@ -707,7 +733,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
assert json_response(conn, 200) == %{
|
assert json_response_and_validate_schema(conn, 200) == %{
|
||||||
"configs" => []
|
"configs" => []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -717,7 +743,9 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
||||||
|
|
||||||
test "common config example", %{conn: conn} do
|
test "common config example", %{conn: conn} do
|
||||||
conn =
|
conn =
|
||||||
post(conn, "/api/pleroma/admin/config", %{
|
conn
|
||||||
|
|> put_req_header("content-type", "application/json")
|
||||||
|
|> post("/api/pleroma/admin/config", %{
|
||||||
configs: [
|
configs: [
|
||||||
%{
|
%{
|
||||||
"group" => ":pleroma",
|
"group" => ":pleroma",
|
||||||
|
@ -741,7 +769,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
||||||
|
|
||||||
assert Config.get([Pleroma.Captcha.NotReal, :name]) == "Pleroma"
|
assert Config.get([Pleroma.Captcha.NotReal, :name]) == "Pleroma"
|
||||||
|
|
||||||
assert json_response(conn, 200) == %{
|
assert json_response_and_validate_schema(conn, 200) == %{
|
||||||
"configs" => [
|
"configs" => [
|
||||||
%{
|
%{
|
||||||
"group" => ":pleroma",
|
"group" => ":pleroma",
|
||||||
|
@ -779,7 +807,9 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
||||||
|
|
||||||
test "tuples with more than two values", %{conn: conn} do
|
test "tuples with more than two values", %{conn: conn} do
|
||||||
conn =
|
conn =
|
||||||
post(conn, "/api/pleroma/admin/config", %{
|
conn
|
||||||
|
|> put_req_header("content-type", "application/json")
|
||||||
|
|> post("/api/pleroma/admin/config", %{
|
||||||
configs: [
|
configs: [
|
||||||
%{
|
%{
|
||||||
"group" => ":pleroma",
|
"group" => ":pleroma",
|
||||||
|
@ -843,7 +873,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
assert json_response(conn, 200) == %{
|
assert json_response_and_validate_schema(conn, 200) == %{
|
||||||
"configs" => [
|
"configs" => [
|
||||||
%{
|
%{
|
||||||
"group" => ":pleroma",
|
"group" => ":pleroma",
|
||||||
|
@ -911,7 +941,9 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
||||||
|
|
||||||
test "settings with nesting map", %{conn: conn} do
|
test "settings with nesting map", %{conn: conn} do
|
||||||
conn =
|
conn =
|
||||||
post(conn, "/api/pleroma/admin/config", %{
|
conn
|
||||||
|
|> put_req_header("content-type", "application/json")
|
||||||
|
|> post("/api/pleroma/admin/config", %{
|
||||||
configs: [
|
configs: [
|
||||||
%{
|
%{
|
||||||
"group" => ":pleroma",
|
"group" => ":pleroma",
|
||||||
|
@ -940,7 +972,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
assert json_response(conn, 200) ==
|
assert json_response_and_validate_schema(conn, 200) ==
|
||||||
%{
|
%{
|
||||||
"configs" => [
|
"configs" => [
|
||||||
%{
|
%{
|
||||||
|
@ -974,7 +1006,9 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
||||||
|
|
||||||
test "value as map", %{conn: conn} do
|
test "value as map", %{conn: conn} do
|
||||||
conn =
|
conn =
|
||||||
post(conn, "/api/pleroma/admin/config", %{
|
conn
|
||||||
|
|> put_req_header("content-type", "application/json")
|
||||||
|
|> post("/api/pleroma/admin/config", %{
|
||||||
configs: [
|
configs: [
|
||||||
%{
|
%{
|
||||||
"group" => ":pleroma",
|
"group" => ":pleroma",
|
||||||
|
@ -984,7 +1018,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
assert json_response(conn, 200) ==
|
assert json_response_and_validate_schema(conn, 200) ==
|
||||||
%{
|
%{
|
||||||
"configs" => [
|
"configs" => [
|
||||||
%{
|
%{
|
||||||
|
@ -999,7 +1033,9 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
||||||
|
|
||||||
test "queues key as atom", %{conn: conn} do
|
test "queues key as atom", %{conn: conn} do
|
||||||
conn =
|
conn =
|
||||||
post(conn, "/api/pleroma/admin/config", %{
|
conn
|
||||||
|
|> put_req_header("content-type", "application/json")
|
||||||
|
|> post("/api/pleroma/admin/config", %{
|
||||||
configs: [
|
configs: [
|
||||||
%{
|
%{
|
||||||
"group" => ":oban",
|
"group" => ":oban",
|
||||||
|
@ -1017,7 +1053,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
assert json_response(conn, 200) == %{
|
assert json_response_and_validate_schema(conn, 200) == %{
|
||||||
"configs" => [
|
"configs" => [
|
||||||
%{
|
%{
|
||||||
"group" => ":oban",
|
"group" => ":oban",
|
||||||
|
@ -1053,7 +1089,9 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
||||||
)
|
)
|
||||||
|
|
||||||
conn =
|
conn =
|
||||||
post(conn, "/api/pleroma/admin/config", %{
|
conn
|
||||||
|
|> put_req_header("content-type", "application/json")
|
||||||
|
|> post("/api/pleroma/admin/config", %{
|
||||||
configs: [
|
configs: [
|
||||||
%{
|
%{
|
||||||
group: config.group,
|
group: config.group,
|
||||||
|
@ -1064,7 +1102,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
assert json_response(conn, 200) == %{
|
assert json_response_and_validate_schema(conn, 200) == %{
|
||||||
"configs" => [
|
"configs" => [
|
||||||
%{
|
%{
|
||||||
"group" => ":pleroma",
|
"group" => ":pleroma",
|
||||||
|
@ -1078,7 +1116,9 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
||||||
|
|
||||||
test "proxy tuple localhost", %{conn: conn} do
|
test "proxy tuple localhost", %{conn: conn} do
|
||||||
conn =
|
conn =
|
||||||
post(conn, "/api/pleroma/admin/config", %{
|
conn
|
||||||
|
|> put_req_header("content-type", "application/json")
|
||||||
|
|> post("/api/pleroma/admin/config", %{
|
||||||
configs: [
|
configs: [
|
||||||
%{
|
%{
|
||||||
group: ":pleroma",
|
group: ":pleroma",
|
||||||
|
@ -1099,7 +1139,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
||||||
"db" => db
|
"db" => db
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
} = json_response(conn, 200)
|
} = json_response_and_validate_schema(conn, 200)
|
||||||
|
|
||||||
assert %{"tuple" => [":proxy_url", %{"tuple" => [":socks5", "localhost", 1234]}]} in value
|
assert %{"tuple" => [":proxy_url", %{"tuple" => [":socks5", "localhost", 1234]}]} in value
|
||||||
assert ":proxy_url" in db
|
assert ":proxy_url" in db
|
||||||
|
@ -1107,7 +1147,9 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
||||||
|
|
||||||
test "proxy tuple domain", %{conn: conn} do
|
test "proxy tuple domain", %{conn: conn} do
|
||||||
conn =
|
conn =
|
||||||
post(conn, "/api/pleroma/admin/config", %{
|
conn
|
||||||
|
|> put_req_header("content-type", "application/json")
|
||||||
|
|> post("/api/pleroma/admin/config", %{
|
||||||
configs: [
|
configs: [
|
||||||
%{
|
%{
|
||||||
group: ":pleroma",
|
group: ":pleroma",
|
||||||
|
@ -1128,7 +1170,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
||||||
"db" => db
|
"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 %{"tuple" => [":proxy_url", %{"tuple" => [":socks5", "domain.com", 1234]}]} in value
|
||||||
assert ":proxy_url" in db
|
assert ":proxy_url" in db
|
||||||
|
@ -1136,7 +1178,9 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
||||||
|
|
||||||
test "proxy tuple ip", %{conn: conn} do
|
test "proxy tuple ip", %{conn: conn} do
|
||||||
conn =
|
conn =
|
||||||
post(conn, "/api/pleroma/admin/config", %{
|
conn
|
||||||
|
|> put_req_header("content-type", "application/json")
|
||||||
|
|> post("/api/pleroma/admin/config", %{
|
||||||
configs: [
|
configs: [
|
||||||
%{
|
%{
|
||||||
group: ":pleroma",
|
group: ":pleroma",
|
||||||
|
@ -1157,7 +1201,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
||||||
"db" => db
|
"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 %{"tuple" => [":proxy_url", %{"tuple" => [":socks5", "127.0.0.1", 1234]}]} in value
|
||||||
assert ":proxy_url" in db
|
assert ":proxy_url" in db
|
||||||
|
@ -1172,7 +1216,9 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
||||||
{:not_real}
|
{:not_real}
|
||||||
])
|
])
|
||||||
|
|
||||||
post(conn, "/api/pleroma/admin/config", %{
|
conn
|
||||||
|
|> put_req_header("content-type", "application/json")
|
||||||
|
|> post("/api/pleroma/admin/config", %{
|
||||||
configs: [
|
configs: [
|
||||||
%{group: ":pleroma", key: ":key1", value: "value1"},
|
%{group: ":pleroma", key: ":key1", value: "value1"},
|
||||||
%{group: ":pleroma", key: ":key2", value: "value2"},
|
%{group: ":pleroma", key: ":key2", value: "value2"},
|
||||||
|
@ -1200,7 +1246,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
||||||
assign(conn, :user, admin)
|
assign(conn, :user, admin)
|
||||||
|> get("/api/pleroma/admin/config/descriptions")
|
|> 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["children"]
|
||||||
assert child["key"]
|
assert child["key"]
|
||||||
|
@ -1222,7 +1268,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
||||||
assign(conn, :user, admin)
|
assign(conn, :user, admin)
|
||||||
|> get("/api/pleroma/admin/config/descriptions")
|
|> get("/api/pleroma/admin/config/descriptions")
|
||||||
|
|
||||||
children = json_response(conn, 200)
|
children = json_response_and_validate_schema(conn, 200)
|
||||||
|
|
||||||
assert length(children) == 4
|
assert length(children) == 4
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue