1
0
mirror of https://git.pleroma.social/sjw/pleroma.git synced 2024-11-12 00:59:04 +01:00

Fix regex breaking listing in admin api and add a test for it

This commit is contained in:
rinpatch 2019-04-05 11:04:15 +03:00
parent 594f8dca20
commit 56013408e0
3 changed files with 40 additions and 25 deletions

View File

@ -100,33 +100,25 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicy do
end end
end end
def list_keyword_policy, do: Pleroma.Config.get(:mrf_keyword) def list_keyword_policy do
def nodeinfo_keyword_policy do
Pleroma.Config.get(:mrf_keyword, []) Pleroma.Config.get(:mrf_keyword, [])
|> Enum.map(fn {key, value} -> |> Enum.reduce(%{}, fn {key, value}, acc ->
{key, base = if is_map(value), do: %{}, else: []
Enum.map(value, fn
{pattern, replacement} ->
%{
"pattern" =>
if not is_binary(pattern) do
inspect(pattern)
else
pattern
end,
"replacement" => replacement
}
pattern -> value =
if not is_binary(pattern) do Enum.reduce(value, base, fn
inspect(pattern) {pattern, replacement}, acc ->
else pattern = unless is_binary(pattern), do: inspect(pattern), else: pattern
pattern Map.put(acc, pattern, replacement)
end
end)} pattern, acc ->
pattern = unless is_binary(pattern), do: inspect(pattern), else: pattern
acc ++ [pattern]
end)
Map.put(acc, key, value)
end) end)
|> Enum.into(%{})
end end
@impl true @impl true

View File

@ -45,7 +45,7 @@ defmodule Pleroma.Web.Nodeinfo.NodeinfoController do
Application.get_env(:pleroma, :mrf_simple) Application.get_env(:pleroma, :mrf_simple)
|> Enum.into(%{}) |> Enum.into(%{})
mrf_keyword = KeywordPolicy.nodeinfo_keyword_policy() mrf_keyword = KeywordPolicy.list_keyword_policy()
mrf_policies = mrf_policies =
MRF.get_policies() MRF.get_policies()

View File

@ -596,4 +596,27 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
"tags" => [] "tags" => []
} }
end end
describe "KeywordPolicy" do
test "GET /api/pleroma/admin/mrf/keyword_policy/list" do
Pleroma.Config.put([:mrf_keyword], %{
reject: [~r/(rof)?lmao/, "yikes!"],
federated_timeline_removal: ["umm spaghetti", ~r/[OoUu]w[OoUu]/],
replace: %{~r/bloat(ed)?/ => "\\0 :rokalife:", "karen" => "kawen"}
})
admin = insert(:user, info: %{is_admin: true})
conn =
build_conn()
|> assign(:user, admin)
|> get("/api/pleroma/admin/mrf/keyword_policy/list")
assert json_response(conn, 200) == %{
"federated_timeline_removal" => ["umm spaghetti", "~r/[OoUu]w[OoUu]/"],
"reject" => ["~r/(rof)?lmao/", "yikes!"],
"replace" => %{"karen" => "kawen", "~r/bloat(ed)?/" => "\\0 :rokalife:"}
}
end
end
end end