From 47fc57bbccbe5df32ef00dda0ee8bdd56b38885f Mon Sep 17 00:00:00 2001 From: Ilja Date: Fri, 20 Nov 2020 13:48:28 +0100 Subject: [PATCH] Change what nodeinfo returns without breaking backwards compatibility * 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 | 18 +++- test/pleroma/web/node_info_test.exs | 100 ++++++++++++++++------ 2 files changed, 90 insertions(+), 28 deletions(-) diff --git a/lib/pleroma/web/activity_pub/mrf/simple_policy.ex b/lib/pleroma/web/activity_pub/mrf/simple_policy.ex index 0853a05a7..22999ef58 100644 --- a/lib/pleroma/web/activity_pub/mrf/simple_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/simple_policy.ex @@ -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(%{}) - {:ok, %{mrf_simple: mrf_simple}} + 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, mrf_simple_info: mrf_simple_info}} end @impl true diff --git a/test/pleroma/web/node_info_test.exs b/test/pleroma/web/node_info_test.exs index cb910d668..eb6b8bf6c 100644 --- a/test/pleroma/web/node_info_test.exs +++ b/test/pleroma/web/node_info_test.exs @@ -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 + assert response["metadata"]["federation"]["mrf_simple"] == expected_config + assert response["metadata"]["federation"]["exclusions"] == true + end + + 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