Don't crash on AP request for tombstone
authorsxsdv1 <sxsdv1@gmail.com>
Sat, 5 Jan 2019 09:38:38 +0000 (10:38 +0100)
committersxsdv1 <sxsdv1@gmail.com>
Sat, 5 Jan 2019 10:16:05 +0000 (11:16 +0100)
Because tombstone objects has no addressing the is_public?-predicate
would cause an error that propagated as a 500 error in the api

lib/pleroma/web/activity_pub/activity_pub.ex
test/support/factory.ex
test/web/activity_pub/activity_pub_controller_test.exs

index 4d754de137d20c3b2f9435f4a48188c1d408d37e..4685f6d95ad796f6e8cca791c6426361b60b90ee 100644 (file)
@@ -801,6 +801,10 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
     end
   end
 
+  def is_public?(%Object{data: %{"type" => "Tombstone"}}) do
+    false
+  end
+
   def is_public?(activity) do
     "https://www.w3.org/ns/activitystreams#Public" in (activity.data["to"] ++
                                                          (activity.data["cc"] || []))
index e5c0c5bcce54889997fcf073e4b8f838498b80ed..57fa4a79d68a65e29c64277ca992b190dd37bd8d 100644 (file)
@@ -57,6 +57,19 @@ defmodule Pleroma.Factory do
     %Pleroma.Object{data: Map.merge(data, %{"to" => [user2.ap_id]})}
   end
 
+  def tombstone_factory do
+    data = %{
+      "type" => "Tombstone",
+      "id" => Pleroma.Web.ActivityPub.Utils.generate_object_id(),
+      "formerType" => "Note",
+      "deleted" => DateTime.utc_now() |> DateTime.to_iso8601()
+    }
+
+    %Pleroma.Object{
+      data: data
+    }
+  end
+
   def direct_note_activity_factory do
     dm = insert(:direct_note)
 
index 620e036748a4e00b20596dfb602f30507e55fade..7d1fe184e21bf540d7e0b4a4ad8633ec97de4f7a 100644 (file)
@@ -75,6 +75,18 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
 
       assert json_response(conn, 404)
     end
+
+    test "it returns 404 for tombstone objects", %{conn: conn} do
+      tombstone = insert(:tombstone)
+      uuid = String.split(tombstone.data["id"], "/") |> List.last()
+
+      conn =
+        conn
+        |> put_req_header("accept", "application/activity+json")
+        |> get("/objects/#{uuid}")
+
+      assert json_response(conn, 404)
+    end
   end
 
   describe "/inbox" do