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
This commit is contained in:
Ilja 2020-11-20 13:48:28 +01:00 committed by Haelwenn (lanodan) Monnier
parent 7fdc3cde06
commit 47fc57bbcc
No known key found for this signature in database
GPG Key ID: D5B7A8E43C997DEE
2 changed files with 90 additions and 28 deletions

View File

@ -260,15 +260,27 @@ def filter(object), do: {:ok, object}
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

View File

@ -166,14 +166,17 @@ test "it shows quarantined instances data if enabled", %{conn: conn} do
assert response["metadata"]["federation"]["quarantined_instances"] == expected_config
end
test "it shows MRF transparency data if enabled", %{conn: conn} do
describe "MRF SimplePolicy" do
setup do
clear_config([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.SimplePolicy])
clear_config([:mrf, :transparency], true)
end
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
@ -183,15 +186,15 @@ test "it shows MRF transparency data if enabled", %{conn: conn} do
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)
expected_config = %{"reject" => [%{"instance" => "example.com", "reason" => ""}]}
expected_config = %{"reject" => ["example.com"]}
response =
conn
@ -201,4 +204,51 @@ test "it performs exclusions from MRF transparency data if configured", %{conn:
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