quarantine instances info

Added a new field in the nodeinfo called quarantined_instances_info
This holds an object like `"quarantined_instances_info":{"quarantined_instances":{"quar.inst":{"reason":"whatever reason"}}}}`
This commit is contained in:
Ilja 2020-11-28 10:34:31 +01:00
parent f4092e96d1
commit d9dfe3d451
2 changed files with 42 additions and 12 deletions

View File

@ -91,7 +91,15 @@ defmodule Pleroma.Web.MastodonAPI.InstanceView do
|> Map.merge(%{ |> Map.merge(%{
quarantined_instances: quarantined_instances:
quarantined quarantined
|> Enum.map(fn {instance, reason} -> %{"instance" => instance, "reason" => reason} end) |> Enum.map(fn {instance, _reason} -> instance end)
})
|> Map.merge(%{
quarantined_instances_info: %{
"quarantined_instances" =>
quarantined
|> Enum.map(fn {instance, reason} -> {instance, %{"reason" => reason}} end)
|> Enum.into(%{})
}
}) })
else else
%{} %{}

View File

@ -152,13 +152,15 @@ defmodule Pleroma.Web.NodeInfoTest do
) )
end end
test "it shows quarantined instances data if enabled", %{conn: conn} do describe "Quarantined instances" do
setup do
clear_config([:mrf, :transparency], true) clear_config([:mrf, :transparency], true)
quarantined_instances = [{"example.com", "reason to quarantine"}]
quarantined_instances = [{"example.com", ""}]
clear_config([:instance, :quarantined_instances], quarantined_instances) clear_config([:instance, :quarantined_instances], quarantined_instances)
end
expected_config = [%{"instance" => "example.com", "reason" => ""}] test "shows quarantined instances data if enabled", %{conn: conn} do
expected_config = ["example.com"]
response = response =
conn conn
@ -168,6 +170,26 @@ defmodule Pleroma.Web.NodeInfoTest do
assert response["metadata"]["federation"]["quarantined_instances"] == expected_config assert response["metadata"]["federation"]["quarantined_instances"] == expected_config
end end
test "shows extra information in the quarantined_info field for relevant entries", %{
conn: conn
} do
clear_config([:mrf, :transparency], true)
expected_config = %{
"quarantined_instances" => %{
"example.com" => %{"reason" => "reason to quarantine"}
}
}
response =
conn
|> get("/nodeinfo/2.1.json")
|> json_response(:ok)
assert response["metadata"]["federation"]["quarantined_instances_info"] == expected_config
end
end
describe "MRF SimplePolicy" do describe "MRF SimplePolicy" do
setup do setup do
clear_config([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.SimplePolicy]) clear_config([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.SimplePolicy])
@ -207,7 +229,7 @@ defmodule Pleroma.Web.NodeInfoTest do
assert response["metadata"]["federation"]["exclusions"] == true assert response["metadata"]["federation"]["exclusions"] == true
end end
test "shows extra information in the mrf_simple_extra field for relevant entries", %{ test "shows extra information in the mrf_simple_info field for relevant entries", %{
conn: conn conn: conn
} do } do
simple_config = %{ simple_config = %{