1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ActivityPub.Transmogrifier.AnnounceHandlingTest do
10 alias Pleroma.Web.ActivityPub.Transmogrifier
11 alias Pleroma.Web.CommonAPI
13 import Pleroma.Factory
15 test "it works for incoming honk announces" do
16 user = insert(:user, ap_id: "https://honktest/u/test", local: false)
17 other_user = insert(:user)
18 {:ok, post} = CommonAPI.post(other_user, %{status: "bonkeronk"})
21 "@context" => "https://www.w3.org/ns/activitystreams",
22 "actor" => "https://honktest/u/test",
23 "id" => "https://honktest/u/test/bonk/1793M7B9MQ48847vdx",
24 "object" => post.data["object"],
25 "published" => "2019-06-25T19:33:58Z",
26 "to" => "https://www.w3.org/ns/activitystreams#Public",
30 {:ok, %Activity{local: false}} = Transmogrifier.handle_incoming(announce)
32 object = Object.get_by_ap_id(post.data["object"])
34 assert length(object.data["announcements"]) == 1
35 assert user.ap_id in object.data["announcements"]
38 test "it works for incoming announces with actor being inlined (kroeg)" do
39 data = File.read!("test/fixtures/kroeg-announce-with-inline-actor.json") |> Jason.decode!()
41 _user = insert(:user, local: false, ap_id: data["actor"]["id"])
42 other_user = insert(:user)
44 {:ok, post} = CommonAPI.post(other_user, %{status: "kroegeroeg"})
48 |> put_in(["object", "id"], post.data["object"])
50 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
52 assert data["actor"] == "https://puckipedia.com/"
55 test "it works for incoming announces, fetching the announced object" do
57 File.read!("test/fixtures/mastodon-announce.json")
59 |> Map.put("object", "http://mastodon.example.org/users/admin/statuses/99541947525187367")
65 body: File.read!("test/fixtures/mastodon-note-object.json"),
66 headers: HttpRequestMock.activitypub_object_headers()
70 _user = insert(:user, local: false, ap_id: data["actor"])
72 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
74 assert data["actor"] == "http://mastodon.example.org/users/admin"
75 assert data["type"] == "Announce"
78 "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity"
80 assert data["object"] ==
81 "http://mastodon.example.org/users/admin/statuses/99541947525187367"
83 assert(Activity.get_create_by_object_ap_id(data["object"]))
86 @tag capture_log: true
87 test "it works for incoming announces with an existing activity" do
89 {:ok, activity} = CommonAPI.post(user, %{status: "hey"})
92 File.read!("test/fixtures/mastodon-announce.json")
94 |> Map.put("object", activity.data["object"])
96 _user = insert(:user, local: false, ap_id: data["actor"])
98 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
100 assert data["actor"] == "http://mastodon.example.org/users/admin"
101 assert data["type"] == "Announce"
104 "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity"
106 assert data["object"] == activity.data["object"]
108 assert Activity.get_create_by_object_ap_id(data["object"]).id == activity.id
111 # Ignore inlined activities for now
113 test "it works for incoming announces with an inlined activity" do
115 File.read!("test/fixtures/mastodon-announce-private.json")
121 ap_id: data["actor"],
122 follower_address: data["actor"] <> "/followers"
125 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
127 assert data["actor"] == "http://mastodon.example.org/users/admin"
128 assert data["type"] == "Announce"
131 "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity"
133 object = Object.normalize(data["object"], fetch: false)
135 assert object.data["id"] == "http://mastodon.example.org/@admin/99541947525187368"
136 assert object.data["content"] == "this is a private toot"
139 @tag capture_log: true
140 test "it rejects incoming announces with an inlined activity from another origin" do
142 %{method: :get} -> %Tesla.Env{status: 404, body: ""}
146 File.read!("test/fixtures/bogus-mastodon-announce.json")
149 _user = insert(:user, local: false, ap_id: data["actor"])
151 assert {:error, _e} = Transmogrifier.handle_incoming(data)