Change what nodeinfo returns without breaking backwards compatibility
authorIlja <domainepublic@spectraltheorem.be>
Fri, 20 Nov 2020 12:48:28 +0000 (13:48 +0100)
committerHaelwenn (lanodan) Monnier <contact@hacktivis.me>
Fri, 6 Aug 2021 05:59:53 +0000 (07:59 +0200)
* Only for SimplePolicy for now
* I added an extra mrf_simple_info key that has an object as value. The object contains only relevant extra info

lib/pleroma/web/activity_pub/mrf/simple_policy.ex
test/pleroma/web/node_info_test.exs

index 0853a05a787a43011b196fc2ae7591118588d176..22999ef581324589928b2aaf33ea9351149552d3 100644 (file)
@@ -260,15 +260,27 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicy do
   def describe do
     exclusions = Config.get([:mrf, :transparency_exclusions]) |> MRF.instance_list_from_tuples()
 
-    mrf_simple =
+    mrf_simple_excluded =
       Config.get(:mrf_simple)
       |> Enum.map(fn {k, v} -> {k, Enum.reject(v, fn {v, _} -> v in exclusions end)} end)
+
+    mrf_simple =
+      mrf_simple_excluded
       |> Enum.map(fn {k, v} ->
-        {k, Enum.map(v, fn {i, r} -> %{"instance" => i, "reason" => r} end)}
+        {k, Enum.map(v, fn {instance, _} -> instance end)}
+      end)
+      |> Enum.into(%{})
+
+    mrf_simple_info =
+      mrf_simple_excluded
+      |> Enum.map(fn {k, v} -> {k, Enum.reject(v, fn {_, reason} -> reason == "" end)} end)
+      |> Enum.reject(fn {_, v} -> v == [] end)
+      |> Enum.map(fn {k, l} ->
+        {k, l |> Enum.map(fn {i, r} -> {i, %{"reason" => r}} end) |> Enum.into(%{})}
       end)
       |> Enum.into(%{})
 
-    {:ok, %{mrf_simple: mrf_simple}}
+    {:ok, %{mrf_simple: mrf_simple, mrf_simple_info: mrf_simple_info}}
   end
 
   @impl true
index cb910d6686ff228fce48c016c741b9877d56d05d..eb6b8bf6c1c20bc9bc1074ec2bb1f83eeb8d6315 100644 (file)
@@ -166,39 +166,89 @@ defmodule Pleroma.Web.NodeInfoTest do
     assert response["metadata"]["federation"]["quarantined_instances"] == expected_config
   end
 
-  test "it shows MRF transparency data if enabled", %{conn: conn} do
-    clear_config([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.SimplePolicy])
-    clear_config([:mrf, :transparency], true)
+  describe "MRF SimplePolicy" do
+    setup do
+      clear_config([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.SimplePolicy])
+      clear_config([:mrf, :transparency], true)
+    end
 
-    simple_config = %{"reject" => [{"example.com", ""}]}
-    clear_config(:mrf_simple, simple_config)
+    test "shows MRF transparency data if enabled", %{conn: conn} do
+      simple_config = %{"reject" => [{"example.com", ""}]}
+      clear_config(:mrf_simple, simple_config)
 
-    expected_config = %{"reject" => [%{"instance" => "example.com", "reason" => ""}]}
+      expected_config = %{"reject" => ["example.com"]}
 
-    response =
-      conn
-      |> get("/nodeinfo/2.1.json")
-      |> json_response(:ok)
+      response =
+        conn
+        |> get("/nodeinfo/2.1.json")
+        |> json_response(:ok)
 
-    assert response["metadata"]["federation"]["mrf_simple"] == expected_config
-  end
+      assert response["metadata"]["federation"]["mrf_simple"] == expected_config
+    end
 
-  test "it performs exclusions from MRF transparency data if configured", %{conn: conn} do
-    clear_config([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.SimplePolicy])
-    clear_config([:mrf, :transparency], true)
-    clear_config([:mrf, :transparency_exclusions], [{"other.site", "We don't want them to know"}])
+    test "performs exclusions from MRF transparency data if configured", %{conn: conn} do
+      clear_config([:mrf, :transparency_exclusions], [
+        {"other.site", "We don't want them to know"}
+      ])
 
-    simple_config = %{"reject" => [{"example.com", ""}, {"other.site", ""}]}
-    clear_config(:mrf_simple, simple_config)
+      simple_config = %{"reject" => [{"example.com", ""}, {"other.site", ""}]}
+      clear_config(:mrf_simple, simple_config)
 
-    expected_config = %{"reject" => [%{"instance" => "example.com", "reason" => ""}]}
+      expected_config = %{"reject" => ["example.com"]}
 
-    response =
-      conn
-      |> get("/nodeinfo/2.1.json")
-      |> json_response(:ok)
+      response =
+        conn
+        |> get("/nodeinfo/2.1.json")
+        |> json_response(:ok)
+
+      assert response["metadata"]["federation"]["mrf_simple"] == expected_config
+      assert response["metadata"]["federation"]["exclusions"] == true
+    end
 
-    assert response["metadata"]["federation"]["mrf_simple"] == expected_config
-    assert response["metadata"]["federation"]["exclusions"] == true
+    test "shows extra information in the mrf_simple_extra field for relevant entries", %{
+      conn: conn
+    } do
+      simple_config = %{
+        media_removal: [{"no.media", "LEEWWWDD >//<"}],
+        media_nsfw: [],
+        federated_timeline_removal: [{"no.ftl", ""}],
+        report_removal: [],
+        reject: [
+          {"example.instance", "Some reason"},
+          {"uwu.owo", "awoo to much"},
+          {"no.reason", ""}
+        ],
+        followers_only: [],
+        accept: [],
+        avatar_removal: [],
+        banner_removal: [],
+        reject_deletes: [
+          {"peak.me", "I want to peak at what they don't want me to see, eheh"}
+        ]
+      }
+
+      clear_config(:mrf_simple, simple_config)
+
+      clear_config([:mrf, :transparency_exclusions], [
+        {"peak.me", "I don't want them to know"}
+      ])
+
+      expected_config = %{
+        "media_removal" => %{
+          "no.media" => %{"reason" => "LEEWWWDD >//<"}
+        },
+        "reject" => %{
+          "example.instance" => %{"reason" => "Some reason"},
+          "uwu.owo" => %{"reason" => "awoo to much"}
+        }
+      }
+
+      response =
+        conn
+        |> get("/nodeinfo/2.1.json")
+        |> json_response(:ok)
+
+      assert response["metadata"]["federation"]["mrf_simple_info"] == expected_config
+    end
   end
 end