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.AcceptHandlingTest do
9 alias Pleroma.Web.ActivityPub.Transmogrifier
10 alias Pleroma.Web.CommonAPI
12 import Pleroma.Factory
14 test "it works for incoming accepts which were pre-accepted" do
15 follower = insert(:user)
16 followed = insert(:user)
18 {:ok, follower} = User.follow(follower, followed)
19 assert User.following?(follower, followed) == true
21 {:ok, _, _, follow_activity} = CommonAPI.follow(follower, followed)
24 File.read!("test/fixtures/mastodon-accept-activity.json")
26 |> Map.put("actor", followed.ap_id)
30 |> Map.put("actor", follower.ap_id)
31 |> Map.put("id", follow_activity.data["id"])
33 accept_data = Map.put(accept_data, "object", object)
35 {:ok, activity} = Transmogrifier.handle_incoming(accept_data)
38 assert activity.data["object"] == follow_activity.data["id"]
40 assert activity.data["id"] == accept_data["id"]
42 follower = User.get_cached_by_id(follower.id)
44 assert User.following?(follower, followed) == true
47 test "it works for incoming accepts which were orphaned" do
48 follower = insert(:user)
49 followed = insert(:user, locked: true)
51 {:ok, _, _, follow_activity} = CommonAPI.follow(follower, followed)
54 File.read!("test/fixtures/mastodon-accept-activity.json")
56 |> Map.put("actor", followed.ap_id)
59 Map.put(accept_data, "object", Map.put(accept_data["object"], "actor", follower.ap_id))
61 {:ok, activity} = Transmogrifier.handle_incoming(accept_data)
62 assert activity.data["object"] == follow_activity.data["id"]
64 follower = User.get_cached_by_id(follower.id)
66 assert User.following?(follower, followed) == true
69 test "it works for incoming accepts which are referenced by IRI only" do
70 follower = insert(:user)
71 followed = insert(:user, locked: true)
73 {:ok, _, _, follow_activity} = CommonAPI.follow(follower, followed)
76 File.read!("test/fixtures/mastodon-accept-activity.json")
78 |> Map.put("actor", followed.ap_id)
79 |> Map.put("object", follow_activity.data["id"])
81 {:ok, activity} = Transmogrifier.handle_incoming(accept_data)
82 assert activity.data["object"] == follow_activity.data["id"]
84 follower = User.get_cached_by_id(follower.id)
86 assert User.following?(follower, followed) == true
88 follower = User.get_by_id(follower.id)
89 assert follower.following_count == 1
91 followed = User.get_by_id(followed.id)
92 assert followed.follower_count == 1
95 test "it fails for incoming accepts which cannot be correlated" do
96 follower = insert(:user)
97 followed = insert(:user, locked: true)
100 File.read!("test/fixtures/mastodon-accept-activity.json")
102 |> Map.put("actor", followed.ap_id)
105 Map.put(accept_data, "object", Map.put(accept_data["object"], "actor", follower.ap_id))
107 :error = Transmogrifier.handle_incoming(accept_data)
109 follower = User.get_cached_by_id(follower.id)
111 refute User.following?(follower, followed) == true