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.AcceptHandlingTest do
6 use Pleroma.DataCase, async: true
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, followed} = 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 are referenced by IRI only" do
48 follower = insert(:user)
49 followed = insert(:user, is_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)
57 |> Map.put("object", follow_activity.data["id"])
59 {:ok, activity} = Transmogrifier.handle_incoming(accept_data)
60 assert activity.data["object"] == follow_activity.data["id"]
62 follower = User.get_cached_by_id(follower.id)
64 assert User.following?(follower, followed) == true
66 follower = User.get_by_id(follower.id)
67 assert follower.following_count == 1
69 followed = User.get_by_id(followed.id)
70 assert followed.follower_count == 1
73 test "it fails for incoming accepts which cannot be correlated" do
74 follower = insert(:user)
75 followed = insert(:user, is_locked: true)
78 File.read!("test/fixtures/mastodon-accept-activity.json")
80 |> Map.put("actor", followed.ap_id)
83 Map.put(accept_data, "object", Map.put(accept_data["object"], "actor", follower.ap_id))
85 {:error, _} = Transmogrifier.handle_incoming(accept_data)
87 follower = User.get_cached_by_id(follower.id)
89 refute User.following?(follower, followed) == true