Make quarentine work with list of tuples instead of strings
authorIlja <domainepublic@spectraltheorem.be>
Fri, 2 Oct 2020 12:51:39 +0000 (14:51 +0200)
committerHaelwenn (lanodan) Monnier <contact@hacktivis.me>
Fri, 6 Aug 2021 05:59:52 +0000 (07:59 +0200)
lib/pleroma/web/activity_pub/mrf.ex
lib/pleroma/web/activity_pub/mrf/simple_policy.ex
lib/pleroma/web/activity_pub/publisher.ex
test/pleroma/web/activity_pub/mrf_test.exs
test/pleroma/web/activity_pub/publisher_test.exs

index ac00fa54ba27f541851edcf939ed25c54946cb2d..5ac4f9f207b4bf12d4dbcc9ab14f5ab14c7c55ab 100644 (file)
@@ -100,6 +100,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
+
   def describe(policies) do
     {:ok, policy_configs} =
       policies
index 8ef03aa3aca636b67277fdc2ae672ceb1c29fd3f..fe0dc874bfbf4092c6a4eee93ba2d9f93b928f10 100644 (file)
@@ -187,9 +187,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
index 590beef64a19cdbf89fe17c45a74f3a478cf7c3d..4f29a441136a2377eb3a7f1cd6ea07430c708e86 100644 (file)
@@ -112,6 +112,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)
index 61d308b978a20d16d7e8dd5905e2dcc81391a13a..6ab27bc8676f91d9c4bc234fbae7c1240e99776f 100644 (file)
@@ -63,6 +63,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])
index d0bb43fb214a63b84f8aae8f275e2aeaf5942d89..b50e22bbe794ccf24733b5ab404849ae3793b1e9 100644 (file)
@@ -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, %{