Merge branch 'develop' into refactor/discoverable_user_field
[akkoma] / test / pleroma / web / activity_pub / object_validators / undo_handling_test.exs
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
5 defmodule Pleroma.Web.ActivityPub.ObjectValidators.UndoHandlingTest do
6 use Pleroma.DataCase
7
8 alias Pleroma.Web.ActivityPub.Builder
9 alias Pleroma.Web.ActivityPub.ObjectValidator
10 alias Pleroma.Web.CommonAPI
11
12 import Pleroma.Factory
13
14 describe "Undos" do
15 setup do
16 user = insert(:user)
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)
20
21 %{user: user, like: like, valid_like_undo: valid_like_undo}
22 end
23
24 test "it validates a basic like undo", %{valid_like_undo: valid_like_undo} do
25 assert {:ok, _, _} = ObjectValidator.validate(valid_like_undo, [])
26 end
27
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
30 } do
31 other_user = insert(:user, ap_id: "https://gensokyo.2hu/users/raymoo")
32
33 bad_actor =
34 valid_like_undo
35 |> Map.put("actor", other_user.ap_id)
36
37 {:error, cng} = ObjectValidator.validate(bad_actor, [])
38
39 assert {:actor, {"not the same as object actor", []}} in cng.errors
40 end
41
42 test "it does not validate if the object is missing", %{valid_like_undo: valid_like_undo} do
43 missing_object =
44 valid_like_undo
45 |> Map.put("object", "https://gensokyo.2hu/objects/1")
46
47 {:error, cng} = ObjectValidator.validate(missing_object, [])
48
49 assert {:object, {"can't find object", []}} in cng.errors
50 assert length(cng.errors) == 1
51 end
52 end
53 end