logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

accept_handling_test.exs (2808B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Web.ActivityPub.Transmogrifier.AcceptHandlingTest do
  5. use Pleroma.DataCase, async: true
  6. alias Pleroma.User
  7. alias Pleroma.Web.ActivityPub.Transmogrifier
  8. alias Pleroma.Web.CommonAPI
  9. import Pleroma.Factory
  10. test "it works for incoming accepts which were pre-accepted" do
  11. follower = insert(:user)
  12. followed = insert(:user)
  13. {:ok, follower, followed} = User.follow(follower, followed)
  14. assert User.following?(follower, followed) == true
  15. {:ok, _, _, follow_activity} = CommonAPI.follow(follower, followed)
  16. accept_data =
  17. File.read!("test/fixtures/mastodon-accept-activity.json")
  18. |> Jason.decode!()
  19. |> Map.put("actor", followed.ap_id)
  20. object =
  21. accept_data["object"]
  22. |> Map.put("actor", follower.ap_id)
  23. |> Map.put("id", follow_activity.data["id"])
  24. accept_data = Map.put(accept_data, "object", object)
  25. {:ok, activity} = Transmogrifier.handle_incoming(accept_data)
  26. refute activity.local
  27. assert activity.data["object"] == follow_activity.data["id"]
  28. assert activity.data["id"] == accept_data["id"]
  29. follower = User.get_cached_by_id(follower.id)
  30. assert User.following?(follower, followed) == true
  31. end
  32. test "it works for incoming accepts which are referenced by IRI only" do
  33. follower = insert(:user)
  34. followed = insert(:user, is_locked: true)
  35. {:ok, _, _, follow_activity} = CommonAPI.follow(follower, followed)
  36. accept_data =
  37. File.read!("test/fixtures/mastodon-accept-activity.json")
  38. |> Jason.decode!()
  39. |> Map.put("actor", followed.ap_id)
  40. |> Map.put("object", follow_activity.data["id"])
  41. {:ok, activity} = Transmogrifier.handle_incoming(accept_data)
  42. assert activity.data["object"] == follow_activity.data["id"]
  43. follower = User.get_cached_by_id(follower.id)
  44. assert User.following?(follower, followed) == true
  45. follower = User.get_by_id(follower.id)
  46. assert follower.following_count == 1
  47. followed = User.get_by_id(followed.id)
  48. assert followed.follower_count == 1
  49. end
  50. test "it fails for incoming accepts which cannot be correlated" do
  51. follower = insert(:user)
  52. followed = insert(:user, is_locked: true)
  53. accept_data =
  54. File.read!("test/fixtures/mastodon-accept-activity.json")
  55. |> Jason.decode!()
  56. |> Map.put("actor", followed.ap_id)
  57. accept_data =
  58. Map.put(accept_data, "object", Map.put(accept_data["object"], "actor", follower.ap_id))
  59. {:error, _} = Transmogrifier.handle_incoming(accept_data)
  60. follower = User.get_cached_by_id(follower.id)
  61. refute User.following?(follower, followed) == true
  62. end
  63. end