MastoAPI: Fix unauth visibility checks when fetching by Activity FlakeID
- Adds another Pleroma.ActivityPub.Visibility.visible_for_user?/2 func - Modifies existing tests to include a local Activity referencing a remote Object - Changes Announce Activity test factory to reference Objects instead of Activities and use a different Actor for the Announce - Changes ap_id of remote user in Announce test factory to match Objects - Adds `object_local` option to Note factories that explicitly changes the domain in the URL to not match the endpoint URL in the test env to properly work with the new visibility func, since we don't store locality of Object unlike Activities
This commit is contained in:
parent
c2b40659e7
commit
01ffaba3d2
3 changed files with 182 additions and 31 deletions
|
|
@ -102,11 +102,18 @@ defmodule Pleroma.Factory do
|
|||
|
||||
user = attrs[:user] || insert(:user)
|
||||
|
||||
object_id = if attrs[:object_local] == false do
|
||||
# Must not match our Endpoint URL in the test env
|
||||
"https://example.com/objects/#{Ecto.UUID.generate()}"
|
||||
else
|
||||
Pleroma.Web.ActivityPub.Utils.generate_object_id()
|
||||
end
|
||||
|
||||
data = %{
|
||||
"type" => "Note",
|
||||
"content" => text,
|
||||
"source" => text,
|
||||
"id" => Pleroma.Web.ActivityPub.Utils.generate_object_id(),
|
||||
"id" => object_id,
|
||||
"actor" => user.ap_id,
|
||||
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
"published" => DateTime.utc_now() |> DateTime.to_iso8601(),
|
||||
|
|
@ -361,14 +368,24 @@ defmodule Pleroma.Factory do
|
|||
|
||||
def note_activity_factory(attrs \\ %{}) do
|
||||
user = attrs[:user] || insert(:user)
|
||||
note = attrs[:note] || insert(:note, user: user)
|
||||
object_local = if attrs[:object_local] == false, do: false, else: true
|
||||
note = attrs[:note] || insert(:note, user: user, object_local: object_local)
|
||||
|
||||
activity_id = if attrs[:local] == false do
|
||||
# Same domain as in note Object factory, it doesn't make sense
|
||||
# to create mismatched Create Activities with an ID coming from
|
||||
# a different domain than the Object
|
||||
"https://example.com/activities/#{Ecto.UUID.generate()}"
|
||||
else
|
||||
Pleroma.Web.ActivityPub.Utils.generate_activity_id()
|
||||
end
|
||||
|
||||
data_attrs = attrs[:data_attrs] || %{}
|
||||
attrs = Map.drop(attrs, [:user, :note, :data_attrs])
|
||||
attrs = Map.drop(attrs, [:user, :note, :data_attrs, :object_local])
|
||||
|
||||
data =
|
||||
%{
|
||||
"id" => Pleroma.Web.ActivityPub.Utils.generate_activity_id(),
|
||||
"id" => activity_id,
|
||||
"type" => "Create",
|
||||
"actor" => note.data["actor"],
|
||||
"to" => note.data["to"],
|
||||
|
|
@ -408,15 +425,17 @@ defmodule Pleroma.Factory do
|
|||
|
||||
def announce_activity_factory(attrs \\ %{}) do
|
||||
note_activity = attrs[:note_activity] || insert(:note_activity)
|
||||
object = Object.normalize(note_activity, fetch: false)
|
||||
user = attrs[:user] || insert(:user)
|
||||
|
||||
data = %{
|
||||
"id" => Pleroma.Web.ActivityPub.Utils.generate_activity_id(),
|
||||
"type" => "Announce",
|
||||
"actor" => note_activity.actor,
|
||||
"object" => note_activity.data["id"],
|
||||
"to" => [user.follower_address, note_activity.data["actor"]],
|
||||
"actor" => user.ap_id,
|
||||
"object" => object.data["id"],
|
||||
"to" => [user.follower_address, object.data["actor"]],
|
||||
"cc" => ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
"context" => note_activity.data["context"]
|
||||
"context" => object.data["context"]
|
||||
}
|
||||
|
||||
%Pleroma.Activity{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue