Ver código fonte

Don't crash on AP request for tombstone

Because tombstone objects has no addressing the is_public?-predicate
would cause an error that propagated as a 500 error in the api
tags/v0.9.9
sxsdv1 5 anos atrás
pai
commit
2d7da5f437
3 arquivos alterados com 29 adições e 0 exclusões
  1. +4
    -0
      lib/pleroma/web/activity_pub/activity_pub.ex
  2. +13
    -0
      test/support/factory.ex
  3. +12
    -0
      test/web/activity_pub/activity_pub_controller_test.exs

+ 4
- 0
lib/pleroma/web/activity_pub/activity_pub.ex Ver arquivo

@@ -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"] || []))


+ 13
- 0
test/support/factory.ex Ver arquivo

@@ -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)



+ 12
- 0
test/web/activity_pub/activity_pub_controller_test.exs Ver arquivo

@@ -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


Carregando…
Cancelar
Salvar