logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

reject_handling_test.exs (2021B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Web.ActivityPub.Transmogrifier.RejectHandlingTest do
  5. use Pleroma.DataCase
  6. alias Pleroma.Activity
  7. alias Pleroma.User
  8. alias Pleroma.Web.ActivityPub.Transmogrifier
  9. alias Pleroma.Web.CommonAPI
  10. import Pleroma.Factory
  11. test "it fails for incoming rejects which cannot be correlated" do
  12. follower = insert(:user)
  13. followed = insert(:user, locked: true)
  14. accept_data =
  15. File.read!("test/fixtures/mastodon-reject-activity.json")
  16. |> Poison.decode!()
  17. |> Map.put("actor", followed.ap_id)
  18. accept_data =
  19. Map.put(accept_data, "object", Map.put(accept_data["object"], "actor", follower.ap_id))
  20. {:error, _} = Transmogrifier.handle_incoming(accept_data)
  21. follower = User.get_cached_by_id(follower.id)
  22. refute User.following?(follower, followed) == true
  23. end
  24. test "it works for incoming rejects which are referenced by IRI only" do
  25. follower = insert(:user)
  26. followed = insert(:user, locked: true)
  27. {:ok, follower} = User.follow(follower, followed)
  28. {:ok, _, _, follow_activity} = CommonAPI.follow(follower, followed)
  29. assert User.following?(follower, followed) == true
  30. reject_data =
  31. File.read!("test/fixtures/mastodon-reject-activity.json")
  32. |> Poison.decode!()
  33. |> Map.put("actor", followed.ap_id)
  34. |> Map.put("object", follow_activity.data["id"])
  35. {:ok, %Activity{data: _}} = Transmogrifier.handle_incoming(reject_data)
  36. follower = User.get_cached_by_id(follower.id)
  37. assert User.following?(follower, followed) == false
  38. end
  39. test "it rejects activities without a valid ID" do
  40. user = insert(:user)
  41. data =
  42. File.read!("test/fixtures/mastodon-follow-activity.json")
  43. |> Poison.decode!()
  44. |> Map.put("object", user.ap_id)
  45. |> Map.put("id", "")
  46. :error = Transmogrifier.handle_incoming(data)
  47. end
  48. end