1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 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") |> Poison.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")
63 %Tesla.Env{status: 200, body: File.read!("test/fixtures/mastodon-note-object.json")}
66 _user = insert(:user, local: false, ap_id: data["actor"])
68 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
70 assert data["actor"] == "http://mastodon.example.org/users/admin"
71 assert data["type"] == "Announce"
74 "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity"
76 assert data["object"] ==
77 "http://mastodon.example.org/users/admin/statuses/99541947525187367"
79 assert(Activity.get_create_by_object_ap_id(data["object"]))
82 @tag capture_log: true
83 test "it works for incoming announces with an existing activity" do
85 {:ok, activity} = CommonAPI.post(user, %{status: "hey"})
88 File.read!("test/fixtures/mastodon-announce.json")
90 |> Map.put("object", activity.data["object"])
92 _user = insert(:user, local: false, ap_id: data["actor"])
94 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
96 assert data["actor"] == "http://mastodon.example.org/users/admin"
97 assert data["type"] == "Announce"
100 "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity"
102 assert data["object"] == activity.data["object"]
104 assert Activity.get_create_by_object_ap_id(data["object"]).id == activity.id
107 # Ignore inlined activities for now
109 test "it works for incoming announces with an inlined activity" do
111 File.read!("test/fixtures/mastodon-announce-private.json")
117 ap_id: data["actor"],
118 follower_address: data["actor"] <> "/followers"
121 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
123 assert data["actor"] == "http://mastodon.example.org/users/admin"
124 assert data["type"] == "Announce"
127 "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity"
129 object = Object.normalize(data["object"])
131 assert object.data["id"] == "http://mastodon.example.org/@admin/99541947525187368"
132 assert object.data["content"] == "this is a private toot"
135 @tag capture_log: true
136 test "it rejects incoming announces with an inlined activity from another origin" do
138 %{method: :get} -> %Tesla.Env{status: 404, body: ""}
142 File.read!("test/fixtures/bogus-mastodon-announce.json")
145 _user = insert(:user, local: false, ap_id: data["actor"])
147 assert {:error, e} = Transmogrifier.handle_incoming(data)
150 test "it does not clobber the addressing on announce activities" do
152 {:ok, activity} = CommonAPI.post(user, %{status: "hey"})
155 File.read!("test/fixtures/mastodon-announce.json")
157 |> Map.put("object", Object.normalize(activity).data["id"])
158 |> Map.put("to", ["http://mastodon.example.org/users/admin/followers"])
164 ap_id: data["actor"],
165 follower_address: "http://mastodon.example.org/users/admin/followers"
168 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
170 assert data["to"] == ["http://mastodon.example.org/users/admin/followers"]