Merge branch 'feature/delivery-tracking' into 'develop'
Track signed fetches of objects and use them for delete federation See merge request pleroma/pleroma!1661
This commit is contained in:
commit
17142a3720
10 changed files with 287 additions and 6 deletions
|
|
@ -8,6 +8,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|
||||
import Pleroma.Factory
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Delivery
|
||||
alias Pleroma.Instances
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.Tests.ObanHelpers
|
||||
|
|
@ -893,4 +894,86 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
assert result["totalItems"] == 15
|
||||
end
|
||||
end
|
||||
|
||||
describe "delivery tracking" do
|
||||
test "it tracks a signed object fetch", %{conn: conn} do
|
||||
user = insert(:user, local: false)
|
||||
activity = insert(:note_activity)
|
||||
object = Object.normalize(activity)
|
||||
|
||||
object_path = String.trim_leading(object.data["id"], Pleroma.Web.Endpoint.url())
|
||||
|
||||
conn
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> assign(:user, user)
|
||||
|> get(object_path)
|
||||
|> json_response(200)
|
||||
|
||||
assert Delivery.get(object.id, user.id)
|
||||
end
|
||||
|
||||
test "it tracks a signed activity fetch", %{conn: conn} do
|
||||
user = insert(:user, local: false)
|
||||
activity = insert(:note_activity)
|
||||
object = Object.normalize(activity)
|
||||
|
||||
activity_path = String.trim_leading(activity.data["id"], Pleroma.Web.Endpoint.url())
|
||||
|
||||
conn
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> assign(:user, user)
|
||||
|> get(activity_path)
|
||||
|> json_response(200)
|
||||
|
||||
assert Delivery.get(object.id, user.id)
|
||||
end
|
||||
|
||||
test "it tracks a signed object fetch when the json is cached", %{conn: conn} do
|
||||
user = insert(:user, local: false)
|
||||
other_user = insert(:user, local: false)
|
||||
activity = insert(:note_activity)
|
||||
object = Object.normalize(activity)
|
||||
|
||||
object_path = String.trim_leading(object.data["id"], Pleroma.Web.Endpoint.url())
|
||||
|
||||
conn
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> assign(:user, user)
|
||||
|> get(object_path)
|
||||
|> json_response(200)
|
||||
|
||||
build_conn()
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> assign(:user, other_user)
|
||||
|> get(object_path)
|
||||
|> json_response(200)
|
||||
|
||||
assert Delivery.get(object.id, user.id)
|
||||
assert Delivery.get(object.id, other_user.id)
|
||||
end
|
||||
|
||||
test "it tracks a signed activity fetch when the json is cached", %{conn: conn} do
|
||||
user = insert(:user, local: false)
|
||||
other_user = insert(:user, local: false)
|
||||
activity = insert(:note_activity)
|
||||
object = Object.normalize(activity)
|
||||
|
||||
activity_path = String.trim_leading(activity.data["id"], Pleroma.Web.Endpoint.url())
|
||||
|
||||
conn
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> assign(:user, user)
|
||||
|> get(activity_path)
|
||||
|> json_response(200)
|
||||
|
||||
build_conn()
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> assign(:user, other_user)
|
||||
|> get(activity_path)
|
||||
|> json_response(200)
|
||||
|
||||
assert Delivery.get(object.id, user.id)
|
||||
assert Delivery.get(object.id, other_user.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
import ExUnit.CaptureLog
|
||||
import Pleroma.Factory
|
||||
|
|
@ -12,7 +12,9 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
|||
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Instances
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.Web.ActivityPub.Publisher
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
@as_public "https://www.w3.org/ns/activitystreams#Public"
|
||||
|
||||
|
|
@ -268,5 +270,69 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
|||
})
|
||||
)
|
||||
end
|
||||
|
||||
test_with_mock "publishes a delete activity to peers who signed fetch requests to the create acitvity/object.",
|
||||
Pleroma.Web.Federator.Publisher,
|
||||
[:passthrough],
|
||||
[] do
|
||||
fetcher =
|
||||
insert(:user,
|
||||
local: false,
|
||||
info: %{
|
||||
ap_enabled: true,
|
||||
source_data: %{"inbox" => "https://domain.com/users/nick1/inbox"}
|
||||
}
|
||||
)
|
||||
|
||||
another_fetcher =
|
||||
insert(:user,
|
||||
local: false,
|
||||
info: %{
|
||||
ap_enabled: true,
|
||||
source_data: %{"inbox" => "https://domain2.com/users/nick1/inbox"}
|
||||
}
|
||||
)
|
||||
|
||||
actor = insert(:user)
|
||||
|
||||
note_activity = insert(:note_activity, user: actor)
|
||||
object = Object.normalize(note_activity)
|
||||
|
||||
activity_path = String.trim_leading(note_activity.data["id"], Pleroma.Web.Endpoint.url())
|
||||
object_path = String.trim_leading(object.data["id"], Pleroma.Web.Endpoint.url())
|
||||
|
||||
build_conn()
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> assign(:user, fetcher)
|
||||
|> get(object_path)
|
||||
|> json_response(200)
|
||||
|
||||
build_conn()
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> assign(:user, another_fetcher)
|
||||
|> get(activity_path)
|
||||
|> json_response(200)
|
||||
|
||||
{:ok, delete} = CommonAPI.delete(note_activity.id, actor)
|
||||
|
||||
res = Publisher.publish(actor, delete)
|
||||
assert res == :ok
|
||||
|
||||
assert called(
|
||||
Pleroma.Web.Federator.Publisher.enqueue_one(Publisher, %{
|
||||
inbox: "https://domain.com/users/nick1/inbox",
|
||||
actor: actor,
|
||||
id: delete.data["id"]
|
||||
})
|
||||
)
|
||||
|
||||
assert called(
|
||||
Pleroma.Web.Federator.Publisher.enqueue_one(Publisher, %{
|
||||
inbox: "https://domain2.com/users/nick1/inbox",
|
||||
actor: actor,
|
||||
id: delete.data["id"]
|
||||
})
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue