2018-12-27 11:24:04 +01:00
|
|
|
# Portions of this file are derived from Pleroma:
|
|
|
|
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social>
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
# Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/test/web/activity_pub/activity_pub_test.exs
|
|
|
|
|
2020-01-22 02:14:42 +01:00
|
|
|
defmodule Mobilizon.Federation.ActivityPubTest do
|
2019-09-22 16:26:23 +02:00
|
|
|
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney
|
2018-10-11 17:37:39 +02:00
|
|
|
use Mobilizon.DataCase
|
2018-05-17 11:32:23 +02:00
|
|
|
|
2019-09-22 16:26:23 +02:00
|
|
|
import Mock
|
2020-07-09 17:24:28 +02:00
|
|
|
import Mox
|
2018-10-11 17:37:39 +02:00
|
|
|
import Mobilizon.Factory
|
2018-05-17 11:32:23 +02:00
|
|
|
|
2021-04-22 12:17:56 +02:00
|
|
|
alias Mobilizon.{Discussions, Events}
|
2020-02-18 08:57:00 +01:00
|
|
|
alias Mobilizon.Resources.Resource
|
|
|
|
alias Mobilizon.Todos.{Todo, TodoList}
|
2020-01-22 02:14:42 +01:00
|
|
|
|
|
|
|
alias Mobilizon.Federation.ActivityPub
|
2021-04-22 12:17:56 +02:00
|
|
|
alias Mobilizon.Federation.ActivityPub.Utils
|
2020-01-22 02:14:42 +01:00
|
|
|
alias Mobilizon.Federation.HTTPSignatures.Signature
|
2020-07-09 17:24:28 +02:00
|
|
|
alias Mobilizon.Service.HTTP.ActivityPub.Mock
|
2018-11-13 12:23:37 +01:00
|
|
|
|
2019-10-25 17:43:37 +02:00
|
|
|
@activity_pub_public_audience "https://www.w3.org/ns/activitystreams#Public"
|
2019-09-22 18:29:13 +02:00
|
|
|
|
2018-12-07 10:47:31 +01:00
|
|
|
describe "setting HTTP signature" do
|
|
|
|
test "set http signature header" do
|
|
|
|
actor = insert(:actor)
|
|
|
|
|
|
|
|
signature =
|
2019-07-30 16:40:59 +02:00
|
|
|
Signature.sign(actor, %{
|
2018-12-07 10:47:31 +01:00
|
|
|
host: "example.com",
|
|
|
|
"content-length": 15,
|
2019-09-22 13:41:24 +02:00
|
|
|
digest: %{id: "my_id"} |> Jason.encode!() |> Signature.build_digest(),
|
2019-07-30 16:40:59 +02:00
|
|
|
"(request-target)": Signature.generate_request_target("POST", "/inbox"),
|
|
|
|
date: Signature.generate_date_header()
|
2018-12-07 10:47:31 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
assert signature =~ "headers=\"(request-target) content-length date digest host\""
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-08-24 11:34:00 +02:00
|
|
|
describe "fetching an" do
|
2018-11-12 18:17:53 +01:00
|
|
|
test "object by url" do
|
2020-07-09 17:24:28 +02:00
|
|
|
url = "https://framapiaf.org/users/Framasoft/statuses/102093631881522097"
|
2018-05-17 11:32:23 +02:00
|
|
|
|
2020-07-09 17:24:28 +02:00
|
|
|
data =
|
|
|
|
File.read!("test/fixtures/mastodon-status-2.json")
|
|
|
|
|> Jason.decode!()
|
2018-05-17 11:32:23 +02:00
|
|
|
|
2020-07-09 17:24:28 +02:00
|
|
|
Mock
|
|
|
|
|> expect(:call, fn
|
|
|
|
%{method: :get, url: ^url}, _opts ->
|
|
|
|
{:ok, %Tesla.Env{status: 200, body: data}}
|
|
|
|
end)
|
|
|
|
|
|
|
|
{:ok, object} = ActivityPub.fetch_object_from_url(url)
|
|
|
|
|
|
|
|
{:ok, object_again} = ActivityPub.fetch_object_from_url(url)
|
|
|
|
|
|
|
|
assert object.id == object_again.id
|
2018-12-14 17:41:55 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
test "object reply by url" do
|
2020-07-09 17:24:28 +02:00
|
|
|
url = "https://zoltasila.pl/objects/1c295713-8e3c-411e-9e62-57a7b9c9e514"
|
|
|
|
reply_to_url = "https://framapiaf.org/users/peertube/statuses/104584600044284729"
|
2018-12-14 17:41:55 +01:00
|
|
|
|
2020-07-09 17:24:28 +02:00
|
|
|
data =
|
|
|
|
File.read!("test/fixtures/mastodon-status-3.json")
|
|
|
|
|> Jason.decode!()
|
|
|
|
|
|
|
|
reply_to_data =
|
|
|
|
File.read!("test/fixtures/mastodon-status-4.json")
|
|
|
|
|> Jason.decode!()
|
|
|
|
|
|
|
|
Mock
|
|
|
|
|> expect(:call, 2, fn
|
|
|
|
%{method: :get, url: ^url}, _opts ->
|
|
|
|
{:ok, %Tesla.Env{status: 200, body: data}}
|
|
|
|
|
|
|
|
%{method: :get, url: ^reply_to_url}, _opts ->
|
|
|
|
{:ok, %Tesla.Env{status: 200, body: reply_to_data}}
|
|
|
|
end)
|
|
|
|
|
|
|
|
{:ok, object} = ActivityPub.fetch_object_from_url(url)
|
|
|
|
|
|
|
|
assert object.in_reply_to_comment.url == reply_to_url
|
2018-12-14 17:41:55 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
test "object reply to a video by url" do
|
2020-07-09 17:24:28 +02:00
|
|
|
url = "https://diaspodon.fr/users/dada/statuses/100820008426311925"
|
|
|
|
origin_url = "https://framatube.org/videos/watch/9c9de5e8-0a1e-484a-b099-e80766180a6d"
|
2018-12-14 17:41:55 +01:00
|
|
|
|
2020-07-09 17:24:28 +02:00
|
|
|
data =
|
|
|
|
File.read!("test/fixtures/mastodon-status-5.json")
|
|
|
|
|> Jason.decode!()
|
|
|
|
|
|
|
|
origin_data =
|
|
|
|
File.read!("test/fixtures/peertube-video.json")
|
|
|
|
|> Jason.decode!()
|
|
|
|
|
|
|
|
Mock
|
|
|
|
|> expect(:call, 2, fn
|
|
|
|
%{method: :get, url: ^url}, _opts ->
|
|
|
|
{:ok, %Tesla.Env{status: 200, body: data}}
|
|
|
|
|
|
|
|
%{method: :get, url: ^origin_url}, _opts ->
|
|
|
|
{:ok, %Tesla.Env{status: 200, body: origin_data}}
|
|
|
|
end)
|
|
|
|
|
|
|
|
{:ok, object} = ActivityPub.fetch_object_from_url(url)
|
|
|
|
|
|
|
|
assert object.in_reply_to_comment == nil
|
2018-05-17 11:32:23 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "deletion" do
|
|
|
|
test "it creates a delete activity and deletes the original event" do
|
|
|
|
event = insert(:event)
|
2019-09-16 02:07:44 +02:00
|
|
|
event = Events.get_public_event_by_url_with_preload!(event.url)
|
2020-07-09 17:24:28 +02:00
|
|
|
{:ok, delete, _} = ActivityPub.delete(event, event.organizer_actor)
|
2018-05-17 11:32:23 +02:00
|
|
|
|
|
|
|
assert delete.data["type"] == "Delete"
|
2018-06-14 17:25:55 +02:00
|
|
|
assert delete.data["actor"] == event.organizer_actor.url
|
2020-07-09 17:24:28 +02:00
|
|
|
assert delete.data["object"]["type"] == "Event"
|
|
|
|
assert delete.data["object"]["id"] == event.url
|
2018-05-17 11:32:23 +02:00
|
|
|
|
2018-08-24 11:34:00 +02:00
|
|
|
assert Events.get_event_by_url(event.url) == nil
|
|
|
|
end
|
|
|
|
|
2019-09-09 09:31:08 +02:00
|
|
|
test "it deletes the original event but only locally if needed" do
|
2020-07-09 17:24:28 +02:00
|
|
|
with_mock Utils, [:passthrough],
|
2019-09-09 09:31:08 +02:00
|
|
|
maybe_federate: fn _ -> :ok end,
|
|
|
|
lazy_put_activity_defaults: fn args -> args end do
|
|
|
|
event = insert(:event)
|
2019-09-21 23:59:07 +02:00
|
|
|
event = Events.get_public_event_by_url_with_preload!(event.url)
|
2020-07-09 17:24:28 +02:00
|
|
|
{:ok, delete, _} = ActivityPub.delete(event, event.organizer_actor, false)
|
2019-09-09 09:31:08 +02:00
|
|
|
|
|
|
|
assert delete.data["type"] == "Delete"
|
|
|
|
assert delete.data["actor"] == event.organizer_actor.url
|
2020-07-09 17:24:28 +02:00
|
|
|
assert delete.data["object"]["type"] == "Event"
|
|
|
|
assert delete.data["object"]["id"] == event.url
|
2019-09-09 09:31:08 +02:00
|
|
|
assert delete.local == false
|
|
|
|
|
|
|
|
assert Events.get_event_by_url(event.url) == nil
|
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
assert_called(Utils.maybe_federate(delete))
|
2019-09-09 09:31:08 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-08-24 11:34:00 +02:00
|
|
|
test "it creates a delete activity and deletes the original comment" do
|
|
|
|
comment = insert(:comment)
|
2020-07-09 17:24:28 +02:00
|
|
|
comment = Discussions.get_comment_from_url_with_preload!(comment.url)
|
|
|
|
assert is_nil(Discussions.get_comment_from_url(comment.url).deleted_at)
|
|
|
|
{:ok, delete, _} = ActivityPub.delete(comment, comment.actor)
|
2018-08-24 11:34:00 +02:00
|
|
|
|
|
|
|
assert delete.data["type"] == "Delete"
|
|
|
|
assert delete.data["actor"] == comment.actor.url
|
2020-07-09 17:24:28 +02:00
|
|
|
assert delete.data["object"]["type"] == "Note"
|
|
|
|
assert delete.data["object"]["id"] == comment.url
|
2018-08-24 11:34:00 +02:00
|
|
|
|
2020-07-09 17:24:28 +02:00
|
|
|
refute is_nil(Discussions.get_comment_from_url(comment.url).deleted_at)
|
2018-05-17 11:32:23 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "update" do
|
2019-09-04 18:24:31 +02:00
|
|
|
@updated_actor_summary "This is an updated actor"
|
|
|
|
|
2018-06-14 17:25:55 +02:00
|
|
|
test "it creates an update activity with the new actor data" do
|
|
|
|
actor = insert(:actor)
|
2019-10-25 17:43:37 +02:00
|
|
|
actor_data = %{summary: @updated_actor_summary}
|
|
|
|
|
2020-07-09 17:24:28 +02:00
|
|
|
{:ok, update, _} = ActivityPub.update(actor, actor_data, false)
|
2018-05-17 11:32:23 +02:00
|
|
|
|
2018-06-14 17:25:55 +02:00
|
|
|
assert update.data["actor"] == actor.url
|
2019-10-25 17:43:37 +02:00
|
|
|
assert update.data["to"] == [@activity_pub_public_audience]
|
|
|
|
assert update.data["object"]["id"] == actor.url
|
2019-12-03 11:29:51 +01:00
|
|
|
assert update.data["object"]["type"] == :Person
|
2019-09-04 18:24:31 +02:00
|
|
|
assert update.data["object"]["summary"] == @updated_actor_summary
|
|
|
|
end
|
|
|
|
|
|
|
|
@updated_start_time DateTime.utc_now() |> DateTime.truncate(:second)
|
|
|
|
|
|
|
|
test "it creates an update activity with the new event data" do
|
|
|
|
actor = insert(:actor)
|
|
|
|
event = insert(:event, organizer_actor: actor)
|
2019-10-25 17:43:37 +02:00
|
|
|
event_data = %{begins_on: @updated_start_time}
|
2019-09-04 18:24:31 +02:00
|
|
|
|
2020-07-09 17:24:28 +02:00
|
|
|
{:ok, update, _} = ActivityPub.update(event, event_data)
|
2019-09-04 18:24:31 +02:00
|
|
|
|
2019-10-25 17:43:37 +02:00
|
|
|
assert update.data["actor"] == actor.url
|
|
|
|
assert update.data["to"] == [@activity_pub_public_audience]
|
|
|
|
assert update.data["object"]["id"] == event.url
|
|
|
|
assert update.data["object"]["type"] == "Event"
|
|
|
|
assert update.data["object"]["startTime"] == DateTime.to_iso8601(@updated_start_time)
|
2018-05-17 11:32:23 +02:00
|
|
|
end
|
|
|
|
end
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2021-01-18 16:19:07 +01:00
|
|
|
describe "remove a member" do
|
|
|
|
test "it creates an remove activity" do
|
|
|
|
group = insert(:group)
|
|
|
|
member = insert(:member, parent: group)
|
|
|
|
moderator = insert(:actor)
|
|
|
|
{:ok, activity, _member} = ActivityPub.remove(member, group, moderator, true)
|
|
|
|
assert activity.data["type"] == "Remove"
|
|
|
|
assert activity.data["actor"] == moderator.url
|
|
|
|
assert activity.data["to"] == [group.members_url]
|
|
|
|
assert activity.data["object"] == member.url
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
describe "create a todo list" do
|
|
|
|
@todo_list_title "My TODO-list"
|
|
|
|
|
|
|
|
test "it creates a todo list" do
|
|
|
|
with_mock Utils, [:passthrough], maybe_federate: fn _ -> :ok end do
|
|
|
|
actor = insert(:actor)
|
|
|
|
group = insert(:group)
|
|
|
|
|
|
|
|
{:ok, create_data, %TodoList{url: todo_list_url}} =
|
|
|
|
ActivityPub.create(:todo_list, %{title: @todo_list_title, actor_id: group.id}, true, %{
|
|
|
|
"actor" => actor.url
|
|
|
|
})
|
|
|
|
|
|
|
|
assert create_data.local
|
|
|
|
assert create_data.data["object"]["id"] == todo_list_url
|
|
|
|
assert create_data.data["object"]["type"] == "TodoList"
|
2020-07-09 17:24:28 +02:00
|
|
|
assert create_data.data["object"]["name"] == @todo_list_title
|
|
|
|
assert create_data.data["to"] == [group.members_url]
|
2020-02-18 08:57:00 +01:00
|
|
|
assert create_data.data["actor"] == actor.url
|
|
|
|
|
|
|
|
assert_called(Utils.maybe_federate(create_data))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "create a todo" do
|
|
|
|
@todo_title "Finish this thing"
|
|
|
|
|
|
|
|
test "it creates a todo" do
|
|
|
|
with_mock Utils, [:passthrough], maybe_federate: fn _ -> :ok end do
|
|
|
|
actor = insert(:actor)
|
|
|
|
todo_list = insert(:todo_list)
|
|
|
|
|
|
|
|
{:ok, create_data, %Todo{url: todo_url}} =
|
|
|
|
ActivityPub.create(
|
|
|
|
:todo,
|
|
|
|
%{title: @todo_title, todo_list_id: todo_list.id, creator_id: actor.id},
|
|
|
|
true,
|
|
|
|
%{"actor" => actor.url}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert create_data.local
|
|
|
|
assert create_data.data["object"]["id"] == todo_url
|
|
|
|
assert create_data.data["object"]["type"] == "Todo"
|
|
|
|
assert create_data.data["object"]["name"] == @todo_title
|
2020-07-09 17:24:28 +02:00
|
|
|
assert create_data.data["to"] == [todo_list.actor.members_url]
|
2020-02-18 08:57:00 +01:00
|
|
|
assert create_data.data["actor"] == actor.url
|
|
|
|
|
|
|
|
assert_called(Utils.maybe_federate(create_data))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
@resource_url "https://framasoft.org/fr/full"
|
|
|
|
@resource_title "my resource"
|
|
|
|
@updated_resource_title "my updated resource"
|
|
|
|
@folder_title "my folder"
|
|
|
|
describe "create resources" do
|
|
|
|
test "it creates a resource" do
|
|
|
|
with_mock Utils, [:passthrough], maybe_federate: fn _ -> :ok end do
|
|
|
|
actor = insert(:actor)
|
|
|
|
group = insert(:group)
|
|
|
|
|
|
|
|
{:ok, create_data, %Resource{url: url}} =
|
|
|
|
ActivityPub.create(
|
|
|
|
:resource,
|
|
|
|
%{
|
|
|
|
title: @resource_title,
|
|
|
|
creator_id: actor.id,
|
|
|
|
actor_id: group.id,
|
|
|
|
parent_id: nil,
|
|
|
|
resource_url: @resource_url,
|
|
|
|
type: :link
|
|
|
|
},
|
|
|
|
true
|
|
|
|
)
|
|
|
|
|
|
|
|
assert create_data.local
|
|
|
|
assert create_data.data["type"] == "Create"
|
|
|
|
assert create_data.data["object"]["id"] == url
|
|
|
|
assert create_data.data["object"]["type"] == "Document"
|
|
|
|
assert create_data.data["object"]["name"] == @resource_title
|
|
|
|
|
|
|
|
assert create_data.data["object"]["url"] == @resource_url
|
|
|
|
|
2020-07-09 17:24:28 +02:00
|
|
|
assert create_data.data["to"] == [group.members_url]
|
2020-02-18 08:57:00 +01:00
|
|
|
assert create_data.data["actor"] == actor.url
|
|
|
|
assert create_data.data["attributedTo"] == [actor.url]
|
|
|
|
|
|
|
|
assert_called(Utils.maybe_federate(create_data))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it creates a folder" do
|
|
|
|
with_mock Utils, [:passthrough], maybe_federate: fn _ -> :ok end do
|
|
|
|
actor = insert(:actor)
|
|
|
|
group = insert(:group)
|
|
|
|
|
|
|
|
{:ok, create_data, %Resource{url: url}} =
|
|
|
|
ActivityPub.create(
|
|
|
|
:resource,
|
|
|
|
%{
|
|
|
|
title: @folder_title,
|
|
|
|
creator_id: actor.id,
|
|
|
|
actor_id: group.id,
|
|
|
|
parent_id: nil,
|
|
|
|
type: :folder
|
|
|
|
},
|
|
|
|
true
|
|
|
|
)
|
|
|
|
|
|
|
|
assert create_data.local
|
|
|
|
assert create_data.data["type"] == "Create"
|
|
|
|
assert create_data.data["object"]["id"] == url
|
|
|
|
assert create_data.data["object"]["type"] == "ResourceCollection"
|
|
|
|
assert create_data.data["object"]["name"] == @folder_title
|
2020-07-09 17:24:28 +02:00
|
|
|
assert create_data.data["to"] == [group.members_url]
|
2020-02-18 08:57:00 +01:00
|
|
|
assert create_data.data["actor"] == actor.url
|
|
|
|
assert create_data.data["attributedTo"] == [actor.url]
|
|
|
|
|
|
|
|
assert_called(Utils.maybe_federate(create_data))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it creates a resource in a folder" do
|
|
|
|
with_mock Utils, [:passthrough], maybe_federate: fn _ -> :ok end do
|
|
|
|
actor = insert(:actor)
|
|
|
|
group = insert(:group)
|
|
|
|
|
|
|
|
%Resource{id: parent_id, url: parent_url} =
|
|
|
|
insert(:resource, type: :folder, resource_url: nil, actor: group)
|
|
|
|
|
|
|
|
{:ok, create_data, %Resource{url: url}} =
|
|
|
|
ActivityPub.create(
|
|
|
|
:resource,
|
|
|
|
%{
|
|
|
|
title: @resource_title,
|
|
|
|
creator_id: actor.id,
|
|
|
|
actor_id: group.id,
|
|
|
|
parent_id: parent_id,
|
|
|
|
resource_url: @resource_url,
|
|
|
|
type: :link
|
|
|
|
},
|
|
|
|
true
|
|
|
|
)
|
|
|
|
|
|
|
|
assert create_data.local
|
|
|
|
assert create_data.data["type"] == "Add"
|
|
|
|
assert create_data.data["target"] == parent_url
|
|
|
|
assert create_data.data["object"]["id"] == url
|
|
|
|
assert create_data.data["object"]["type"] == "Document"
|
|
|
|
assert create_data.data["object"]["name"] == @resource_title
|
|
|
|
|
|
|
|
assert create_data.data["object"]["url"] == @resource_url
|
|
|
|
|
2020-07-09 17:24:28 +02:00
|
|
|
assert create_data.data["to"] == [group.members_url]
|
2020-02-18 08:57:00 +01:00
|
|
|
assert create_data.data["actor"] == actor.url
|
|
|
|
assert create_data.data["attributedTo"] == [actor.url]
|
|
|
|
|
|
|
|
assert_called(Utils.maybe_federate(create_data))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "move resources" do
|
|
|
|
test "rename resource" do
|
|
|
|
with_mock Utils, [:passthrough], maybe_federate: fn _ -> :ok end do
|
|
|
|
actor = insert(:actor)
|
|
|
|
group = insert(:group)
|
|
|
|
|
|
|
|
%Resource{} =
|
|
|
|
resource =
|
|
|
|
insert(:resource,
|
|
|
|
resource_url: @resource_url,
|
|
|
|
actor: group,
|
|
|
|
creator: actor,
|
|
|
|
title: @resource_title
|
|
|
|
)
|
|
|
|
|
|
|
|
{:ok, update_data, %Resource{url: url}} =
|
|
|
|
ActivityPub.update(
|
|
|
|
resource,
|
|
|
|
%{
|
|
|
|
title: @updated_resource_title
|
|
|
|
},
|
|
|
|
true
|
|
|
|
)
|
|
|
|
|
|
|
|
assert update_data.local
|
|
|
|
assert update_data.data["type"] == "Update"
|
|
|
|
assert update_data.data["object"]["id"] == url
|
|
|
|
assert update_data.data["object"]["type"] == "Document"
|
|
|
|
assert update_data.data["object"]["name"] == @updated_resource_title
|
|
|
|
|
|
|
|
assert update_data.data["object"]["url"] == @resource_url
|
|
|
|
|
2020-07-09 17:24:28 +02:00
|
|
|
assert update_data.data["to"] == [group.members_url]
|
2020-02-18 08:57:00 +01:00
|
|
|
assert update_data.data["actor"] == actor.url
|
|
|
|
assert update_data.data["attributedTo"] == [actor.url]
|
|
|
|
|
|
|
|
assert_called(Utils.maybe_federate(update_data))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test "move resource" do
|
|
|
|
with_mock Utils, [:passthrough], maybe_federate: fn _ -> :ok end do
|
|
|
|
actor = insert(:actor)
|
|
|
|
group = insert(:group)
|
|
|
|
|
|
|
|
%Resource{} =
|
|
|
|
resource =
|
|
|
|
insert(:resource,
|
|
|
|
resource_url: @resource_url,
|
|
|
|
actor: group,
|
|
|
|
creator: actor,
|
|
|
|
title: @resource_title
|
|
|
|
)
|
|
|
|
|
|
|
|
%Resource{id: parent_id, url: parent_url} =
|
|
|
|
insert(:resource, type: :folder, resource_url: nil, actor: group)
|
|
|
|
|
|
|
|
{:ok, update_data, %Resource{url: url}} =
|
|
|
|
ActivityPub.move(
|
|
|
|
:resource,
|
|
|
|
resource,
|
|
|
|
%{
|
|
|
|
parent_id: parent_id
|
|
|
|
},
|
|
|
|
true
|
|
|
|
)
|
|
|
|
|
|
|
|
assert update_data.local
|
|
|
|
assert update_data.data["type"] == "Move"
|
|
|
|
assert update_data.data["object"]["id"] == url
|
|
|
|
assert update_data.data["object"]["type"] == "Document"
|
|
|
|
assert update_data.data["object"]["name"] == @resource_title
|
|
|
|
|
|
|
|
assert update_data.data["object"]["url"] == @resource_url
|
|
|
|
|
2020-07-09 17:24:28 +02:00
|
|
|
assert update_data.data["to"] == [group.members_url]
|
2020-02-18 08:57:00 +01:00
|
|
|
assert update_data.data["actor"] == actor.url
|
|
|
|
assert update_data.data["origin"] == nil
|
|
|
|
assert update_data.data["target"] == parent_url
|
|
|
|
|
|
|
|
assert_called(Utils.maybe_federate(update_data))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "delete resources" do
|
|
|
|
test "delete resource" do
|
|
|
|
with_mock Utils, [:passthrough], maybe_federate: fn _ -> :ok end do
|
|
|
|
actor = insert(:actor)
|
|
|
|
group = insert(:group)
|
|
|
|
|
|
|
|
%Resource{} =
|
|
|
|
resource =
|
|
|
|
insert(:resource,
|
|
|
|
resource_url: @resource_url,
|
|
|
|
actor: group,
|
|
|
|
creator: actor,
|
|
|
|
title: @resource_title
|
|
|
|
)
|
|
|
|
|
|
|
|
{:ok, update_data, %Resource{url: url}} =
|
|
|
|
ActivityPub.delete(
|
|
|
|
resource,
|
2020-07-09 17:24:28 +02:00
|
|
|
actor,
|
2020-02-18 08:57:00 +01:00
|
|
|
true
|
|
|
|
)
|
|
|
|
|
|
|
|
assert update_data.local
|
|
|
|
assert update_data.data["type"] == "Delete"
|
2020-07-09 17:24:28 +02:00
|
|
|
assert update_data.data["object"]["type"] == "Document"
|
|
|
|
assert update_data.data["object"]["id"] == url
|
|
|
|
assert update_data.data["to"] == [group.members_url]
|
|
|
|
assert update_data.data["actor"] == actor.url
|
|
|
|
assert update_data.data["attributedTo"] == [group.url]
|
2020-02-18 08:57:00 +01:00
|
|
|
|
|
|
|
assert_called(Utils.maybe_federate(update_data))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-07-09 17:24:28 +02:00
|
|
|
|
|
|
|
describe "announce" do
|
|
|
|
end
|
2018-05-17 11:32:23 +02:00
|
|
|
end
|