From 79ed38836cd67b5a0b1ee2c9bd1617b8d66e5c70 Mon Sep 17 00:00:00 2001 From: Ilja Date: Fri, 2 Oct 2020 14:51:39 +0200 Subject: [PATCH] Make quarentine work with list of tuples instead of strings --- lib/pleroma/web/activity_pub/mrf.ex | 5 +++++ lib/pleroma/web/activity_pub/mrf/simple_policy.ex | 4 +--- lib/pleroma/web/activity_pub/publisher.ex | 1 + test/web/activity_pub/mrf/mrf_test.exs | 9 +++++++++ test/web/activity_pub/publisher_test.exs | 4 ++-- 5 files changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/pleroma/web/activity_pub/mrf.ex b/lib/pleroma/web/activity_pub/mrf.ex index 5e5361082..28473a134 100644 --- a/lib/pleroma/web/activity_pub/mrf.ex +++ b/lib/pleroma/web/activity_pub/mrf.ex @@ -51,6 +51,11 @@ defmodule Pleroma.Web.ActivityPub.MRF do Enum.any?(domains, fn domain -> Regex.match?(domain, host) end) end + @spec instance_list_from_tuples([{String.t(), String.t()}]) :: [String.t()] + def instance_list_from_tuples(list) do + Enum.map(list, fn {instance, _} -> instance end) + end + @callback describe() :: {:ok | :error, Map.t()} def describe(policies) do diff --git a/lib/pleroma/web/activity_pub/mrf/simple_policy.ex b/lib/pleroma/web/activity_pub/mrf/simple_policy.ex index 22cb242fc..48463f996 100644 --- a/lib/pleroma/web/activity_pub/mrf/simple_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/simple_policy.ex @@ -183,9 +183,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicy do defp instance_list(config_key) do Config.get([:mrf_simple, config_key]) - |> Enum.map(fn - {instance, _} -> instance - end) + |> MRF.instance_list_from_tuples() end @impl true diff --git a/lib/pleroma/web/activity_pub/publisher.ex b/lib/pleroma/web/activity_pub/publisher.ex index 9c3956683..e4e9cfb69 100644 --- a/lib/pleroma/web/activity_pub/publisher.ex +++ b/lib/pleroma/web/activity_pub/publisher.ex @@ -126,6 +126,7 @@ defmodule Pleroma.Web.ActivityPub.Publisher do quarantined_instances = Config.get([:instance, :quarantined_instances], []) + |> Pleroma.Web.ActivityPub.MRF.instance_list_from_tuples() |> Pleroma.Web.ActivityPub.MRF.subdomains_regex() !Pleroma.Web.ActivityPub.MRF.subdomain_match?(quarantined_instances, host) diff --git a/test/web/activity_pub/mrf/mrf_test.exs b/test/web/activity_pub/mrf/mrf_test.exs index e82c8afa6..042590926 100644 --- a/test/web/activity_pub/mrf/mrf_test.exs +++ b/test/web/activity_pub/mrf/mrf_test.exs @@ -59,6 +59,15 @@ defmodule Pleroma.Web.ActivityPub.MRFTest do end end + describe "instance_list_from_tuples/1" do + test "returns a list of instances from a list of {instance, reason} tuples" do + list = [{"some.tld", "a reason"}, {"other.tld", "another reason"}] + expected = ["some.tld", "other.tld"] + + assert MRF.instance_list_from_tuples(list) == expected + end + end + describe "describe/0" do test "it works as expected with noop policy" do clear_config([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.NoOpPolicy]) diff --git a/test/web/activity_pub/publisher_test.exs b/test/web/activity_pub/publisher_test.exs index 3a9d9ce26..ed8bed719 100644 --- a/test/web/activity_pub/publisher_test.exs +++ b/test/web/activity_pub/publisher_test.exs @@ -271,7 +271,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do Pleroma.Web.Federator.Publisher, [:passthrough], [] do - Config.put([:instance, :quarantined_instances], ["domain.com"]) + Config.put([:instance, :quarantined_instances], [{"domain.com", "some reason"}]) follower = insert(:user, %{ @@ -308,7 +308,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do Pleroma.Web.Federator.Publisher, [:passthrough], [] do - Config.put([:instance, :quarantined_instances], ["somedomain.com"]) + Config.put([:instance, :quarantined_instances], [{"somedomain.com", "some reason"}]) follower = insert(:user, %{