quarantine instances info
authorIlja <domainepublic@spectraltheorem.be>
Sat, 28 Nov 2020 09:34:31 +0000 (10:34 +0100)
committerHaelwenn (lanodan) Monnier <contact@hacktivis.me>
Fri, 6 Aug 2021 05:59:53 +0000 (07:59 +0200)
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"}}}}`

lib/pleroma/web/mastodon_api/views/instance_view.ex
test/pleroma/web/node_info_test.exs

index db40ea3fab8f143cdc1092ffe587925950cc2290..a341ca6f4a4f11eb1a860ff685f22e311664903e 100644 (file)
@@ -98,7 +98,15 @@ defmodule Pleroma.Web.MastodonAPI.InstanceView do
       |> Map.merge(%{
         quarantined_instances:
           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
       %{}
index eb6b8bf6c1c20bc9bc1074ec2bb1f83eeb8d6315..9deceb1b5f02cf04842b8c1cd5e4abdb651a04d0 100644 (file)
@@ -150,20 +150,42 @@ defmodule Pleroma.Web.NodeInfoTest do
            )
   end
 
-  test "it shows quarantined instances data if enabled", %{conn: conn} do
-    clear_config([:mrf, :transparency], true)
+  describe "Quarantined instances" do
+    setup do
+      clear_config([:mrf, :transparency], true)
+      quarantined_instances = [{"example.com", "reason to quarantine"}]
+      clear_config([:instance, :quarantined_instances], quarantined_instances)
+    end
 
-    quarantined_instances = [{"example.com", ""}]
-    clear_config([:instance, :quarantined_instances], quarantined_instances)
+    test "shows quarantined instances data if enabled", %{conn: conn} do
+      expected_config = ["example.com"]
 
-    expected_config = [%{"instance" => "example.com", "reason" => ""}]
+      response =
+        conn
+        |> get("/nodeinfo/2.1.json")
+        |> json_response(:ok)
 
-    response =
-      conn
-      |> get("/nodeinfo/2.1.json")
-      |> json_response(:ok)
+      assert response["metadata"]["federation"]["quarantined_instances"] == expected_config
+    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"}
+        }
+      }
 
-    assert response["metadata"]["federation"]["quarantined_instances"] == expected_config
+      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
@@ -205,7 +227,7 @@ defmodule Pleroma.Web.NodeInfoTest do
       assert response["metadata"]["federation"]["exclusions"] == true
     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
     } do
       simple_config = %{