Always accept deletions through SimplePolicy
authorAlex Gleason <alex@alexgleason.me>
Mon, 13 Apr 2020 01:26:35 +0000 (20:26 -0500)
committerAlex Gleason <alex@alexgleason.me>
Mon, 13 Apr 2020 01:26:35 +0000 (20:26 -0500)
lib/pleroma/web/activity_pub/mrf/simple_policy.ex
test/web/activity_pub/mrf/simple_policy_test.exs

index 4edc007fd564dc889b829bdd78e85a327572c2e5..b23f263f5a151f612f8676f70bf74534742cfb0f 100644 (file)
@@ -148,6 +148,9 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicy do
 
   defp check_banner_removal(_actor_info, object), do: {:ok, object}
 
+  @impl true
+  def filter(%{"type" => "Delete"} = object), do: {:ok, object}
+
   @impl true
   def filter(%{"actor" => actor} = object) do
     actor_info = URI.parse(actor)
index 91c24c2d96fac2a31fabb75ef48bc1ec8a7e5808..eaa595706acf50fc9680a4d0a426321378be40c0 100644 (file)
@@ -258,6 +258,14 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
 
       assert SimplePolicy.filter(remote_user) == {:reject, nil}
     end
+
+    test "always accept deletions" do
+      Config.put([:mrf_simple, :reject], ["remote.instance"])
+
+      deletion_message = build_remote_deletion_message()
+
+      assert SimplePolicy.filter(deletion_message) == {:ok, deletion_message}
+    end
   end
 
   describe "when :accept" do
@@ -308,6 +316,14 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
 
       assert SimplePolicy.filter(remote_user) == {:ok, remote_user}
     end
+
+    test "always accept deletions" do
+      Config.put([:mrf_simple, :accept], ["non.matching.remote"])
+
+      deletion_message = build_remote_deletion_message()
+
+      assert SimplePolicy.filter(deletion_message) == {:ok, deletion_message}
+    end
   end
 
   describe "when :avatar_removal" do
@@ -408,4 +424,11 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
       "type" => "Person"
     }
   end
+
+  defp build_remote_deletion_message do
+    %{
+      "type" => "Delete",
+      "actor" => "https://remote.instance/users/bob"
+    }
+  end
 end