logo

pleroma

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

reject_validation_test.exs (1774B)


  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.ObjectValidators.RejectValidationTest do
  5. use Pleroma.DataCase
  6. alias Pleroma.Web.ActivityPub.Builder
  7. alias Pleroma.Web.ActivityPub.ObjectValidator
  8. alias Pleroma.Web.ActivityPub.Pipeline
  9. import Pleroma.Factory
  10. setup do
  11. follower = insert(:user)
  12. followed = insert(:user, local: false)
  13. {:ok, follow_data, _} = Builder.follow(follower, followed)
  14. {:ok, follow_activity, _} = Pipeline.common_pipeline(follow_data, local: true)
  15. {:ok, reject_data, _} = Builder.reject(followed, follow_activity)
  16. %{reject_data: reject_data, followed: followed}
  17. end
  18. test "it validates a basic 'reject'", %{reject_data: reject_data} do
  19. assert {:ok, _, _} = ObjectValidator.validate(reject_data, [])
  20. end
  21. test "it fails when the actor doesn't exist", %{reject_data: reject_data} do
  22. reject_data =
  23. reject_data
  24. |> Map.put("actor", "https://gensokyo.2hu/users/raymoo")
  25. assert {:error, _} = ObjectValidator.validate(reject_data, [])
  26. end
  27. test "it fails when the rejected activity doesn't exist", %{reject_data: reject_data} do
  28. reject_data =
  29. reject_data
  30. |> Map.put("object", "https://gensokyo.2hu/users/raymoo/follows/1")
  31. assert {:error, _} = ObjectValidator.validate(reject_data, [])
  32. end
  33. test "for an rejected follow, it only validates if the actor of the reject is the followed actor",
  34. %{reject_data: reject_data} do
  35. stranger = insert(:user)
  36. reject_data =
  37. reject_data
  38. |> Map.put("actor", stranger.ap_id)
  39. assert {:error, _} = ObjectValidator.validate(reject_data, [])
  40. end
  41. end