diff options
| author | lain <lain@soykaf.club> | 2020-05-05 14:17:47 +0200 | 
|---|---|---|
| committer | lain <lain@soykaf.club> | 2020-05-05 14:17:47 +0200 | 
| commit | f1da8882f971f932b65f655b6457759387dafe51 (patch) | |
| tree | 25a5cd5a2fa27bafc0d75bda972ca951ee8c56ab /test/web/activity_pub/object_validator_test.exs | |
| parent | 8b2457bdbf8791923701b0b015f6ddf2e7c89bf7 (diff) | |
| download | pleroma-f1da8882f971f932b65f655b6457759387dafe51.tar.gz pleroma-f1da8882f971f932b65f655b6457759387dafe51.zip | |
UndoValidator: Add UndoValidator.
Diffstat (limited to 'test/web/activity_pub/object_validator_test.exs')
| -rw-r--r-- | test/web/activity_pub/object_validator_test.exs | 41 | 
1 files changed, 41 insertions, 0 deletions
| diff --git a/test/web/activity_pub/object_validator_test.exs b/test/web/activity_pub/object_validator_test.exs index 93989e28a..8626e127e 100644 --- a/test/web/activity_pub/object_validator_test.exs +++ b/test/web/activity_pub/object_validator_test.exs @@ -1,6 +1,7 @@  defmodule Pleroma.Web.ActivityPub.ObjectValidatorTest do    use Pleroma.DataCase +  alias Pleroma.Web.ActivityPub.Builder    alias Pleroma.Web.ActivityPub.ObjectValidator    alias Pleroma.Web.ActivityPub.ObjectValidators.LikeValidator    alias Pleroma.Web.ActivityPub.Utils @@ -8,6 +9,46 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidatorTest do    import Pleroma.Factory +  describe "Undos" do +    setup do +      user = insert(:user) +      {:ok, post_activity} = CommonAPI.post(user, %{"status" => "uguu"}) +      {:ok, like} = CommonAPI.favorite(user, post_activity.id) +      {:ok, valid_like_undo, []} = Builder.undo(user, like) + +      %{user: user, like: like, valid_like_undo: valid_like_undo} +    end + +    test "it validates a basic like undo", %{valid_like_undo: valid_like_undo} do +      assert {:ok, _, _} = ObjectValidator.validate(valid_like_undo, []) +    end + +    test "it does not validate if the actor of the undo is not the actor of the object", %{ +      valid_like_undo: valid_like_undo +    } do +      other_user = insert(:user, ap_id: "https://gensokyo.2hu/users/raymoo") + +      bad_actor = +        valid_like_undo +        |> Map.put("actor", other_user.ap_id) + +      {:error, cng} = ObjectValidator.validate(bad_actor, []) + +      assert {:actor, {"not the same as object actor", []}} in cng.errors +    end + +    test "it does not validate if the object is missing", %{valid_like_undo: valid_like_undo} do +      missing_object = +        valid_like_undo +        |> Map.put("object", "https://gensokyo.2hu/objects/1") + +      {:error, cng} = ObjectValidator.validate(missing_object, []) + +      assert {:object, {"can't find object", []}} in cng.errors +      assert length(cng.errors) == 1 +    end +  end +    describe "likes" do      setup do        user = insert(:user) | 
