1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ActivityPub.ObjectValidators.UndoHandlingTest do
6 use Pleroma.DataCase, async: true
8 alias Pleroma.Web.ActivityPub.Builder
9 alias Pleroma.Web.ActivityPub.ObjectValidator
10 alias Pleroma.Web.CommonAPI
12 import Pleroma.Factory
17 {:ok, post_activity} = CommonAPI.post(user, %{status: "uguu"})
18 {:ok, like} = CommonAPI.favorite(user, post_activity.id)
19 {:ok, valid_like_undo, []} = Builder.undo(user, like)
21 %{user: user, like: like, valid_like_undo: valid_like_undo}
24 test "it validates a basic like undo", %{valid_like_undo: valid_like_undo} do
25 assert {:ok, _, _} = ObjectValidator.validate(valid_like_undo, [])
28 test "it does not validate if the actor of the undo is not the actor of the object", %{
29 valid_like_undo: valid_like_undo
31 other_user = insert(:user, ap_id: "https://gensokyo.2hu/users/raymoo")
35 |> Map.put("actor", other_user.ap_id)
37 {:error, cng} = ObjectValidator.validate(bad_actor, [])
39 assert {:actor, {"not the same as object actor", []}} in cng.errors
42 test "it does not validate if the object is missing", %{valid_like_undo: valid_like_undo} do
45 |> Map.put("object", "https://gensokyo.2hu/objects/1")
47 {:error, cng} = ObjectValidator.validate(missing_object, [])
49 assert {:object, {"can't find object", []}} in cng.errors
50 assert length(cng.errors) == 1