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/transmogrifier_test.exs
|
|
|
|
|
2020-01-22 01:14:42 +00:00
|
|
|
defmodule Mobilizon.Federation.ActivityPub.TransmogrifierTest do
|
2019-09-22 14:26:23 +00:00
|
|
|
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney
|
|
|
|
|
2018-12-14 16:41:55 +00:00
|
|
|
use Mobilizon.DataCase
|
|
|
|
|
|
|
|
import Mobilizon.Factory
|
2019-12-03 10:29:51 +00:00
|
|
|
import ExUnit.CaptureLog
|
2020-02-18 07:57:00 +00:00
|
|
|
import Mock
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2020-06-11 17:13:21 +00:00
|
|
|
alias Mobilizon.{Actors, Conversations, Events}
|
2020-02-18 07:57:00 +00:00
|
|
|
alias Mobilizon.Actors.{Actor, Member}
|
|
|
|
alias Mobilizon.Conversations.Comment
|
|
|
|
alias Mobilizon.Events.{Event, Participant}
|
|
|
|
alias Mobilizon.Resources.Resource
|
|
|
|
alias Mobilizon.Todos.{Todo, TodoList}
|
2020-01-22 01:14:42 +00:00
|
|
|
|
|
|
|
alias Mobilizon.Federation.ActivityPub
|
|
|
|
alias Mobilizon.Federation.ActivityPub.Utils
|
|
|
|
alias Mobilizon.Federation.ActivityPub.{Activity, Relay, Transmogrifier}
|
2020-02-18 07:57:00 +00:00
|
|
|
alias Mobilizon.Federation.ActivityStream.Convertible
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2020-01-26 20:11:16 +00:00
|
|
|
alias Mobilizon.GraphQL.API
|
2019-09-22 16:29:13 +00:00
|
|
|
|
2020-01-28 18:18:33 +00:00
|
|
|
alias Mobilizon.Web.Endpoint
|
|
|
|
|
2018-12-14 16:41:55 +00:00
|
|
|
setup_all do
|
|
|
|
HTTPoison.start()
|
|
|
|
end
|
|
|
|
|
2019-07-30 08:35:29 +00:00
|
|
|
describe "handle incoming events" do
|
|
|
|
test "it works for incoming events" do
|
2019-11-17 18:13:54 +00:00
|
|
|
use_cassette "activity_pub/fetch_mobilizon_post_activity" do
|
|
|
|
data = File.read!("test/fixtures/mobilizon-post-activity.json") |> Jason.decode!()
|
2019-07-30 08:35:29 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
{:ok, %Activity{data: data, local: false}, %Event{} = event} =
|
|
|
|
Transmogrifier.handle_incoming(data)
|
2019-07-30 08:35:29 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
assert data["id"] ==
|
|
|
|
"https://test.mobilizon.org/events/39026210-0c69-4238-b3cc-986f33f98ed0/activity"
|
2019-07-30 08:35:29 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
assert data["to"] == ["https://www.w3.org/ns/activitystreams#Public"]
|
2019-12-20 12:04:34 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
#
|
|
|
|
# assert data["cc"] == [
|
|
|
|
# "https://framapiaf.org/users/admin/followers",
|
|
|
|
# "http://localtesting.pleroma.lol/users/lain"
|
|
|
|
# ]
|
2019-07-30 08:35:29 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
assert data["actor"] == "https://test.mobilizon.org/@Alicia"
|
2019-07-30 08:35:29 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
object = data["object"]
|
2019-07-30 08:35:29 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
assert object["id"] ==
|
|
|
|
"https://test.mobilizon.org/events/39026210-0c69-4238-b3cc-986f33f98ed0"
|
2019-07-30 08:35:29 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
assert object["to"] == ["https://www.w3.org/ns/activitystreams#Public"]
|
2019-07-30 08:35:29 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
# assert object["cc"] == [
|
|
|
|
# "https://framapiaf.org/users/admin/followers",
|
|
|
|
# "http://localtesting.pleroma.lol/users/lain"
|
|
|
|
# ]
|
2019-07-30 08:35:29 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
assert object["actor"] == "https://test.mobilizon.org/@Alicia"
|
|
|
|
assert object["location"]["name"] == "Locaux de Framasoft"
|
|
|
|
assert object["attributedTo"] == "https://test.mobilizon.org/@Alicia"
|
2019-07-30 08:35:29 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
assert event.physical_address.street == "10 Rue Jangot"
|
2019-07-30 08:35:29 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
assert event.physical_address.url ==
|
|
|
|
"https://event1.tcit.fr/address/eeecc11d-0030-43e8-a897-6422876372jd"
|
2019-07-30 08:35:29 +00:00
|
|
|
|
2020-02-07 17:41:36 +00:00
|
|
|
assert event.online_address == "https://google.com"
|
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
{:ok, %Actor{}} = Actors.get_actor_by_url(object["actor"])
|
|
|
|
end
|
2019-07-30 08:35:29 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
describe "handle incoming comments" do
|
2019-12-17 08:28:44 +00:00
|
|
|
test "it ignores an incoming comment if we already have it" do
|
|
|
|
comment = insert(:comment)
|
|
|
|
|
|
|
|
activity = %{
|
|
|
|
"type" => "Create",
|
|
|
|
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
|
|
|
|
"actor" => comment.actor.url,
|
|
|
|
"object" => Convertible.model_to_as(comment)
|
|
|
|
}
|
|
|
|
|
|
|
|
data =
|
|
|
|
File.read!("test/fixtures/mastodon-post-activity.json")
|
|
|
|
|> Jason.decode!()
|
|
|
|
|> Map.put("object", activity["object"])
|
|
|
|
|
|
|
|
assert {:ok, nil, _} = Transmogrifier.handle_incoming(data)
|
|
|
|
end
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-11-15 17:36:47 +00:00
|
|
|
test "it fetches replied-to activities if we don't have them" do
|
|
|
|
data =
|
|
|
|
File.read!("test/fixtures/mastodon-post-activity.json")
|
|
|
|
|> Jason.decode!()
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-11-15 17:36:47 +00:00
|
|
|
object =
|
|
|
|
data["object"]
|
|
|
|
|> Map.put("inReplyTo", "https://blob.cat/objects/02fdea3d-932c-4348-9ecb-3f9eb3fbdd94")
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-11-15 17:36:47 +00:00
|
|
|
data =
|
|
|
|
data
|
|
|
|
|> Map.put("object", object)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-11-15 17:36:47 +00:00
|
|
|
{:ok, returned_activity, _} = Transmogrifier.handle_incoming(data)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-11-15 17:36:47 +00:00
|
|
|
%Comment{} =
|
|
|
|
origin_comment =
|
2020-02-18 07:57:00 +00:00
|
|
|
Conversations.get_comment_from_url(
|
2019-11-15 17:36:47 +00:00
|
|
|
"https://blob.cat/objects/02fdea3d-932c-4348-9ecb-3f9eb3fbdd94"
|
|
|
|
)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-11-15 17:36:47 +00:00
|
|
|
assert returned_activity.data["object"]["inReplyTo"] ==
|
|
|
|
"https://blob.cat/objects/02fdea3d-932c-4348-9ecb-3f9eb3fbdd94"
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-11-15 17:36:47 +00:00
|
|
|
assert returned_activity.data["object"]["inReplyTo"] == origin_comment.url
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it does not crash if the object in inReplyTo can't be fetched" do
|
|
|
|
data =
|
|
|
|
File.read!("test/fixtures/mastodon-post-activity.json")
|
|
|
|
|> Poison.decode!()
|
|
|
|
|
|
|
|
object =
|
|
|
|
data["object"]
|
|
|
|
|> Map.put("inReplyTo", "https://404.site/whatever")
|
|
|
|
|
|
|
|
data =
|
|
|
|
data
|
|
|
|
|> Map.put("object", object)
|
|
|
|
|
2019-12-03 10:29:51 +00:00
|
|
|
assert capture_log([level: :warn], fn ->
|
2019-11-15 17:36:47 +00:00
|
|
|
{:ok, _returned_activity, _entity} = Transmogrifier.handle_incoming(data)
|
|
|
|
end) =~ "[warn] Parent object is something we don't handle"
|
|
|
|
end
|
2018-12-14 16:41:55 +00:00
|
|
|
|
|
|
|
test "it works for incoming notices" do
|
2019-11-17 18:13:54 +00:00
|
|
|
use_cassette "activity_pub/mastodon_post_activity" do
|
|
|
|
data = File.read!("test/fixtures/mastodon-post-activity.json") |> Jason.decode!()
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
{:ok, %Activity{data: data, local: false}, _} = Transmogrifier.handle_incoming(data)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
assert data["id"] ==
|
|
|
|
"https://framapiaf.org/users/admin/statuses/99512778738411822/activity"
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-12-03 10:29:51 +00:00
|
|
|
assert data["to"] == [
|
|
|
|
"https://www.w3.org/ns/activitystreams#Public",
|
|
|
|
"https://framapiaf.org/users/tcit"
|
|
|
|
]
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
# assert data["cc"] == [
|
|
|
|
# "https://framapiaf.org/users/admin/followers",
|
|
|
|
# "http://mobilizon.com/@tcit"
|
|
|
|
# ]
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
assert data["actor"] == "https://framapiaf.org/users/admin"
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
object = data["object"]
|
|
|
|
assert object["id"] == "https://framapiaf.org/users/admin/statuses/99512778738411822"
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
assert object["to"] == ["https://www.w3.org/ns/activitystreams#Public"]
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
# assert object["cc"] == [
|
|
|
|
# "https://framapiaf.org/users/admin/followers",
|
|
|
|
# "http://localtesting.pleroma.lol/users/lain"
|
|
|
|
# ]
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
assert object["actor"] == "https://framapiaf.org/users/admin"
|
|
|
|
assert object["attributedTo"] == "https://framapiaf.org/users/admin"
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
{:ok, %Actor{}} = Actors.get_actor_by_url(object["actor"])
|
|
|
|
end
|
2018-12-14 16:41:55 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test "it works for incoming notices with hashtags" do
|
2019-11-17 18:13:54 +00:00
|
|
|
use_cassette "activity_pub/mastodon_activity_hashtag" do
|
|
|
|
data = File.read!("test/fixtures/mastodon-post-activity-hashtag.json") |> Jason.decode!()
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
{:ok, %Activity{data: data, local: false}, _} = Transmogrifier.handle_incoming(data)
|
|
|
|
assert Enum.at(data["object"]["tag"], 0)["name"] == "@tcit@framapiaf.org"
|
|
|
|
assert Enum.at(data["object"]["tag"], 1)["name"] == "#moo"
|
|
|
|
end
|
2018-12-14 16:41:55 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# test "it works for incoming notices with contentMap" do
|
|
|
|
# data =
|
2019-02-14 13:19:55 +00:00
|
|
|
# File.read!("test/fixtures/mastodon-post-activity-contentmap.json") |> Jason.decode!()
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-07-30 08:35:29 +00:00
|
|
|
# {:ok, %Activity{data: data, local: false}, _} = Transmogrifier.handle_incoming(data)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
|
|
|
# assert data["object"]["content"] ==
|
|
|
|
# "<p><span class=\"h-card\"><a href=\"http://localtesting.pleroma.lol/users/lain\" class=\"u-url mention\">@<span>lain</span></a></span></p>"
|
|
|
|
# end
|
|
|
|
|
|
|
|
# test "it works for incoming notices with to/cc not being an array (kroeg)" do
|
2019-02-14 13:19:55 +00:00
|
|
|
# data = File.read!("test/fixtures/kroeg-post-activity.json") |> Jason.decode!()
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-07-30 08:35:29 +00:00
|
|
|
# {:ok, %Activity{data: data, local: false}, _} = Transmogrifier.handle_incoming(data)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
|
|
|
# assert data["object"]["content"] ==
|
|
|
|
# "<p>henlo from my Psion netBook</p><p>message sent from my Psion netBook</p>"
|
|
|
|
# end
|
|
|
|
|
|
|
|
# test "it works for incoming announces with actor being inlined (kroeg)" do
|
2019-02-14 13:19:55 +00:00
|
|
|
# data = File.read!("test/fixtures/kroeg-announce-with-inline-actor.json") |> Jason.decode!()
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-07-30 08:35:29 +00:00
|
|
|
# {:ok, %Activity{data: data, local: false}, _} = Transmogrifier.handle_incoming(data)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
|
|
|
# assert data["actor"] == "https://puckipedia.com/"
|
|
|
|
# end
|
|
|
|
|
|
|
|
# test "it works for incoming notices with tag not being an array (kroeg)" do
|
2019-02-14 13:19:55 +00:00
|
|
|
# data = File.read!("test/fixtures/kroeg-array-less-emoji.json") |> Jason.decode!()
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-07-30 08:35:29 +00:00
|
|
|
# {:ok, %Activity{data: data, local: false}, _} = Transmogrifier.handle_incoming(data)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
|
|
|
# assert data["object"]["emoji"] == %{
|
|
|
|
# "icon_e_smile" => "https://puckipedia.com/forum/images/smilies/icon_e_smile.png"
|
|
|
|
# }
|
|
|
|
|
2019-02-14 13:19:55 +00:00
|
|
|
# data = File.read!("test/fixtures/kroeg-array-less-hashtag.json") |> Jason.decode!()
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-07-30 08:35:29 +00:00
|
|
|
# {:ok, %Activity{data: data, local: false}, _} = Transmogrifier.handle_incoming(data)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
|
|
|
# assert "test" in data["object"]["tag"]
|
|
|
|
# end
|
|
|
|
|
|
|
|
test "it works for incoming notices with url not being a string (prismo)" do
|
2019-02-14 13:19:55 +00:00
|
|
|
data = File.read!("test/fixtures/prismo-url-map.json") |> Jason.decode!()
|
2018-12-14 16:41:55 +00:00
|
|
|
|
|
|
|
assert {:error, :not_supported} == Transmogrifier.handle_incoming(data)
|
|
|
|
# Pages are not supported
|
|
|
|
# {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
|
|
|
|
|
|
|
# assert data["object"]["url"] == "https://prismo.news/posts/83"
|
|
|
|
end
|
2020-02-18 07:57:00 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "handle incoming todo lists" do
|
|
|
|
test "it ignores an incoming todo list if we already have it" do
|
|
|
|
todo_list = insert(:todo_list)
|
|
|
|
actor = insert(:actor)
|
|
|
|
|
|
|
|
activity = %{
|
|
|
|
"type" => "Create",
|
|
|
|
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
|
|
|
|
"actor" => actor.url,
|
|
|
|
"object" => Convertible.model_to_as(todo_list)
|
|
|
|
}
|
|
|
|
|
|
|
|
data =
|
|
|
|
File.read!("test/fixtures/mastodon-post-activity.json")
|
|
|
|
|> Jason.decode!()
|
|
|
|
|> Map.put("object", activity["object"])
|
|
|
|
|
|
|
|
assert {:ok, nil, _} = Transmogrifier.handle_incoming(data)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it accepts incoming todo lists" do
|
|
|
|
actor = insert(:actor)
|
|
|
|
group = insert(:group, domain: "morebilizon.com")
|
|
|
|
|
|
|
|
activity = %{
|
|
|
|
"type" => "Create",
|
|
|
|
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
|
|
|
|
"actor" => actor.url,
|
|
|
|
"object" => %{
|
|
|
|
"type" => "TodoList",
|
|
|
|
"actor" => group.url,
|
|
|
|
"id" => "https://mobilizon.app/todo-list/gjfkghfkd",
|
|
|
|
"name" => "My new todo list"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert {:ok, %Activity{data: data, local: false}, %TodoList{}} =
|
|
|
|
Transmogrifier.handle_incoming(activity)
|
|
|
|
|
|
|
|
assert data["actor"] == actor.url
|
|
|
|
assert data["object"]["actor"] == group.url
|
|
|
|
end
|
|
|
|
|
|
|
|
@mobilizon_group_url "https://mobilizon.app/@mygroupe"
|
|
|
|
test "it accepts incoming todo lists and fetches the group if needed" do
|
|
|
|
group = insert(:group, domain: "morebilizon.com", url: @mobilizon_group_url)
|
|
|
|
%Actor{url: actor_url} = actor = insert(:actor)
|
|
|
|
|
|
|
|
with_mock ActivityPub, [:passthrough],
|
|
|
|
get_or_fetch_actor_by_url: fn url ->
|
|
|
|
case url do
|
|
|
|
@mobilizon_group_url -> {:ok, group}
|
|
|
|
actor_url -> {:ok, actor}
|
|
|
|
end
|
|
|
|
end do
|
|
|
|
activity = %{
|
|
|
|
"type" => "Create",
|
|
|
|
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
|
|
|
|
"actor" => actor.url,
|
|
|
|
"object" => %{
|
|
|
|
"type" => "TodoList",
|
|
|
|
"actor" => @mobilizon_group_url,
|
|
|
|
"id" => "https://mobilizon.app/todo-list/gjfkghfkd",
|
|
|
|
"name" => "My new todo list"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert {:ok, %Activity{data: data, local: false}, %TodoList{}} =
|
|
|
|
Transmogrifier.handle_incoming(activity)
|
|
|
|
|
|
|
|
assert data["actor"] == actor.url
|
|
|
|
assert data["object"]["actor"] == @mobilizon_group_url
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it accepts incoming todo lists and handles group being not found" do
|
|
|
|
%Actor{url: actor_url} = actor = insert(:actor)
|
|
|
|
|
|
|
|
with_mock ActivityPub, [:passthrough],
|
|
|
|
get_or_fetch_actor_by_url: fn url ->
|
|
|
|
case url do
|
|
|
|
@mobilizon_group_url -> {:error, "Not found"}
|
|
|
|
^actor_url -> {:ok, actor}
|
|
|
|
end
|
|
|
|
end do
|
|
|
|
activity = %{
|
|
|
|
"type" => "Create",
|
|
|
|
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
|
|
|
|
"actor" => actor_url,
|
|
|
|
"object" => %{
|
|
|
|
"type" => "TodoList",
|
|
|
|
"actor" => @mobilizon_group_url,
|
|
|
|
"id" => "https://mobilizon.app/todo-list/gjfkghfkd",
|
|
|
|
"name" => "My new todo list"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert :error = Transmogrifier.handle_incoming(activity)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "handle incoming todos" do
|
|
|
|
test "it ignores an incoming todo if we already have it" do
|
|
|
|
todo = insert(:todo)
|
|
|
|
actor = insert(:actor)
|
|
|
|
|
|
|
|
activity = %{
|
|
|
|
"type" => "Create",
|
|
|
|
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
|
|
|
|
"actor" => actor.url,
|
|
|
|
"object" => Convertible.model_to_as(todo)
|
|
|
|
}
|
|
|
|
|
|
|
|
data =
|
|
|
|
File.read!("test/fixtures/mastodon-post-activity.json")
|
|
|
|
|> Jason.decode!()
|
|
|
|
|> Map.put("object", activity["object"])
|
|
|
|
|
|
|
|
assert {:ok, nil, _} = Transmogrifier.handle_incoming(data)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it accepts incoming todos" do
|
|
|
|
actor = insert(:actor)
|
|
|
|
todo_list = insert(:todo_list)
|
|
|
|
|
|
|
|
activity = %{
|
|
|
|
"type" => "Create",
|
|
|
|
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
|
|
|
|
"actor" => actor.url,
|
|
|
|
"object" => %{
|
|
|
|
"type" => "Todo",
|
|
|
|
"actor" => actor.url,
|
|
|
|
"todoList" => todo_list.url,
|
|
|
|
"id" => "https://mobilizon.app/todo/gjfkghfkd",
|
|
|
|
"name" => "My new todo",
|
|
|
|
"status" => false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert {:ok, %Activity{data: data, local: false},
|
|
|
|
%Todo{todo_list: %TodoList{id: todo_list_id}}} =
|
|
|
|
Transmogrifier.handle_incoming(activity)
|
|
|
|
|
|
|
|
assert data["actor"] == actor.url
|
|
|
|
assert data["object"]["todoList"] == todo_list.url
|
|
|
|
assert todo_list_id == todo_list.id
|
|
|
|
end
|
|
|
|
|
|
|
|
@mobilizon_group_url "https://mobilizon.app/@mygroupe"
|
|
|
|
test "it accepts incoming todos and fetches the todo list if needed" do
|
|
|
|
group = insert(:group, domain: "morebilizon.com", url: @mobilizon_group_url)
|
|
|
|
%Actor{url: actor_url} = actor = insert(:actor)
|
|
|
|
|
|
|
|
with_mock ActivityPub, [:passthrough],
|
|
|
|
get_or_fetch_actor_by_url: fn url ->
|
|
|
|
case url do
|
|
|
|
@mobilizon_group_url -> {:ok, group}
|
|
|
|
actor_url -> {:ok, actor}
|
|
|
|
end
|
|
|
|
end do
|
|
|
|
activity = %{
|
|
|
|
"type" => "Create",
|
|
|
|
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
|
|
|
|
"actor" => actor.url,
|
|
|
|
"object" => %{
|
|
|
|
"type" => "TodoList",
|
|
|
|
"actor" => @mobilizon_group_url,
|
|
|
|
"id" => "https://mobilizon.app/todo-list/gjfkghfkd",
|
|
|
|
"name" => "My new todo list"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert {:ok, %Activity{data: data, local: false}, %TodoList{}} =
|
|
|
|
Transmogrifier.handle_incoming(activity)
|
|
|
|
|
|
|
|
assert data["actor"] == actor.url
|
|
|
|
assert data["object"]["actor"] == @mobilizon_group_url
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it accepts incoming todo lists and handles group being not found" do
|
|
|
|
%Actor{url: actor_url} = actor = insert(:actor)
|
|
|
|
|
|
|
|
with_mock ActivityPub, [:passthrough],
|
|
|
|
get_or_fetch_actor_by_url: fn url ->
|
|
|
|
case url do
|
|
|
|
@mobilizon_group_url -> {:error, "Not found"}
|
|
|
|
^actor_url -> {:ok, actor}
|
|
|
|
end
|
|
|
|
end do
|
|
|
|
activity = %{
|
|
|
|
"type" => "Create",
|
|
|
|
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
|
|
|
|
"actor" => actor_url,
|
|
|
|
"object" => %{
|
|
|
|
"type" => "TodoList",
|
|
|
|
"actor" => @mobilizon_group_url,
|
|
|
|
"id" => "https://mobilizon.app/todo-list/gjfkghfkd",
|
|
|
|
"name" => "My new todo list"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert :error = Transmogrifier.handle_incoming(activity)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "handle incoming resources" do
|
|
|
|
test "it ignores an incoming resource if we already have it" do
|
|
|
|
actor = insert(:actor)
|
|
|
|
group = insert(:group)
|
|
|
|
%Resource{} = resource = insert(:resource, actor: group, creator: actor)
|
|
|
|
|
|
|
|
activity = %{
|
|
|
|
"type" => "Add",
|
|
|
|
"to" => [group.url],
|
|
|
|
"actor" => actor.url,
|
|
|
|
"target" => group.resources_url,
|
|
|
|
"object" => Convertible.model_to_as(resource)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert {:ok, nil, _} = Transmogrifier.handle_incoming(activity)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it accepts incoming resources" do
|
|
|
|
creator =
|
|
|
|
insert(:actor,
|
|
|
|
domain: "mobilizon.app",
|
|
|
|
url: "https://mobilizon.app/@myremoteactor",
|
|
|
|
preferred_username: "myremoteactor"
|
|
|
|
)
|
|
|
|
|
|
|
|
group =
|
|
|
|
insert(:group,
|
|
|
|
domain: "somewhere.com",
|
|
|
|
url: "https://somewhere.com/@myremotegroup",
|
|
|
|
preferred_username: "myremotegroup"
|
|
|
|
)
|
|
|
|
|
|
|
|
insert(:member, parent: group, actor: creator, role: :member)
|
|
|
|
|
|
|
|
activity = %{
|
|
|
|
"type" => "Add",
|
|
|
|
"to" => [group.url],
|
|
|
|
"actor" => creator.url,
|
|
|
|
"target" => group.resources_url,
|
|
|
|
"object" => %{
|
|
|
|
"type" => "Document",
|
|
|
|
"actor" => creator.url,
|
|
|
|
"attributedTo" => [group.url],
|
|
|
|
"id" => "https://mobilizon.app/resource/gjfkghfkd",
|
|
|
|
"name" => "My new resource",
|
|
|
|
"summary" => "A description for the resource",
|
|
|
|
"url" => "https://framasoft.org"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert {:ok, %Activity{data: data, local: false}, %Resource{} = resource} =
|
|
|
|
Transmogrifier.handle_incoming(activity)
|
|
|
|
|
|
|
|
assert resource.actor_id == group.id
|
|
|
|
assert resource.creator_id == creator.id
|
|
|
|
assert resource.title == "My new resource"
|
|
|
|
assert resource.type == :link
|
|
|
|
assert is_nil(resource.parent_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it accepts incoming folders" do
|
|
|
|
creator =
|
|
|
|
insert(:actor,
|
|
|
|
domain: "mobilizon.app",
|
|
|
|
url: "https://mobilizon.app/@myremoteactor",
|
|
|
|
preferred_username: "myremoteactor"
|
|
|
|
)
|
|
|
|
|
|
|
|
group =
|
|
|
|
insert(:group,
|
|
|
|
domain: "somewhere.com",
|
|
|
|
url: "https://somewhere.com/@myremotegroup",
|
|
|
|
preferred_username: "myremotegroup"
|
|
|
|
)
|
|
|
|
|
|
|
|
insert(:member, parent: group, actor: creator, role: :member)
|
|
|
|
|
|
|
|
activity = %{
|
|
|
|
"type" => "Add",
|
|
|
|
"to" => [group.url],
|
|
|
|
"actor" => creator.url,
|
|
|
|
"target" => group.resources_url,
|
|
|
|
"object" => %{
|
|
|
|
"type" => "ResourceCollection",
|
|
|
|
"actor" => creator.url,
|
|
|
|
"attributedTo" => [group.url],
|
|
|
|
"id" => "https://mobilizon.app/resource/gjfkghfkd",
|
|
|
|
"name" => "My new folder"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert {:ok, %Activity{data: data, local: false}, %Resource{} = resource} =
|
|
|
|
Transmogrifier.handle_incoming(activity)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
assert resource.actor_id == group.id
|
|
|
|
assert resource.creator_id == creator.id
|
|
|
|
assert resource.title == "My new folder"
|
|
|
|
assert resource.type == :folder
|
|
|
|
assert is_nil(resource.parent_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it accepts incoming resources that are in a folder" do
|
|
|
|
creator =
|
|
|
|
insert(:actor,
|
|
|
|
domain: "mobilizon1.com",
|
|
|
|
url: "http://mobilizon1.com/@tcit",
|
|
|
|
preferred_username: "tcit",
|
|
|
|
user: nil
|
|
|
|
)
|
|
|
|
|
|
|
|
group =
|
|
|
|
insert(:group,
|
|
|
|
domain: "mobilizon1.com",
|
|
|
|
url: "http://mobilizon1.com/@demo",
|
|
|
|
preferred_username: "demo",
|
|
|
|
resources_url: "http://mobilizon1.com/@demo/resources"
|
|
|
|
)
|
|
|
|
|
|
|
|
insert(:member, parent: group, actor: creator, role: :member)
|
|
|
|
|
|
|
|
parent_resource =
|
|
|
|
insert(:resource,
|
|
|
|
type: :folder,
|
|
|
|
title: "folder",
|
|
|
|
path: "/folder",
|
|
|
|
actor: group,
|
|
|
|
creator: creator
|
|
|
|
)
|
|
|
|
|
|
|
|
activity = %{
|
|
|
|
"type" => "Add",
|
|
|
|
"to" => [group.url],
|
|
|
|
"actor" => creator.url,
|
|
|
|
"target" => parent_resource.url,
|
|
|
|
"object" => %{
|
|
|
|
"type" => "Document",
|
|
|
|
"actor" => creator.url,
|
|
|
|
"attributedTo" => [group.url],
|
|
|
|
"id" => "https://mobilizon.app/resource/gjfkghfkd",
|
|
|
|
"name" => "My new resource",
|
|
|
|
"summary" => "A description for the resource",
|
|
|
|
"context" => parent_resource.url,
|
|
|
|
"url" => "https://framasoft.org"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert {:ok, %Activity{data: data, local: false}, %Resource{} = resource} =
|
|
|
|
Transmogrifier.handle_incoming(activity)
|
|
|
|
|
|
|
|
assert resource.actor_id == group.id
|
|
|
|
assert resource.creator_id == creator.id
|
|
|
|
assert resource.title == "My new resource"
|
|
|
|
assert resource.type == :link
|
|
|
|
refute is_nil(resource.parent_id)
|
|
|
|
assert resource.parent_id == parent_resource.id
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it accepts incoming resources and handles group being not found" do
|
|
|
|
creator =
|
|
|
|
insert(:actor,
|
|
|
|
domain: "mobilizon.app",
|
|
|
|
url: "https://mobilizon.app/@myremoteactor",
|
|
|
|
preferred_username: "myremoteactor"
|
|
|
|
)
|
|
|
|
|
|
|
|
group =
|
|
|
|
insert(:group,
|
|
|
|
domain: "somewhere.com",
|
|
|
|
url: "https://somewhere.com/@myremotegroup",
|
|
|
|
preferred_username: "myremotegroup"
|
|
|
|
)
|
|
|
|
|
|
|
|
insert(:member, parent: group, actor: creator, role: :member)
|
|
|
|
|
|
|
|
activity = %{
|
|
|
|
"type" => "Add",
|
|
|
|
"to" => [group.url],
|
|
|
|
"actor" => creator.url,
|
|
|
|
"target" => group.resources_url,
|
|
|
|
"object" => %{
|
|
|
|
"type" => "Document",
|
|
|
|
"actor" => "https://someurl.com/notfound",
|
|
|
|
"attributedTo" => "https://someurl.com/notfound",
|
|
|
|
"id" => "https://mobilizon.app/resource/gjfkghfkd",
|
|
|
|
"name" => "My new resource",
|
|
|
|
"summary" => "A description for the resource",
|
|
|
|
"url" => "https://framasoft.org"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert :error = Transmogrifier.handle_incoming(activity)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it refuses incoming resources if actor is not a member of the group" do
|
|
|
|
creator =
|
|
|
|
insert(:actor,
|
|
|
|
domain: "mobilizon.app",
|
|
|
|
url: "https://mobilizon.app/@myremoteactor",
|
|
|
|
preferred_username: "myremoteactor"
|
|
|
|
)
|
|
|
|
|
|
|
|
group =
|
|
|
|
insert(:group,
|
|
|
|
domain: "somewhere.com",
|
|
|
|
url: "https://somewhere.com/@myremotegroup",
|
|
|
|
preferred_username: "myremotegroup"
|
|
|
|
)
|
|
|
|
|
|
|
|
activity = %{
|
|
|
|
"type" => "Add",
|
|
|
|
"to" => [group.url],
|
|
|
|
"actor" => creator.url,
|
|
|
|
"target" => group.resources_url,
|
|
|
|
"object" => %{
|
|
|
|
"type" => "Document",
|
|
|
|
"actor" => creator.url,
|
|
|
|
"attributedTo" => [group.url],
|
|
|
|
"id" => "https://mobilizon.app/resource/gjfkghfkd",
|
|
|
|
"name" => "My new resource",
|
|
|
|
"summary" => "A description for the resource",
|
|
|
|
"url" => "https://framasoft.org"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert :error = Transmogrifier.handle_incoming(activity)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "handle incoming follow requests" do
|
2018-12-14 16:41:55 +00:00
|
|
|
test "it works for incoming follow requests" do
|
2019-11-17 18:13:54 +00:00
|
|
|
use_cassette "activity_pub/mastodon_follow_activity" do
|
|
|
|
actor = insert(:actor)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
data =
|
|
|
|
File.read!("test/fixtures/mastodon-follow-activity.json")
|
|
|
|
|> Jason.decode!()
|
|
|
|
|> Map.put("object", actor.url)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
{:ok, %Activity{data: data, local: false}, _} = Transmogrifier.handle_incoming(data)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
assert data["actor"] == "https://social.tcit.fr/users/tcit"
|
|
|
|
assert data["type"] == "Follow"
|
|
|
|
assert data["id"] == "https://social.tcit.fr/users/tcit#follows/2"
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
actor = Actors.get_actor_with_preload(actor.id)
|
|
|
|
assert Actors.is_following(Actors.get_actor_by_url!(data["actor"], true), actor)
|
|
|
|
end
|
2018-12-14 16:41:55 +00:00
|
|
|
end
|
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
test "it rejects activities without a valid ID" do
|
|
|
|
actor = insert(:actor)
|
|
|
|
|
|
|
|
data =
|
|
|
|
File.read!("test/fixtures/mastodon-follow-activity.json")
|
|
|
|
|> Jason.decode!()
|
|
|
|
|> Map.put("object", actor.url)
|
|
|
|
|> Map.put("id", "")
|
|
|
|
|
|
|
|
:error = Transmogrifier.handle_incoming(data)
|
|
|
|
end
|
|
|
|
|
2018-12-14 16:41:55 +00:00
|
|
|
# test "it works for incoming follow requests from hubzilla" do
|
|
|
|
# user = insert(:user)
|
|
|
|
|
|
|
|
# data =
|
|
|
|
# File.read!("test/fixtures/hubzilla-follow-activity.json")
|
2019-02-14 13:19:55 +00:00
|
|
|
# |> Jason.decode!()
|
2018-12-14 16:41:55 +00:00
|
|
|
# |> Map.put("object", user.ap_id)
|
|
|
|
# |> Utils.normalize_params()
|
|
|
|
|
|
|
|
# {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
|
|
|
|
|
|
|
# assert data["actor"] == "https://hubzilla.example.org/channel/kaniini"
|
|
|
|
# assert data["type"] == "Follow"
|
|
|
|
# assert data["id"] == "https://hubzilla.example.org/channel/kaniini#follows/2"
|
2019-09-11 01:16:37 +00:00
|
|
|
# assert User.is_following(User.get_by_ap_id(data["actor"]), user)
|
2018-12-14 16:41:55 +00:00
|
|
|
# end
|
2020-02-18 07:57:00 +00:00
|
|
|
end
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
# test "it works for incoming likes" do
|
|
|
|
# %Comment{url: url} = insert(:comment)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
# data =
|
|
|
|
# File.read!("test/fixtures/mastodon-like.json")
|
|
|
|
# |> Jason.decode!()
|
|
|
|
# |> Map.put("object", url)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
# {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
# assert data["actor"] == "http://mastodon.example.org/users/admin"
|
|
|
|
# assert data["type"] == "Like"
|
|
|
|
# assert data["id"] == "http://mastodon.example.org/users/admin#likes/2"
|
|
|
|
# assert data["object"] == url
|
|
|
|
# end
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
# test "it returns an error for incoming unlikes wihout a like activity" do
|
|
|
|
# %Comment{url: url} = insert(:comment)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
# data =
|
|
|
|
# File.read!("test/fixtures/mastodon-undo-like.json")
|
|
|
|
# |> Jason.decode!()
|
|
|
|
# |> Map.put("object", url)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
# assert Transmogrifier.handle_incoming(data) == {:error, :not_supported}
|
|
|
|
# end
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
# test "it works for incoming unlikes with an existing like activity" do
|
|
|
|
# comment = insert(:comment)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
# like_data =
|
|
|
|
# File.read!("test/fixtures/mastodon-like.json")
|
|
|
|
# |> Jason.decode!()
|
|
|
|
# |> Map.put("object", comment.url)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
# {:ok, %Activity{data: like_data, local: false}} = Transmogrifier.handle_incoming(like_data)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
# data =
|
|
|
|
# File.read!("test/fixtures/mastodon-undo-like.json")
|
|
|
|
# |> Jason.decode!()
|
|
|
|
# |> Map.put("object", like_data)
|
|
|
|
# |> Map.put("actor", like_data["actor"])
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
# {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
# assert data["actor"] == "http://mastodon.example.org/users/admin"
|
|
|
|
# assert data["type"] == "Undo"
|
|
|
|
# assert data["id"] == "http://mastodon.example.org/users/admin#likes/2/undo"
|
|
|
|
# assert data["object"]["id"] == "http://mastodon.example.org/users/admin#likes/2"
|
|
|
|
# end
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
describe "handle incoming follow announces" do
|
2019-07-30 14:40:59 +00:00
|
|
|
test "it works for incoming announces" do
|
2019-11-17 18:13:54 +00:00
|
|
|
use_cassette "activity_pub/mastodon_announce_activity" do
|
|
|
|
data = File.read!("test/fixtures/mastodon-announce.json") |> Jason.decode!()
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
{:ok, %Activity{data: data, local: false}, _} = Transmogrifier.handle_incoming(data)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
assert data["actor"] == "https://framapiaf.org/users/Framasoft"
|
|
|
|
assert data["type"] == "Announce"
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
assert data["id"] ==
|
|
|
|
"https://framapiaf.org/users/Framasoft/statuses/102501959686438400/activity"
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
assert data["object"] ==
|
|
|
|
"https://framapiaf.org/users/Framasoft/statuses/102501959686438400"
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
assert %Comment{} = Conversations.get_comment_from_url(data["object"])
|
2019-11-17 18:13:54 +00:00
|
|
|
end
|
2019-07-30 14:40:59 +00:00
|
|
|
end
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-07-30 14:40:59 +00:00
|
|
|
test "it works for incoming announces with an existing activity" do
|
2019-11-17 18:13:54 +00:00
|
|
|
use_cassette "activity_pub/mastodon_announce_existing_activity" do
|
|
|
|
comment = insert(:comment)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
data =
|
|
|
|
File.read!("test/fixtures/mastodon-announce.json")
|
|
|
|
|> Jason.decode!()
|
|
|
|
|> Map.put("object", comment.url)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
{:ok, %Activity{data: data, local: false}, _} = Transmogrifier.handle_incoming(data)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
assert data["actor"] == "https://framapiaf.org/users/Framasoft"
|
|
|
|
assert data["type"] == "Announce"
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
assert data["id"] ==
|
|
|
|
"https://framapiaf.org/users/Framasoft/statuses/102501959686438400/activity"
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
assert data["object"] == comment.url
|
|
|
|
end
|
2019-07-30 14:40:59 +00:00
|
|
|
end
|
2020-02-18 07:57:00 +00:00
|
|
|
end
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
describe "handle incoming update activities" do
|
2019-09-04 16:24:31 +00:00
|
|
|
test "it works for incoming update activities on actors" do
|
2019-11-17 18:13:54 +00:00
|
|
|
use_cassette "activity_pub/update_actor_activity" do
|
|
|
|
data = File.read!("test/fixtures/mastodon-post-activity.json") |> Jason.decode!()
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
{:ok, %Activity{data: data, local: false}, _} = Transmogrifier.handle_incoming(data)
|
|
|
|
update_data = File.read!("test/fixtures/mastodon-update.json") |> Jason.decode!()
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
object =
|
|
|
|
update_data["object"]
|
|
|
|
|> Map.put("actor", data["actor"])
|
|
|
|
|> Map.put("id", data["actor"])
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
update_data =
|
|
|
|
update_data
|
|
|
|
|> Map.put("actor", data["actor"])
|
|
|
|
|> Map.put("object", object)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
{:ok, %Activity{data: _data, local: false}, _} =
|
|
|
|
Transmogrifier.handle_incoming(update_data)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
{:ok, %Actor{} = actor} = Actors.get_actor_by_url(update_data["actor"])
|
|
|
|
assert actor.name == "nextsoft"
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
assert actor.summary == "<p>Some bio</p>"
|
|
|
|
end
|
2018-12-14 16:41:55 +00:00
|
|
|
end
|
|
|
|
|
2019-09-04 16:24:31 +00:00
|
|
|
test "it works for incoming update activities on events" do
|
2019-11-17 18:13:54 +00:00
|
|
|
use_cassette "activity_pub/event_update_activities" do
|
|
|
|
data = File.read!("test/fixtures/mobilizon-post-activity.json") |> Jason.decode!()
|
2019-09-04 16:24:31 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
{:ok, %Activity{data: data, local: false}, _} = Transmogrifier.handle_incoming(data)
|
|
|
|
update_data = File.read!("test/fixtures/mastodon-update.json") |> Jason.decode!()
|
2019-09-04 16:24:31 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
object =
|
|
|
|
data["object"]
|
|
|
|
|> Map.put("actor", data["actor"])
|
|
|
|
|> Map.put("name", "My updated event")
|
|
|
|
|> Map.put("id", data["object"]["id"])
|
|
|
|
|> Map.put("type", "Event")
|
|
|
|
|
|
|
|
update_data =
|
|
|
|
update_data
|
|
|
|
|> Map.put("actor", data["actor"])
|
|
|
|
|> Map.put("object", object)
|
2019-09-04 16:24:31 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
{:ok, %Activity{data: data, local: false}, _} =
|
|
|
|
Transmogrifier.handle_incoming(update_data)
|
2019-09-04 16:24:31 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
%Event{} = event = Events.get_event_by_url(data["object"]["id"])
|
|
|
|
assert event.title == "My updated event"
|
2019-09-04 16:24:31 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
assert event.description == data["object"]["content"]
|
|
|
|
end
|
2019-09-04 16:24:31 +00:00
|
|
|
end
|
|
|
|
|
2018-12-14 16:41:55 +00:00
|
|
|
# test "it works for incoming update activities which lock the account" do
|
2019-02-14 13:19:55 +00:00
|
|
|
# data = File.read!("test/fixtures/mastodon-post-activity.json") |> Jason.decode!()
|
2018-12-14 16:41:55 +00:00
|
|
|
|
|
|
|
# {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
2019-02-14 13:19:55 +00:00
|
|
|
# update_data = File.read!("test/fixtures/mastodon-update.json") |> Jason.decode!()
|
2018-12-14 16:41:55 +00:00
|
|
|
|
|
|
|
# object =
|
|
|
|
# update_data["object"]
|
|
|
|
# |> Map.put("actor", data["actor"])
|
|
|
|
# |> Map.put("id", data["actor"])
|
|
|
|
# |> Map.put("manuallyApprovesFollowers", true)
|
|
|
|
|
|
|
|
# update_data =
|
|
|
|
# update_data
|
|
|
|
# |> Map.put("actor", data["actor"])
|
|
|
|
# |> Map.put("object", object)
|
|
|
|
|
|
|
|
# {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(update_data)
|
|
|
|
|
|
|
|
# user = User.get_cached_by_ap_id(data["actor"])
|
|
|
|
# assert user.info["locked"] == true
|
|
|
|
# end
|
2020-02-18 07:57:00 +00:00
|
|
|
end
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
describe "handle incoming delete activities" do
|
2018-12-14 16:41:55 +00:00
|
|
|
test "it works for incoming deletes" do
|
|
|
|
%Actor{url: actor_url} = actor = insert(:actor)
|
2019-10-25 15:43:37 +00:00
|
|
|
%Comment{url: comment_url} = insert(:comment, actor: nil, actor_id: actor.id)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
|
|
|
data =
|
|
|
|
File.read!("test/fixtures/mastodon-delete.json")
|
2019-02-14 13:19:55 +00:00
|
|
|
|> Jason.decode!()
|
2018-12-14 16:41:55 +00:00
|
|
|
|
|
|
|
object =
|
|
|
|
data["object"]
|
|
|
|
|> Map.put("id", comment_url)
|
|
|
|
|
|
|
|
data =
|
|
|
|
data
|
|
|
|
|> Map.put("object", object)
|
|
|
|
|> Map.put("actor", actor_url)
|
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
assert Conversations.get_comment_from_url(comment_url)
|
|
|
|
assert is_nil(Conversations.get_comment_from_url(comment_url).deleted_at)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-07-30 08:35:29 +00:00
|
|
|
{:ok, %Activity{local: false}, _} = Transmogrifier.handle_incoming(data)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
refute is_nil(Conversations.get_comment_from_url(comment_url).deleted_at)
|
2018-12-14 16:41:55 +00:00
|
|
|
end
|
|
|
|
|
2019-12-03 10:29:51 +00:00
|
|
|
test "it fails for incoming deletes with spoofed origin" do
|
|
|
|
comment = insert(:comment)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-12-03 10:29:51 +00:00
|
|
|
announce_data =
|
|
|
|
File.read!("test/fixtures/mastodon-announce.json")
|
|
|
|
|> Jason.decode!()
|
|
|
|
|> Map.put("object", comment.url)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-12-03 10:29:51 +00:00
|
|
|
{:ok, %Activity{local: false}, _} = Transmogrifier.handle_incoming(announce_data)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-12-03 10:29:51 +00:00
|
|
|
data =
|
|
|
|
File.read!("test/fixtures/mastodon-delete.json")
|
|
|
|
|> Jason.decode!()
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-12-03 10:29:51 +00:00
|
|
|
object =
|
|
|
|
data["object"]
|
|
|
|
|> Map.put("id", comment.url)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-12-03 10:29:51 +00:00
|
|
|
data =
|
|
|
|
data
|
|
|
|
|> Map.put("object", object)
|
|
|
|
|
|
|
|
:error = Transmogrifier.handle_incoming(data)
|
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
assert Conversations.get_comment_from_url(comment.url)
|
2019-12-03 10:29:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test "it works for incoming actor deletes" do
|
|
|
|
%Actor{url: url} = actor = insert(:actor, url: "https://framapiaf.org/users/admin")
|
|
|
|
%Event{url: event1_url} = event1 = insert(:event, organizer_actor: actor)
|
|
|
|
insert(:event, organizer_actor: actor)
|
|
|
|
|
|
|
|
%Comment{url: comment1_url} = comment1 = insert(:comment, actor: actor)
|
|
|
|
insert(:comment, actor: actor)
|
|
|
|
|
|
|
|
data =
|
|
|
|
File.read!("test/fixtures/mastodon-delete-user.json")
|
|
|
|
|> Poison.decode!()
|
|
|
|
|
|
|
|
{:ok, _activity, _actor} = Transmogrifier.handle_incoming(data)
|
|
|
|
assert %{success: 1, failure: 0} == Oban.drain_queue(:background)
|
|
|
|
|
2020-06-11 17:13:21 +00:00
|
|
|
assert {:error, :actor_not_found} = Actors.get_actor_by_url(url)
|
2019-12-03 10:29:51 +00:00
|
|
|
assert {:error, :event_not_found} = Events.get_event(event1.id)
|
2020-06-11 17:13:21 +00:00
|
|
|
# Tombstone are cascade deleted, seems correct for now
|
|
|
|
# assert %Tombstone{} = Tombstone.find_tombstone(event1_url)
|
2020-02-18 07:57:00 +00:00
|
|
|
assert %Comment{deleted_at: deleted_at} = Conversations.get_comment(comment1.id)
|
2019-12-03 10:29:51 +00:00
|
|
|
refute is_nil(deleted_at)
|
2020-06-11 17:13:21 +00:00
|
|
|
# assert %Tombstone{} = Tombstone.find_tombstone(comment1_url)
|
2019-12-03 10:29:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test "it fails for incoming actor deletes with spoofed origin" do
|
|
|
|
%{url: url} = insert(:actor)
|
|
|
|
|
|
|
|
data =
|
|
|
|
File.read!("test/fixtures/mastodon-delete-user.json")
|
|
|
|
|> Poison.decode!()
|
|
|
|
|> Map.put("actor", url)
|
|
|
|
|
|
|
|
assert capture_log(fn ->
|
|
|
|
assert :error == Transmogrifier.handle_incoming(data)
|
|
|
|
end) =~ "Object origin check failed"
|
|
|
|
|
|
|
|
assert Actors.get_actor_by_url(url)
|
|
|
|
end
|
2020-02-18 07:57:00 +00:00
|
|
|
end
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
describe "handle incoming undo activities" do
|
2019-07-30 14:40:59 +00:00
|
|
|
test "it works for incoming unannounces with an existing notice" do
|
2019-11-17 18:13:54 +00:00
|
|
|
use_cassette "activity_pub/mastodon_unannounce_activity" do
|
|
|
|
comment = insert(:comment)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
announce_data =
|
|
|
|
File.read!("test/fixtures/mastodon-announce.json")
|
|
|
|
|> Jason.decode!()
|
|
|
|
|> Map.put("object", comment.url)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
{:ok, %Activity{data: announce_data, local: false}, _} =
|
|
|
|
Transmogrifier.handle_incoming(announce_data)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
data =
|
|
|
|
File.read!("test/fixtures/mastodon-undo-announce.json")
|
|
|
|
|> Jason.decode!()
|
|
|
|
|> Map.put("object", announce_data)
|
|
|
|
|> Map.put("actor", announce_data["actor"])
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
{:ok, %Activity{data: data, local: false}, _} = Transmogrifier.handle_incoming(data)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
assert data["type"] == "Undo"
|
|
|
|
assert data["object"]["type"] == "Announce"
|
|
|
|
assert data["object"]["object"] == comment.url
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
assert data["object"]["id"] ==
|
|
|
|
"https://framapiaf.org/users/Framasoft/statuses/102501959686438400/activity"
|
|
|
|
end
|
2019-07-30 14:40:59 +00:00
|
|
|
end
|
2018-12-14 16:41:55 +00:00
|
|
|
|
|
|
|
test "it works for incomming unfollows with an existing follow" do
|
2019-11-17 18:13:54 +00:00
|
|
|
use_cassette "activity_pub/unfollow_existing_follow_activity" do
|
|
|
|
actor = insert(:actor)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
follow_data =
|
|
|
|
File.read!("test/fixtures/mastodon-follow-activity.json")
|
|
|
|
|> Jason.decode!()
|
|
|
|
|> Map.put("object", actor.url)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
{:ok, %Activity{data: _, local: false}, _} = Transmogrifier.handle_incoming(follow_data)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
data =
|
|
|
|
File.read!("test/fixtures/mastodon-unfollow-activity.json")
|
|
|
|
|> Jason.decode!()
|
|
|
|
|> Map.put("object", follow_data)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
{:ok, %Activity{data: data, local: false}, _} = Transmogrifier.handle_incoming(data)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
assert data["type"] == "Undo"
|
|
|
|
assert data["object"]["type"] == "Follow"
|
|
|
|
assert data["object"]["object"] == actor.url
|
|
|
|
assert data["actor"] == "https://social.tcit.fr/users/tcit"
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-11-17 18:13:54 +00:00
|
|
|
{:ok, followed} = Actors.get_actor_by_url(data["actor"])
|
|
|
|
refute Actors.is_following(followed, actor)
|
|
|
|
end
|
2018-12-14 16:41:55 +00:00
|
|
|
end
|
2020-02-18 07:57:00 +00:00
|
|
|
end
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
# test "it works for incoming blocks" do
|
|
|
|
# user = insert(:user)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
# data =
|
|
|
|
# File.read!("test/fixtures/mastodon-block-activity.json")
|
|
|
|
# |> Jason.decode!()
|
|
|
|
# |> Map.put("object", user.ap_id)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
# {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
# assert data["type"] == "Block"
|
|
|
|
# assert data["object"] == user.ap_id
|
|
|
|
# assert data["actor"] == "http://mastodon.example.org/users/admin"
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
# blocker = User.get_by_ap_id(data["actor"])
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
# assert User.blocks?(blocker, user)
|
|
|
|
# end
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
# test "incoming blocks successfully tear down any follow relationship" do
|
|
|
|
# blocker = insert(:user)
|
|
|
|
# blocked = insert(:user)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
# data =
|
|
|
|
# File.read!("test/fixtures/mastodon-block-activity.json")
|
|
|
|
# |> Jason.decode!()
|
|
|
|
# |> Map.put("object", blocked.ap_id)
|
|
|
|
# |> Map.put("actor", blocker.ap_id)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
# {:ok, blocker} = User.follow(blocker, blocked)
|
|
|
|
# {:ok, blocked} = User.follow(blocked, blocker)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
# assert User.following?(blocker, blocked)
|
|
|
|
# assert User.following?(blocked, blocker)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
# {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
# assert data["type"] == "Block"
|
|
|
|
# assert data["object"] == blocked.ap_id
|
|
|
|
# assert data["actor"] == blocker.ap_id
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
# blocker = User.get_by_ap_id(data["actor"])
|
|
|
|
# blocked = User.get_by_ap_id(data["object"])
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
# assert User.blocks?(blocker, blocked)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
# refute User.following?(blocker, blocked)
|
|
|
|
# refute User.following?(blocked, blocker)
|
|
|
|
# end
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
# test "it works for incoming unblocks with an existing block" do
|
|
|
|
# user = insert(:user)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
# block_data =
|
|
|
|
# File.read!("test/fixtures/mastodon-block-activity.json")
|
|
|
|
# |> Jason.decode!()
|
|
|
|
# |> Map.put("object", user.ap_id)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
# {:ok, %Activity{data: _, local: false}} = Transmogrifier.handle_incoming(block_data)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
# data =
|
|
|
|
# File.read!("test/fixtures/mastodon-unblock-activity.json")
|
|
|
|
# |> Jason.decode!()
|
|
|
|
# |> Map.put("object", block_data)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
# {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
|
|
|
# assert data["type"] == "Undo"
|
|
|
|
# assert data["object"]["type"] == "Block"
|
|
|
|
# assert data["object"]["object"] == user.ap_id
|
|
|
|
# assert data["actor"] == "http://mastodon.example.org/users/admin"
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
# blocker = User.get_by_ap_id(data["actor"])
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
# refute User.blocks?(blocker, user)
|
|
|
|
# end
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
describe "handle incoming follow accept activities" do
|
2019-07-30 14:40:59 +00:00
|
|
|
test "it works for incoming accepts which were pre-accepted" do
|
|
|
|
follower = insert(:actor)
|
|
|
|
followed = insert(:actor)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-09-11 01:16:37 +00:00
|
|
|
refute Actors.is_following(follower, followed)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-07-30 14:40:59 +00:00
|
|
|
{:ok, follow_activity, _} = ActivityPub.follow(follower, followed)
|
2019-09-11 01:16:37 +00:00
|
|
|
assert Actors.is_following(follower, followed)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-07-30 14:40:59 +00:00
|
|
|
accept_data =
|
|
|
|
File.read!("test/fixtures/mastodon-accept-activity.json")
|
|
|
|
|> Jason.decode!()
|
|
|
|
|> Map.put("actor", followed.url)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-07-30 14:40:59 +00:00
|
|
|
object =
|
|
|
|
accept_data["object"]
|
|
|
|
|> Map.put("actor", follower.url)
|
|
|
|
|> Map.put("id", follow_activity.data["id"])
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-07-30 14:40:59 +00:00
|
|
|
accept_data = Map.put(accept_data, "object", object)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-07-30 14:40:59 +00:00
|
|
|
{:ok, activity, _} = Transmogrifier.handle_incoming(accept_data)
|
|
|
|
refute activity.local
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-07-30 14:40:59 +00:00
|
|
|
assert activity.data["object"]["id"] == follow_activity.data["id"]
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-07-30 14:40:59 +00:00
|
|
|
{:ok, follower} = Actors.get_actor_by_url(follower.url)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-09-11 01:16:37 +00:00
|
|
|
assert Actors.is_following(follower, followed)
|
2019-07-30 14:40:59 +00:00
|
|
|
end
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-07-30 14:40:59 +00:00
|
|
|
test "it works for incoming accepts which are referenced by IRI only" do
|
|
|
|
follower = insert(:actor)
|
|
|
|
followed = insert(:actor)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-07-30 14:40:59 +00:00
|
|
|
{:ok, follow_activity, _} = ActivityPub.follow(follower, followed)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-07-30 14:40:59 +00:00
|
|
|
accept_data =
|
|
|
|
File.read!("test/fixtures/mastodon-accept-activity.json")
|
|
|
|
|> Jason.decode!()
|
|
|
|
|> Map.put("actor", followed.url)
|
|
|
|
|> Map.put("object", follow_activity.data["id"])
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-07-30 14:40:59 +00:00
|
|
|
{:ok, activity, _} = Transmogrifier.handle_incoming(accept_data)
|
2019-10-25 15:43:37 +00:00
|
|
|
assert activity.data["object"]["id"] == follow_activity.data["id"]
|
|
|
|
assert activity.data["object"]["id"] =~ "/follow/"
|
2019-07-30 14:40:59 +00:00
|
|
|
assert activity.data["id"] =~ "/accept/follow/"
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-07-30 14:40:59 +00:00
|
|
|
{:ok, follower} = Actors.get_actor_by_url(follower.url)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-09-11 01:16:37 +00:00
|
|
|
assert Actors.is_following(follower, followed)
|
2019-07-30 14:40:59 +00:00
|
|
|
end
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-07-30 14:40:59 +00:00
|
|
|
test "it fails for incoming accepts which cannot be correlated" do
|
|
|
|
follower = insert(:actor)
|
|
|
|
followed = insert(:actor)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-07-30 14:40:59 +00:00
|
|
|
accept_data =
|
|
|
|
File.read!("test/fixtures/mastodon-accept-activity.json")
|
|
|
|
|> Jason.decode!()
|
|
|
|
|> Map.put("actor", followed.url)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-07-30 14:40:59 +00:00
|
|
|
accept_data =
|
|
|
|
Map.put(accept_data, "object", Map.put(accept_data["object"], "actor", follower.url))
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-07-30 14:40:59 +00:00
|
|
|
:error = Transmogrifier.handle_incoming(accept_data)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-07-30 14:40:59 +00:00
|
|
|
{:ok, follower} = Actors.get_actor_by_url(follower.url)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-09-11 01:16:37 +00:00
|
|
|
refute Actors.is_following(follower, followed)
|
2019-07-30 14:40:59 +00:00
|
|
|
end
|
2020-02-18 07:57:00 +00:00
|
|
|
end
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
describe "handle incoming follow reject activities" do
|
2019-07-30 14:40:59 +00:00
|
|
|
test "it fails for incoming rejects which cannot be correlated" do
|
|
|
|
follower = insert(:actor)
|
|
|
|
followed = insert(:actor)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-07-30 14:40:59 +00:00
|
|
|
accept_data =
|
|
|
|
File.read!("test/fixtures/mastodon-reject-activity.json")
|
|
|
|
|> Jason.decode!()
|
|
|
|
|> Map.put("actor", followed.url)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-07-30 14:40:59 +00:00
|
|
|
accept_data =
|
|
|
|
Map.put(accept_data, "object", Map.put(accept_data["object"], "actor", follower.url))
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-07-30 14:40:59 +00:00
|
|
|
:error = Transmogrifier.handle_incoming(accept_data)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-07-30 14:40:59 +00:00
|
|
|
{:ok, follower} = Actors.get_actor_by_url(follower.url)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-09-11 01:16:37 +00:00
|
|
|
refute Actors.is_following(follower, followed)
|
2019-07-30 14:40:59 +00:00
|
|
|
end
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-07-30 14:40:59 +00:00
|
|
|
test "it works for incoming rejects which are referenced by IRI only" do
|
|
|
|
follower = insert(:actor)
|
|
|
|
followed = insert(:actor)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-07-30 14:40:59 +00:00
|
|
|
{:ok, follow_activity, _} = ActivityPub.follow(follower, followed)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-09-11 01:16:37 +00:00
|
|
|
assert Actors.is_following(follower, followed)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-07-30 14:40:59 +00:00
|
|
|
reject_data =
|
|
|
|
File.read!("test/fixtures/mastodon-reject-activity.json")
|
|
|
|
|> Jason.decode!()
|
|
|
|
|> Map.put("actor", followed.url)
|
|
|
|
|> Map.put("object", follow_activity.data["id"])
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-07-30 14:40:59 +00:00
|
|
|
{:ok, %Activity{data: _}, _} = Transmogrifier.handle_incoming(reject_data)
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-09-11 01:16:37 +00:00
|
|
|
refute Actors.is_following(follower, followed)
|
2019-07-30 14:40:59 +00:00
|
|
|
end
|
2020-02-18 07:57:00 +00:00
|
|
|
end
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
describe "handle incoming flag activities" do
|
2019-07-23 11:49:22 +00:00
|
|
|
test "it accepts Flag activities" do
|
2020-01-22 01:14:42 +00:00
|
|
|
%Actor{url: reporter_url} = Relay.get_actor()
|
2019-07-23 11:49:22 +00:00
|
|
|
%Actor{url: reported_url} = reported = insert(:actor)
|
|
|
|
|
|
|
|
%Comment{url: comment_url} = _comment = insert(:comment, actor: reported)
|
|
|
|
|
|
|
|
message = %{
|
|
|
|
"@context" => "https://www.w3.org/ns/activitystreams",
|
2019-12-03 10:29:51 +00:00
|
|
|
"to" => [],
|
2019-07-23 11:49:22 +00:00
|
|
|
"cc" => [reported_url],
|
|
|
|
"object" => [reported_url, comment_url],
|
|
|
|
"type" => "Flag",
|
|
|
|
"content" => "blocked AND reported!!!",
|
|
|
|
"actor" => reporter_url
|
|
|
|
}
|
|
|
|
|
|
|
|
assert {:ok, activity, _} = Transmogrifier.handle_incoming(message)
|
|
|
|
|
|
|
|
assert activity.data["object"] == [reported_url, comment_url]
|
|
|
|
assert activity.data["content"] == "blocked AND reported!!!"
|
|
|
|
assert activity.data["actor"] == reporter_url
|
2019-12-03 10:29:51 +00:00
|
|
|
assert activity.data["cc"] == []
|
2019-07-23 11:49:22 +00:00
|
|
|
end
|
2020-02-18 07:57:00 +00:00
|
|
|
end
|
2019-08-14 15:45:11 +00:00
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
describe "handle incoming join activities" do
|
2020-03-05 18:32:34 +00:00
|
|
|
@join_message "I want to get in!"
|
2019-08-14 15:45:11 +00:00
|
|
|
test "it accepts Join activities" do
|
2019-12-03 10:29:51 +00:00
|
|
|
%Actor{url: organizer_url} = organizer = insert(:actor)
|
2019-08-14 15:45:11 +00:00
|
|
|
%Actor{url: participant_url} = _participant = insert(:actor)
|
|
|
|
|
|
|
|
%Event{url: event_url} = _event = insert(:event, organizer_actor: organizer)
|
|
|
|
|
|
|
|
join_data =
|
|
|
|
File.read!("test/fixtures/mobilizon-join-activity.json")
|
|
|
|
|> Jason.decode!()
|
|
|
|
|> Map.put("actor", participant_url)
|
|
|
|
|> Map.put("object", event_url)
|
2020-03-05 18:32:34 +00:00
|
|
|
|> Map.put("participationMessage", @join_message)
|
2019-08-14 15:45:11 +00:00
|
|
|
|
2020-03-05 18:32:34 +00:00
|
|
|
assert {:ok, activity, %Participant{} = participant} =
|
|
|
|
Transmogrifier.handle_incoming(join_data)
|
|
|
|
|
|
|
|
assert participant.metadata.message == @join_message
|
|
|
|
assert participant.role == :participant
|
2019-08-14 15:45:11 +00:00
|
|
|
|
2019-12-03 10:29:51 +00:00
|
|
|
assert activity.data["type"] == "Accept"
|
|
|
|
assert activity.data["object"]["object"] == event_url
|
|
|
|
assert activity.data["object"]["id"] =~ "/join/event/"
|
|
|
|
assert activity.data["object"]["type"] =~ "Join"
|
2020-03-05 18:32:34 +00:00
|
|
|
assert activity.data["object"]["participationMessage"] == @join_message
|
2019-12-03 10:29:51 +00:00
|
|
|
assert activity.data["actor"] == organizer_url
|
|
|
|
assert activity.data["id"] =~ "/accept/join/"
|
2019-08-14 15:45:11 +00:00
|
|
|
end
|
2020-02-18 07:57:00 +00:00
|
|
|
end
|
2019-08-14 15:45:11 +00:00
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
describe "handle incoming accept join activities" do
|
2019-08-14 15:45:11 +00:00
|
|
|
test "it accepts Accept activities for Join activities" do
|
|
|
|
%Actor{url: organizer_url} = organizer = insert(:actor)
|
|
|
|
%Actor{} = participant_actor = insert(:actor)
|
|
|
|
|
|
|
|
%Event{} = event = insert(:event, organizer_actor: organizer, join_options: :restricted)
|
|
|
|
|
2019-12-20 12:04:34 +00:00
|
|
|
{:ok, join_activity, participation} =
|
|
|
|
ActivityPub.join(event, participant_actor, false, %{metadata: %{role: :not_approved}})
|
2019-08-14 15:45:11 +00:00
|
|
|
|
|
|
|
accept_data =
|
|
|
|
File.read!("test/fixtures/mastodon-accept-activity.json")
|
|
|
|
|> Jason.decode!()
|
|
|
|
|> Map.put("actor", organizer_url)
|
|
|
|
|> Map.put("object", participation.url)
|
|
|
|
|
|
|
|
{:ok, accept_activity, _} = Transmogrifier.handle_incoming(accept_data)
|
2019-10-25 15:43:37 +00:00
|
|
|
assert accept_activity.data["object"]["id"] == join_activity.data["id"]
|
|
|
|
assert accept_activity.data["object"]["id"] =~ "/join/"
|
2019-08-14 15:45:11 +00:00
|
|
|
assert accept_activity.data["id"] =~ "/accept/join/"
|
|
|
|
|
|
|
|
# We don't accept already accepted Accept activities
|
|
|
|
:error = Transmogrifier.handle_incoming(accept_data)
|
|
|
|
end
|
2020-02-18 07:57:00 +00:00
|
|
|
end
|
2019-08-14 15:45:11 +00:00
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
describe "handle incoming reject join activities" do
|
2019-08-14 15:45:11 +00:00
|
|
|
test "it accepts Reject activities for Join activities" do
|
|
|
|
%Actor{url: organizer_url} = organizer = insert(:actor)
|
|
|
|
%Actor{} = participant_actor = insert(:actor)
|
|
|
|
|
|
|
|
%Event{} = event = insert(:event, organizer_actor: organizer, join_options: :restricted)
|
|
|
|
|
|
|
|
{:ok, join_activity, participation} = ActivityPub.join(event, participant_actor)
|
|
|
|
|
|
|
|
reject_data =
|
|
|
|
File.read!("test/fixtures/mastodon-reject-activity.json")
|
|
|
|
|> Jason.decode!()
|
|
|
|
|> Map.put("actor", organizer_url)
|
|
|
|
|> Map.put("object", participation.url)
|
|
|
|
|
|
|
|
{:ok, reject_activity, _} = Transmogrifier.handle_incoming(reject_data)
|
2019-12-03 10:29:51 +00:00
|
|
|
assert reject_activity.data["object"]["id"] == join_activity.data["id"]
|
|
|
|
assert reject_activity.data["object"]["id"] =~ "/join/"
|
2019-08-14 15:45:11 +00:00
|
|
|
assert reject_activity.data["id"] =~ "/reject/join/"
|
|
|
|
|
|
|
|
# We don't accept already rejected Reject activities
|
2019-12-03 10:29:51 +00:00
|
|
|
assert capture_log([level: :warn], fn ->
|
|
|
|
assert :error == Transmogrifier.handle_incoming(reject_data)
|
|
|
|
end) =~
|
|
|
|
"Unable to process Reject activity \"http://mastodon.example.org/users/admin#rejects/follows/4\". Object \"#{
|
|
|
|
join_activity.data["id"]
|
|
|
|
}\" wasn't found."
|
2019-08-14 15:45:11 +00:00
|
|
|
|
|
|
|
# Organiser is not present since we use factories directly
|
2019-09-22 11:41:24 +00:00
|
|
|
assert event.id
|
|
|
|
|> Events.list_participants_for_event()
|
2020-03-05 18:32:34 +00:00
|
|
|
|> Map.get(:elements)
|
2019-09-22 11:41:24 +00:00
|
|
|
|> Enum.map(& &1.id) ==
|
2019-08-14 15:45:11 +00:00
|
|
|
[]
|
|
|
|
end
|
2020-02-18 07:57:00 +00:00
|
|
|
end
|
2019-08-14 15:45:11 +00:00
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
describe "handle incoming leave activities on events" do
|
2019-08-14 15:45:11 +00:00
|
|
|
test "it accepts Leave activities" do
|
|
|
|
%Actor{url: _organizer_url} = organizer = insert(:actor)
|
|
|
|
%Actor{url: participant_url} = participant_actor = insert(:actor)
|
|
|
|
|
|
|
|
%Event{url: event_url} =
|
|
|
|
event = insert(:event, organizer_actor: organizer, join_options: :restricted)
|
|
|
|
|
|
|
|
organizer_participation =
|
|
|
|
%Participant{} = insert(:participant, event: event, actor: organizer, role: :creator)
|
|
|
|
|
|
|
|
{:ok, _join_activity, _participation} = ActivityPub.join(event, participant_actor)
|
|
|
|
|
|
|
|
join_data =
|
|
|
|
File.read!("test/fixtures/mobilizon-leave-activity.json")
|
|
|
|
|> Jason.decode!()
|
|
|
|
|> Map.put("actor", participant_url)
|
|
|
|
|> Map.put("object", event_url)
|
|
|
|
|
|
|
|
assert {:ok, activity, _} = Transmogrifier.handle_incoming(join_data)
|
|
|
|
|
|
|
|
assert activity.data["object"] == event_url
|
|
|
|
assert activity.data["actor"] == participant_url
|
|
|
|
|
|
|
|
# The only participant left is the organizer
|
2019-09-22 11:41:24 +00:00
|
|
|
assert event.id
|
|
|
|
|> Events.list_participants_for_event()
|
2020-03-05 18:32:34 +00:00
|
|
|
|> Map.get(:elements)
|
2019-09-22 11:41:24 +00:00
|
|
|
|> Enum.map(& &1.id) ==
|
|
|
|
[organizer_participation.id]
|
2019-08-14 15:45:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test "it refuses Leave activities when actor is the only organizer" do
|
|
|
|
%Actor{url: organizer_url} = organizer = insert(:actor)
|
|
|
|
|
|
|
|
%Event{url: event_url} =
|
|
|
|
event = insert(:event, organizer_actor: organizer, join_options: :restricted)
|
|
|
|
|
|
|
|
%Participant{} = insert(:participant, event: event, actor: organizer, role: :creator)
|
|
|
|
|
|
|
|
join_data =
|
|
|
|
File.read!("test/fixtures/mobilizon-leave-activity.json")
|
|
|
|
|> Jason.decode!()
|
|
|
|
|> Map.put("actor", organizer_url)
|
|
|
|
|> Map.put("object", event_url)
|
|
|
|
|
|
|
|
assert :error = Transmogrifier.handle_incoming(join_data)
|
|
|
|
end
|
2018-12-14 16:41:55 +00:00
|
|
|
end
|
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
describe "handle Invite activities on group" do
|
|
|
|
test "it accepts Invite activities" do
|
|
|
|
%Actor{url: group_url, id: group_id} = group = insert(:group)
|
|
|
|
%Actor{url: group_admin_url, id: group_admin_id} = group_admin = insert(:actor)
|
|
|
|
|
|
|
|
%Member{} =
|
|
|
|
_group_admin_member =
|
|
|
|
insert(:member, parent: group, actor: group_admin, role: :administrator)
|
|
|
|
|
|
|
|
%Actor{url: invitee_url, id: invitee_id} = _invitee = insert(:actor)
|
|
|
|
|
|
|
|
invite_data =
|
|
|
|
File.read!("test/fixtures/mobilizon-invite-activity.json")
|
|
|
|
|> Jason.decode!()
|
|
|
|
|> Map.put("actor", group_admin_url)
|
|
|
|
|> Map.put("object", group_url)
|
|
|
|
|> Map.put("target", invitee_url)
|
|
|
|
|
|
|
|
assert {:ok, activity, %Member{}} = Transmogrifier.handle_incoming(invite_data)
|
|
|
|
assert %Member{} = member = Actors.get_member_by_url(invite_data["id"])
|
|
|
|
assert member.actor.id == invitee_id
|
|
|
|
assert member.parent.id == group_id
|
|
|
|
assert member.role == :invited
|
|
|
|
assert member.invited_by_id == group_admin_id
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it refuses Invite activities for " do
|
|
|
|
%Actor{url: group_url, id: group_id} = group = insert(:group)
|
|
|
|
%Actor{url: group_admin_url, id: group_admin_id} = group_admin = insert(:actor)
|
|
|
|
|
|
|
|
%Member{} =
|
|
|
|
_group_admin_member =
|
|
|
|
insert(:member, parent: group, actor: group_admin, role: :administrator)
|
|
|
|
|
|
|
|
%Actor{url: invitee_url, id: invitee_id} = _invitee = insert(:actor)
|
|
|
|
|
|
|
|
invite_data =
|
|
|
|
File.read!("test/fixtures/mobilizon-invite-activity.json")
|
|
|
|
|> Jason.decode!()
|
|
|
|
|> Map.put("actor", group_admin_url)
|
|
|
|
|> Map.put("object", group_url)
|
|
|
|
|> Map.put("target", invitee_url)
|
|
|
|
|
|
|
|
assert {:ok, activity, %Member{}} = Transmogrifier.handle_incoming(invite_data)
|
|
|
|
assert %Member{} = member = Actors.get_member_by_url(invite_data["id"])
|
|
|
|
assert member.actor.id == invitee_id
|
|
|
|
assert member.parent.id == group_id
|
|
|
|
assert member.role == :invited
|
|
|
|
assert member.invited_by_id == group_admin_id
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-12-14 16:41:55 +00:00
|
|
|
describe "prepare outgoing" do
|
|
|
|
test "it turns mentions into tags" do
|
|
|
|
actor = insert(:actor)
|
|
|
|
other_actor = insert(:actor)
|
|
|
|
|
2019-07-30 08:35:29 +00:00
|
|
|
{:ok, activity, _} =
|
2019-10-25 15:43:37 +00:00
|
|
|
API.Comments.create_comment(%{
|
|
|
|
actor_id: actor.id,
|
|
|
|
text: "hey, @#{other_actor.preferred_username}, how are ya? #2hu"
|
|
|
|
})
|
2018-12-14 16:41:55 +00:00
|
|
|
|
|
|
|
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
|
|
|
|
object = modified["object"]
|
|
|
|
|
|
|
|
expected_mention = %{
|
|
|
|
"href" => other_actor.url,
|
|
|
|
"name" => "@#{other_actor.preferred_username}",
|
|
|
|
"type" => "Mention"
|
|
|
|
}
|
|
|
|
|
|
|
|
expected_tag = %{
|
2020-01-28 18:18:33 +00:00
|
|
|
"href" => Endpoint.url() <> "/tags/2hu",
|
2018-12-14 16:41:55 +00:00
|
|
|
"type" => "Hashtag",
|
|
|
|
"name" => "#2hu"
|
|
|
|
}
|
|
|
|
|
|
|
|
assert Enum.member?(object["tag"], expected_tag)
|
|
|
|
assert Enum.member?(object["tag"], expected_mention)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it adds the json-ld context and the conversation property" do
|
|
|
|
actor = insert(:actor)
|
|
|
|
|
2019-10-25 15:43:37 +00:00
|
|
|
{:ok, activity, _} = API.Comments.create_comment(%{actor_id: actor.id, text: "hey"})
|
2019-07-30 08:35:29 +00:00
|
|
|
|
2018-12-14 16:41:55 +00:00
|
|
|
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
|
|
|
|
|
2019-01-03 10:34:31 +00:00
|
|
|
assert modified["@context"] == Utils.make_json_ld_header()["@context"]
|
2018-12-14 16:41:55 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test "it sets the 'attributedTo' property to the actor of the object if it doesn't have one" do
|
|
|
|
actor = insert(:actor)
|
|
|
|
|
2019-10-25 15:43:37 +00:00
|
|
|
{:ok, activity, _} = API.Comments.create_comment(%{actor_id: actor.id, text: "hey"})
|
2019-07-30 08:35:29 +00:00
|
|
|
|
2018-12-14 16:41:55 +00:00
|
|
|
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
|
|
|
|
|
|
|
|
assert modified["object"]["actor"] == modified["object"]["attributedTo"]
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it strips internal hashtag data" do
|
|
|
|
actor = insert(:actor)
|
|
|
|
|
2019-10-25 15:43:37 +00:00
|
|
|
{:ok, activity, _} = API.Comments.create_comment(%{actor_id: actor.id, text: "#2hu"})
|
2018-12-14 16:41:55 +00:00
|
|
|
|
|
|
|
expected_tag = %{
|
2020-01-28 18:18:33 +00:00
|
|
|
"href" => Endpoint.url() <> "/tags/2hu",
|
2018-12-14 16:41:55 +00:00
|
|
|
"type" => "Hashtag",
|
|
|
|
"name" => "#2hu"
|
|
|
|
}
|
|
|
|
|
|
|
|
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
|
|
|
|
|
|
|
|
assert modified["object"]["tag"] == [expected_tag]
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it strips internal fields" do
|
|
|
|
actor = insert(:actor)
|
|
|
|
|
2019-10-25 15:43:37 +00:00
|
|
|
{:ok, activity, _} = API.Comments.create_comment(%{actor_id: actor.id, text: "#2hu"})
|
2018-12-14 16:41:55 +00:00
|
|
|
|
|
|
|
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
|
|
|
|
|
|
|
|
# TODO : When and if custom emoji are implemented, this should be 2
|
|
|
|
assert length(modified["object"]["tag"]) == 1
|
|
|
|
|
|
|
|
assert is_nil(modified["object"]["emoji"])
|
|
|
|
assert is_nil(modified["object"]["likes"])
|
|
|
|
assert is_nil(modified["object"]["like_count"])
|
|
|
|
assert is_nil(modified["object"]["announcements"])
|
|
|
|
assert is_nil(modified["object"]["announcement_count"])
|
|
|
|
assert is_nil(modified["object"]["context_id"])
|
|
|
|
end
|
2019-12-03 10:29:51 +00:00
|
|
|
end
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-12-03 10:29:51 +00:00
|
|
|
describe "actor origin check" do
|
|
|
|
test "it rejects objects with a bogus origin" do
|
|
|
|
use_cassette "activity_pub/object_bogus_origin" do
|
|
|
|
{:error, _} = ActivityPub.fetch_object_from_url("https://info.pleroma.site/activity.json")
|
|
|
|
end
|
|
|
|
end
|
2018-12-14 16:41:55 +00:00
|
|
|
|
2019-12-03 10:29:51 +00:00
|
|
|
test "it rejects activities which reference objects with bogus origins" do
|
|
|
|
use_cassette "activity_pub/activity_object_bogus" do
|
|
|
|
data = %{
|
|
|
|
"@context" => "https://www.w3.org/ns/activitystreams",
|
|
|
|
"id" => "https://framapiaf.org/users/admin/activities/1234",
|
|
|
|
"actor" => "https://framapiaf.org/users/admin",
|
|
|
|
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
|
|
|
|
"object" => "https://info.pleroma.site/activity.json",
|
|
|
|
"type" => "Announce"
|
|
|
|
}
|
|
|
|
|
|
|
|
:error = Transmogrifier.handle_incoming(data)
|
|
|
|
end
|
|
|
|
end
|
2018-12-14 16:41:55 +00:00
|
|
|
end
|
|
|
|
end
|