2020-05-18 06:48:37 -06:00
|
|
|
# Pleroma: A lightweight social networking server
|
2022-02-25 23:11:42 -07:00
|
|
|
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
2020-05-18 06:48:37 -06:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.ActivityPub.Transmogrifier.AnnounceHandlingTest do
|
|
|
|
use Pleroma.DataCase
|
|
|
|
|
|
|
|
alias Pleroma.Activity
|
|
|
|
alias Pleroma.Object
|
|
|
|
alias Pleroma.Web.ActivityPub.Transmogrifier
|
2020-05-21 05:31:52 -06:00
|
|
|
alias Pleroma.Web.CommonAPI
|
2020-05-18 06:48:37 -06:00
|
|
|
|
|
|
|
import Pleroma.Factory
|
|
|
|
|
|
|
|
test "it works for incoming honk announces" do
|
2020-05-20 07:44:37 -06:00
|
|
|
user = insert(:user, ap_id: "https://honktest/u/test", local: false)
|
2020-05-18 06:48:37 -06:00
|
|
|
other_user = insert(:user)
|
|
|
|
{:ok, post} = CommonAPI.post(other_user, %{status: "bonkeronk"})
|
|
|
|
|
|
|
|
announce = %{
|
|
|
|
"@context" => "https://www.w3.org/ns/activitystreams",
|
|
|
|
"actor" => "https://honktest/u/test",
|
|
|
|
"id" => "https://honktest/u/test/bonk/1793M7B9MQ48847vdx",
|
|
|
|
"object" => post.data["object"],
|
|
|
|
"published" => "2019-06-25T19:33:58Z",
|
|
|
|
"to" => "https://www.w3.org/ns/activitystreams#Public",
|
|
|
|
"type" => "Announce"
|
|
|
|
}
|
|
|
|
|
|
|
|
{:ok, %Activity{local: false}} = Transmogrifier.handle_incoming(announce)
|
2020-05-20 07:44:37 -06:00
|
|
|
|
|
|
|
object = Object.get_by_ap_id(post.data["object"])
|
|
|
|
|
|
|
|
assert length(object.data["announcements"]) == 1
|
|
|
|
assert user.ap_id in object.data["announcements"]
|
2020-05-18 06:48:37 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
test "it works for incoming announces with actor being inlined (kroeg)" do
|
2020-11-23 12:28:55 -07:00
|
|
|
data = File.read!("test/fixtures/kroeg-announce-with-inline-actor.json") |> Jason.decode!()
|
2020-05-18 06:48:37 -06:00
|
|
|
|
|
|
|
_user = insert(:user, local: false, ap_id: data["actor"]["id"])
|
|
|
|
other_user = insert(:user)
|
|
|
|
|
|
|
|
{:ok, post} = CommonAPI.post(other_user, %{status: "kroegeroeg"})
|
|
|
|
|
|
|
|
data =
|
|
|
|
data
|
|
|
|
|> put_in(["object", "id"], post.data["object"])
|
|
|
|
|
|
|
|
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
|
|
|
|
|
|
|
assert data["actor"] == "https://puckipedia.com/"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it works for incoming announces, fetching the announced object" do
|
2020-05-20 07:44:37 -06:00
|
|
|
data =
|
|
|
|
File.read!("test/fixtures/mastodon-announce.json")
|
2020-11-23 12:28:55 -07:00
|
|
|
|> Jason.decode!()
|
2020-05-20 07:44:37 -06:00
|
|
|
|> Map.put("object", "http://mastodon.example.org/users/admin/statuses/99541947525187367")
|
|
|
|
|
|
|
|
Tesla.Mock.mock(fn
|
|
|
|
%{method: :get} ->
|
2020-10-28 09:08:23 -06:00
|
|
|
%Tesla.Env{
|
|
|
|
status: 200,
|
|
|
|
body: File.read!("test/fixtures/mastodon-note-object.json"),
|
|
|
|
headers: HttpRequestMock.activitypub_object_headers()
|
|
|
|
}
|
2020-05-20 07:44:37 -06:00
|
|
|
end)
|
2020-05-18 06:48:37 -06:00
|
|
|
|
|
|
|
_user = insert(:user, local: false, ap_id: data["actor"])
|
|
|
|
|
|
|
|
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
|
|
|
|
|
|
|
assert data["actor"] == "http://mastodon.example.org/users/admin"
|
|
|
|
assert data["type"] == "Announce"
|
|
|
|
|
|
|
|
assert data["id"] ==
|
|
|
|
"http://mastodon.example.org/users/admin/statuses/99542391527669785/activity"
|
|
|
|
|
|
|
|
assert data["object"] ==
|
|
|
|
"http://mastodon.example.org/users/admin/statuses/99541947525187367"
|
|
|
|
|
|
|
|
assert(Activity.get_create_by_object_ap_id(data["object"]))
|
|
|
|
end
|
|
|
|
|
|
|
|
@tag capture_log: true
|
|
|
|
test "it works for incoming announces with an existing activity" do
|
|
|
|
user = insert(:user)
|
|
|
|
{:ok, activity} = CommonAPI.post(user, %{status: "hey"})
|
|
|
|
|
|
|
|
data =
|
|
|
|
File.read!("test/fixtures/mastodon-announce.json")
|
2020-11-23 12:28:55 -07:00
|
|
|
|> Jason.decode!()
|
2020-05-18 06:48:37 -06:00
|
|
|
|> Map.put("object", activity.data["object"])
|
|
|
|
|
|
|
|
_user = insert(:user, local: false, ap_id: data["actor"])
|
|
|
|
|
|
|
|
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
|
|
|
|
|
|
|
assert data["actor"] == "http://mastodon.example.org/users/admin"
|
|
|
|
assert data["type"] == "Announce"
|
|
|
|
|
|
|
|
assert data["id"] ==
|
|
|
|
"http://mastodon.example.org/users/admin/statuses/99542391527669785/activity"
|
|
|
|
|
|
|
|
assert data["object"] == activity.data["object"]
|
|
|
|
|
|
|
|
assert Activity.get_create_by_object_ap_id(data["object"]).id == activity.id
|
|
|
|
end
|
|
|
|
|
2020-05-20 07:44:37 -06:00
|
|
|
# Ignore inlined activities for now
|
|
|
|
@tag skip: true
|
2020-05-18 06:48:37 -06:00
|
|
|
test "it works for incoming announces with an inlined activity" do
|
|
|
|
data =
|
|
|
|
File.read!("test/fixtures/mastodon-announce-private.json")
|
2020-11-23 12:28:55 -07:00
|
|
|
|> Jason.decode!()
|
2020-05-18 06:48:37 -06:00
|
|
|
|
|
|
|
_user =
|
|
|
|
insert(:user,
|
|
|
|
local: false,
|
|
|
|
ap_id: data["actor"],
|
|
|
|
follower_address: data["actor"] <> "/followers"
|
|
|
|
)
|
|
|
|
|
|
|
|
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
|
|
|
|
|
|
|
assert data["actor"] == "http://mastodon.example.org/users/admin"
|
|
|
|
assert data["type"] == "Announce"
|
|
|
|
|
|
|
|
assert data["id"] ==
|
|
|
|
"http://mastodon.example.org/users/admin/statuses/99542391527669785/activity"
|
|
|
|
|
2021-01-04 05:38:31 -07:00
|
|
|
object = Object.normalize(data["object"], fetch: false)
|
2020-05-18 06:48:37 -06:00
|
|
|
|
|
|
|
assert object.data["id"] == "http://mastodon.example.org/@admin/99541947525187368"
|
|
|
|
assert object.data["content"] == "this is a private toot"
|
|
|
|
end
|
|
|
|
|
|
|
|
@tag capture_log: true
|
|
|
|
test "it rejects incoming announces with an inlined activity from another origin" do
|
|
|
|
Tesla.Mock.mock(fn
|
|
|
|
%{method: :get} -> %Tesla.Env{status: 404, body: ""}
|
|
|
|
end)
|
|
|
|
|
|
|
|
data =
|
|
|
|
File.read!("test/fixtures/bogus-mastodon-announce.json")
|
2020-11-23 12:28:55 -07:00
|
|
|
|> Jason.decode!()
|
2020-05-18 06:48:37 -06:00
|
|
|
|
|
|
|
_user = insert(:user, local: false, ap_id: data["actor"])
|
|
|
|
|
2020-10-15 06:54:59 -06:00
|
|
|
assert {:error, _e} = Transmogrifier.handle_incoming(data)
|
2020-05-18 06:48:37 -06:00
|
|
|
end
|
|
|
|
end
|