logo

pleroma

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

accept_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.AcceptValidationTest 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, accept_data, _} = Builder.accept(followed, follow_activity)
  16. %{accept_data: accept_data, followed: followed}
  17. end
  18. test "it validates a basic 'accept'", %{accept_data: accept_data} do
  19. assert {:ok, _, _} = ObjectValidator.validate(accept_data, [])
  20. end
  21. test "it fails when the actor doesn't exist", %{accept_data: accept_data} do
  22. accept_data =
  23. accept_data
  24. |> Map.put("actor", "https://gensokyo.2hu/users/raymoo")
  25. assert {:error, _} = ObjectValidator.validate(accept_data, [])
  26. end
  27. test "it fails when the accepted activity doesn't exist", %{accept_data: accept_data} do
  28. accept_data =
  29. accept_data
  30. |> Map.put("object", "https://gensokyo.2hu/users/raymoo/follows/1")
  31. assert {:error, _} = ObjectValidator.validate(accept_data, [])
  32. end
  33. test "for an accepted follow, it only validates if the actor of the accept is the followed actor",
  34. %{accept_data: accept_data} do
  35. stranger = insert(:user)
  36. accept_data =
  37. accept_data
  38. |> Map.put("actor", stranger.ap_id)
  39. assert {:error, _} = ObjectValidator.validate(accept_data, [])
  40. end
  41. end