logo

pleroma

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

undo_handling_test.exs (1754B)


  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.ObjectValidators.UndoHandlingTest do
  5. use Pleroma.DataCase, async: true
  6. alias Pleroma.Web.ActivityPub.Builder
  7. alias Pleroma.Web.ActivityPub.ObjectValidator
  8. alias Pleroma.Web.CommonAPI
  9. import Pleroma.Factory
  10. describe "Undos" do
  11. setup do
  12. user = insert(:user)
  13. {:ok, post_activity} = CommonAPI.post(user, %{status: "uguu"})
  14. {:ok, like} = CommonAPI.favorite(user, post_activity.id)
  15. {:ok, valid_like_undo, []} = Builder.undo(user, like)
  16. %{user: user, like: like, valid_like_undo: valid_like_undo}
  17. end
  18. test "it validates a basic like undo", %{valid_like_undo: valid_like_undo} do
  19. assert {:ok, _, _} = ObjectValidator.validate(valid_like_undo, [])
  20. end
  21. test "it does not validate if the actor of the undo is not the actor of the object", %{
  22. valid_like_undo: valid_like_undo
  23. } do
  24. other_user = insert(:user, ap_id: "https://gensokyo.2hu/users/raymoo")
  25. bad_actor =
  26. valid_like_undo
  27. |> Map.put("actor", other_user.ap_id)
  28. {:error, cng} = ObjectValidator.validate(bad_actor, [])
  29. assert {:actor, {"not the same as object actor", []}} in cng.errors
  30. end
  31. test "it does not validate if the object is missing", %{valid_like_undo: valid_like_undo} do
  32. missing_object =
  33. valid_like_undo
  34. |> Map.put("object", "https://gensokyo.2hu/objects/1")
  35. {:error, cng} = ObjectValidator.validate(missing_object, [])
  36. assert {:object, {"can't find object", []}} in cng.errors
  37. assert length(cng.errors) == 1
  38. end
  39. end
  40. end