From 9c1f3bfeffa7e40d319d931c975b948f33800c40 Mon Sep 17 00:00:00 2001 From: Alexander Date: Sat, 21 Dec 2019 13:54:22 +0300 Subject: [PATCH] fixes for logger backends --- lib/pleroma/web/admin_api/config.ex | 3 ++- test/web/admin_api/admin_api_controller_test.exs | 16 +++++++++++++--- test/web/admin_api/config_test.exs | 12 ++++++++++++ 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/lib/pleroma/web/admin_api/config.ex b/lib/pleroma/web/admin_api/config.ex index a8a698c89..ef658e079 100644 --- a/lib/pleroma/web/admin_api/config.ex +++ b/lib/pleroma/web/admin_api/config.ex @@ -295,7 +295,8 @@ defp do_transform_string(value) do @spec is_module_name?(String.t()) :: boolean() def is_module_name?(string) do - Regex.match?(~r/^(Pleroma|Phoenix|Tesla)\./, string) or string in ["Oban", "Ueberauth"] + Regex.match?(~r/^(Pleroma|Phoenix|Tesla|Quack)\./, string) or + string in ["Oban", "Ueberauth", "ExSyslogger"] end defp do_eval(entity) do diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs index 56a3a3a97..ea3c43158 100644 --- a/test/web/admin_api/admin_api_controller_test.exs +++ b/test/web/admin_api/admin_api_controller_test.exs @@ -2218,7 +2218,11 @@ test "saving full setting if value is in full_key_update list", %{conn: conn} do conn = post(conn, "/api/pleroma/admin/config", %{ configs: [ - %{group: config.group, key: config.key, value: [":console"]} + %{ + group: config.group, + key: config.key, + value: [":console", %{"tuple" => ["ExSyslogger", ":ex_syslogger"]}] + } ] }) @@ -2227,12 +2231,18 @@ test "saving full setting if value is in full_key_update list", %{conn: conn} do %{ "group" => ":logger", "key" => ":backends", - "value" => [":console"] + "value" => [ + ":console", + %{"tuple" => ["ExSyslogger", ":ex_syslogger"]} + ] } ] } - assert Application.get_env(:logger, :backends) == [:console] + assert Application.get_env(:logger, :backends) == [ + :console, + {ExSyslogger, :ex_syslogger} + ] ExUnit.CaptureLog.capture_log(fn -> require Logger diff --git a/test/web/admin_api/config_test.exs b/test/web/admin_api/config_test.exs index b8b1b0130..4f96322af 100644 --- a/test/web/admin_api/config_test.exs +++ b/test/web/admin_api/config_test.exs @@ -175,6 +175,18 @@ test "tesla module" do assert Config.from_binary(binary) == Tesla.Adapter.Hackney end + test "ExSyslogger module" do + binary = Config.transform("ExSyslogger") + assert binary == :erlang.term_to_binary(ExSyslogger) + assert Config.from_binary(binary) == ExSyslogger + end + + test "Quack.Logger module" do + binary = Config.transform("Quack.Logger") + assert binary == :erlang.term_to_binary(Quack.Logger) + assert Config.from_binary(binary) == Quack.Logger + end + test "sigil" do binary = Config.transform("~r[comp[lL][aA][iI][nN]er]") assert binary == :erlang.term_to_binary(~r/comp[lL][aA][iI][nN]er/)