2018-12-27 10:24:04 +00: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 01:14:42 +00:00
|
|
|
defmodule Mobilizon.Federation.ActivityPubTest do
|
2018-10-11 15:37:39 +00:00
|
|
|
use Mobilizon.DataCase
|
2018-05-17 09:32:23 +00:00
|
|
|
|
2019-09-22 14:26:23 +00:00
|
|
|
import Mock
|
2020-07-09 15:24:28 +00:00
|
|
|
import Mox
|
2018-10-11 15:37:39 +00:00
|
|
|
import Mobilizon.Factory
|
2018-05-17 09:32:23 +00:00
|
|
|
|
2021-04-22 10:17:56 +00:00
|
|
|
alias Mobilizon.{Discussions, Events}
|
2020-02-18 07:57:00 +00:00
|
|
|
alias Mobilizon.Resources.Resource
|
|
|
|
alias Mobilizon.Todos.{Todo, TodoList}
|
2020-01-22 01:14:42 +00:00
|
|
|
|
|
|
|
alias Mobilizon.Federation.ActivityPub
|
2021-09-28 17:40:37 +00:00
|
|
|
alias Mobilizon.Federation.ActivityPub.{Actions, Utils}
|
2020-01-22 01:14:42 +00:00
|
|
|
alias Mobilizon.Federation.HTTPSignatures.Signature
|
2020-07-09 15:24:28 +00:00
|
|
|
alias Mobilizon.Service.HTTP.ActivityPub.Mock
|
2018-11-13 11:23:37 +00:00
|
|
|
|
2019-10-25 15:43:37 +00:00
|
|
|
@activity_pub_public_audience "https://www.w3.org/ns/activitystreams#Public"
|
2019-09-22 16:29:13 +00:00
|
|
|
|
2018-12-07 09:47:31 +00:00
|
|
|
describe "setting HTTP signature" do
|
|
|
|
test "set http signature header" do
|
|
|
|
actor = insert(:actor)
|
|
|
|
|
|
|
|
signature =
|
2019-07-30 14:40:59 +00:00
|
|
|
Signature.sign(actor, %{
|
2018-12-07 09:47:31 +00:00
|
|
|
host: "example.com",
|
|
|
|
"content-length": 15,
|
2019-09-22 11:41:24 +00:00
|
|
|
digest: %{id: "my_id"} |> Jason.encode!() |> Signature.build_digest(),
|
2019-07-30 14:40:59 +00:00
|
|
|
"(request-target)": Signature.generate_request_target("POST", "/inbox"),
|
|
|
|
date: Signature.generate_date_header()
|
2018-12-07 09:47:31 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
assert signature =~ "headers=\"(request-target) content-length date digest host\""
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-08-24 09:34:00 +00:00
|
|
|
describe "fetching an" do
|
2018-11-12 17:17:53 +00:00
|
|
|
test "object by url" do
|
2020-07-09 15:24:28 +00:00
|
|
|
url = "https://framapiaf.org/users/Framasoft/statuses/102093631881522097"
|
2018-05-17 09:32:23 +00:00
|
|
|
|
2020-07-09 15:24:28 +00:00
|
|
|
data =
|
|
|
|
File.read!("test/fixtures/mastodon-status-2.json")
|
|
|
|
|> Jason.decode!()
|
2018-05-17 09:32:23 +00:00
|
|
|
|
2021-11-13 17:45:01 +00:00
|
|
|
actor_data =
|
|
|
|
File.read!("test/fixtures/mastodon-actor.json")
|
|
|
|
|> Jason.decode!()
|
|
|
|
|
2020-07-09 15:24:28 +00:00
|
|
|
Mock
|
2021-11-13 17:45:01 +00:00
|
|
|
|> expect(:call, 2, fn
|
2020-07-09 15:24:28 +00:00
|
|
|
%{method: :get, url: ^url}, _opts ->
|
|
|
|
{:ok, %Tesla.Env{status: 200, body: data}}
|
2021-11-13 17:45:01 +00:00
|
|
|
|
|
|
|
%{method: :get, url: "https://framapiaf.org/users/Framasoft"}, _opts ->
|
|
|
|
{:ok, %Tesla.Env{status: 200, body: actor_data}}
|
2020-07-09 15:24:28 +00:00
|
|
|
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 16:41:55 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test "object reply by url" do
|
2021-05-18 14:04:01 +00:00
|
|
|
url = "https://pirateradio.social/notice/A5XnLBsFNQDKtthzM0"
|
|
|
|
reply_to_url = "https://framapiaf.org/users/peertube/statuses/105945857653893100"
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2020-07-09 15:24:28 +00: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!()
|
|
|
|
|
2021-11-13 17:45:01 +00:00
|
|
|
actor_data =
|
|
|
|
File.read!("test/fixtures/mastodon-actor.json")
|
|
|
|
|> Jason.decode!()
|
|
|
|
|
2020-07-09 15:24:28 +00:00
|
|
|
Mock
|
2021-11-13 17:45:01 +00:00
|
|
|
|> expect(:call, 3, fn
|
2020-07-09 15:24:28 +00:00
|
|
|
%{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}}
|
2021-11-13 17:45:01 +00:00
|
|
|
|
|
|
|
%{method: :get, url: "https://pirateradio.social/users/captain"}, _opts ->
|
|
|
|
{:ok, %Tesla.Env{status: 200, body: actor_data}}
|
2020-07-09 15:24:28 +00:00
|
|
|
end)
|
|
|
|
|
|
|
|
{:ok, object} = ActivityPub.fetch_object_from_url(url)
|
|
|
|
|
|
|
|
assert object.in_reply_to_comment.url == reply_to_url
|
2018-12-14 16:41:55 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test "object reply to a video by url" do
|
2020-07-09 15:24:28 +00:00
|
|
|
url = "https://diaspodon.fr/users/dada/statuses/100820008426311925"
|
|
|
|
origin_url = "https://framatube.org/videos/watch/9c9de5e8-0a1e-484a-b099-e80766180a6d"
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2020-07-09 15:24:28 +00:00
|
|
|
data =
|
|
|
|
File.read!("test/fixtures/mastodon-status-5.json")
|
|
|
|
|> Jason.decode!()
|
|
|
|
|
|
|
|
origin_data =
|
|
|
|
File.read!("test/fixtures/peertube-video.json")
|
|
|
|
|> Jason.decode!()
|
|
|
|
|
2021-11-13 17:45:01 +00:00
|
|
|
actor_data =
|
|
|
|
File.read!("test/fixtures/mastodon-actor.json")
|
|
|
|
|> Jason.decode!()
|
|
|
|
|
2020-07-09 15:24:28 +00:00
|
|
|
Mock
|
2021-11-13 17:45:01 +00:00
|
|
|
|> expect(:call, 5, fn
|
2020-07-09 15:24:28 +00:00
|
|
|
%{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}}
|
2021-11-13 17:45:01 +00:00
|
|
|
|
|
|
|
%{method: :get, url: "https://diaspodon.fr/users/dada"}, _opts ->
|
|
|
|
{:ok, %Tesla.Env{status: 200, body: actor_data}}
|
|
|
|
|
|
|
|
%{method: :get, url: "https://framatube.org/accounts/framasoft"}, _opts ->
|
|
|
|
{:ok, %Tesla.Env{status: 200, body: actor_data}}
|
|
|
|
|
|
|
|
%{method: :get, url: "https://framapiaf.org/users/Pouhiou"}, _opts ->
|
|
|
|
{:ok, %Tesla.Env{status: 200, body: actor_data}}
|
2020-07-09 15:24:28 +00:00
|
|
|
end)
|
|
|
|
|
|
|
|
{:ok, object} = ActivityPub.fetch_object_from_url(url)
|
|
|
|
|
|
|
|
assert object.in_reply_to_comment == nil
|
2018-05-17 09:32:23 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "deletion" do
|
|
|
|
test "it creates a delete activity and deletes the original event" do
|
|
|
|
event = insert(:event)
|
2019-09-16 00:07:44 +00:00
|
|
|
event = Events.get_public_event_by_url_with_preload!(event.url)
|
2021-09-28 17:40:37 +00:00
|
|
|
{:ok, delete, _} = Actions.Delete.delete(event, event.organizer_actor)
|
2018-05-17 09:32:23 +00:00
|
|
|
|
|
|
|
assert delete.data["type"] == "Delete"
|
2018-06-14 15:25:55 +00:00
|
|
|
assert delete.data["actor"] == event.organizer_actor.url
|
2021-11-03 16:45:32 +00:00
|
|
|
assert delete.data["object"]["type"] == "Tombstone"
|
2020-07-09 15:24:28 +00:00
|
|
|
assert delete.data["object"]["id"] == event.url
|
2018-05-17 09:32:23 +00:00
|
|
|
|
2018-08-24 09:34:00 +00:00
|
|
|
assert Events.get_event_by_url(event.url) == nil
|
|
|
|
end
|
|
|
|
|
2019-09-09 07:31:08 +00:00
|
|
|
test "it deletes the original event but only locally if needed" do
|
2020-07-09 15:24:28 +00:00
|
|
|
with_mock Utils, [:passthrough],
|
2019-09-09 07:31:08 +00:00
|
|
|
maybe_federate: fn _ -> :ok end,
|
|
|
|
lazy_put_activity_defaults: fn args -> args end do
|
|
|
|
event = insert(:event)
|
2019-09-21 21:59:07 +00:00
|
|
|
event = Events.get_public_event_by_url_with_preload!(event.url)
|
2021-09-28 17:40:37 +00:00
|
|
|
{:ok, delete, _} = Actions.Delete.delete(event, event.organizer_actor, false)
|
2019-09-09 07:31:08 +00:00
|
|
|
|
|
|
|
assert delete.data["type"] == "Delete"
|
|
|
|
assert delete.data["actor"] == event.organizer_actor.url
|
2021-11-03 16:45:32 +00:00
|
|
|
assert delete.data["object"]["type"] == "Tombstone"
|
2020-07-09 15:24:28 +00:00
|
|
|
assert delete.data["object"]["id"] == event.url
|
2019-09-09 07:31:08 +00:00
|
|
|
assert delete.local == false
|
|
|
|
|
|
|
|
assert Events.get_event_by_url(event.url) == nil
|
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
assert_called(Utils.maybe_federate(delete))
|
2019-09-09 07:31:08 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-08-24 09:34:00 +00:00
|
|
|
test "it creates a delete activity and deletes the original comment" do
|
|
|
|
comment = insert(:comment)
|
2020-07-09 15:24:28 +00:00
|
|
|
comment = Discussions.get_comment_from_url_with_preload!(comment.url)
|
|
|
|
assert is_nil(Discussions.get_comment_from_url(comment.url).deleted_at)
|
2021-09-28 17:40:37 +00:00
|
|
|
{:ok, delete, _} = Actions.Delete.delete(comment, comment.actor)
|
2018-08-24 09:34:00 +00:00
|
|
|
|
|
|
|
assert delete.data["type"] == "Delete"
|
|
|
|
assert delete.data["actor"] == comment.actor.url
|
2021-11-03 16:45:32 +00:00
|
|
|
assert delete.data["object"]["type"] == "Tombstone"
|
2020-07-09 15:24:28 +00:00
|
|
|
assert delete.data["object"]["id"] == comment.url
|
2018-08-24 09:34:00 +00:00
|
|
|
|
2020-07-09 15:24:28 +00:00
|
|
|
refute is_nil(Discussions.get_comment_from_url(comment.url).deleted_at)
|
2018-05-17 09:32:23 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "update" do
|
2019-09-04 16:24:31 +00:00
|
|
|
@updated_actor_summary "This is an updated actor"
|
|
|
|
|
2018-06-14 15:25:55 +00:00
|
|
|
test "it creates an update activity with the new actor data" do
|
|
|
|
actor = insert(:actor)
|
2019-10-25 15:43:37 +00:00
|
|
|
actor_data = %{summary: @updated_actor_summary}
|
|
|
|
|
2022-04-20 09:33:13 +00:00
|
|
|
{:ok, update, _} = Actions.Update.update(actor, actor_data, true)
|
2018-05-17 09:32:23 +00:00
|
|
|
|
2018-06-14 15:25:55 +00:00
|
|
|
assert update.data["actor"] == actor.url
|
2019-10-25 15:43:37 +00:00
|
|
|
assert update.data["to"] == [@activity_pub_public_audience]
|
|
|
|
assert update.data["object"]["id"] == actor.url
|
2019-12-03 10:29:51 +00:00
|
|
|
assert update.data["object"]["type"] == :Person
|
2019-09-04 16:24:31 +00: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 15:43:37 +00:00
|
|
|
event_data = %{begins_on: @updated_start_time}
|
2019-09-04 16:24:31 +00:00
|
|
|
|
2021-09-28 17:40:37 +00:00
|
|
|
{:ok, update, _} = Actions.Update.update(event, event_data)
|
2019-09-04 16:24:31 +00:00
|
|
|
|
2019-10-25 15:43:37 +00: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 09:32:23 +00:00
|
|
|
end
|
|
|
|
end
|
2020-02-18 07:57:00 +00:00
|
|
|
|
2021-01-18 15:19:07 +00:00
|
|
|
describe "remove a member" do
|
|
|
|
test "it creates an remove activity" do
|
|
|
|
group = insert(:group)
|
|
|
|
member = insert(:member, parent: group)
|
|
|
|
moderator = insert(:actor)
|
2021-09-28 17:40:37 +00:00
|
|
|
{:ok, activity, _member} = Actions.Remove.remove(member, group, moderator, true)
|
2021-01-18 15:19:07 +00:00
|
|
|
assert activity.data["type"] == "Remove"
|
|
|
|
assert activity.data["actor"] == moderator.url
|
2021-11-12 14:42:52 +00:00
|
|
|
assert activity.data["to"] == [member.actor.url, group.members_url]
|
2021-01-18 15:19:07 +00:00
|
|
|
assert activity.data["object"] == member.url
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-02-18 07:57:00 +00: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}} =
|
2021-09-28 17:40:37 +00:00
|
|
|
Actions.Create.create(
|
|
|
|
:todo_list,
|
|
|
|
%{title: @todo_list_title, actor_id: group.id},
|
|
|
|
true,
|
|
|
|
%{
|
|
|
|
"actor" => actor.url
|
|
|
|
}
|
|
|
|
)
|
2020-02-18 07:57:00 +00:00
|
|
|
|
|
|
|
assert create_data.local
|
|
|
|
assert create_data.data["object"]["id"] == todo_list_url
|
|
|
|
assert create_data.data["object"]["type"] == "TodoList"
|
2020-07-09 15:24:28 +00:00
|
|
|
assert create_data.data["object"]["name"] == @todo_list_title
|
|
|
|
assert create_data.data["to"] == [group.members_url]
|
2020-02-18 07:57:00 +00: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}} =
|
2021-09-28 17:40:37 +00:00
|
|
|
Actions.Create.create(
|
2020-02-18 07:57:00 +00:00
|
|
|
: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 15:24:28 +00:00
|
|
|
assert create_data.data["to"] == [todo_list.actor.members_url]
|
2020-02-18 07:57:00 +00: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}} =
|
2021-09-28 17:40:37 +00:00
|
|
|
Actions.Create.create(
|
2020-02-18 07:57:00 +00:00
|
|
|
: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 15:24:28 +00:00
|
|
|
assert create_data.data["to"] == [group.members_url]
|
2020-02-18 07:57:00 +00: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}} =
|
2021-09-28 17:40:37 +00:00
|
|
|
Actions.Create.create(
|
2020-02-18 07:57:00 +00:00
|
|
|
: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 15:24:28 +00:00
|
|
|
assert create_data.data["to"] == [group.members_url]
|
2020-02-18 07:57:00 +00: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}} =
|
2021-09-28 17:40:37 +00:00
|
|
|
Actions.Create.create(
|
2020-02-18 07:57:00 +00:00
|
|
|
: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 15:24:28 +00:00
|
|
|
assert create_data.data["to"] == [group.members_url]
|
2020-02-18 07:57:00 +00: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}} =
|
2021-09-28 17:40:37 +00:00
|
|
|
Actions.Update.update(
|
2020-02-18 07:57:00 +00:00
|
|
|
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 15:24:28 +00:00
|
|
|
assert update_data.data["to"] == [group.members_url]
|
2020-02-18 07:57:00 +00: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}} =
|
2021-09-28 17:40:37 +00:00
|
|
|
Actions.Move.move(
|
2020-02-18 07:57:00 +00:00
|
|
|
: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 15:24:28 +00:00
|
|
|
assert update_data.data["to"] == [group.members_url]
|
2020-02-18 07:57:00 +00: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}} =
|
2021-09-28 17:40:37 +00:00
|
|
|
Actions.Delete.delete(
|
2020-02-18 07:57:00 +00:00
|
|
|
resource,
|
2020-07-09 15:24:28 +00:00
|
|
|
actor,
|
2020-02-18 07:57:00 +00:00
|
|
|
true
|
|
|
|
)
|
|
|
|
|
|
|
|
assert update_data.local
|
|
|
|
assert update_data.data["type"] == "Delete"
|
2021-11-03 16:45:32 +00:00
|
|
|
assert update_data.data["object"]["type"] == "Tombstone"
|
2020-07-09 15:24:28 +00:00
|
|
|
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 07:57:00 +00:00
|
|
|
|
|
|
|
assert_called(Utils.maybe_federate(update_data))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-07-09 15:24:28 +00:00
|
|
|
|
|
|
|
describe "announce" do
|
|
|
|
end
|
2018-05-17 09:32:23 +00:00
|
|
|
end
|