diff options
Diffstat (limited to 'test/pleroma/web/activity_pub/object_validators')
-rw-r--r-- | test/pleroma/web/activity_pub/object_validators/announce_validation_test.exs | 22 | ||||
-rw-r--r-- | test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs (renamed from test/pleroma/web/activity_pub/object_validators/article_note_validator_test.exs) | 6 | ||||
-rw-r--r-- | test/pleroma/web/activity_pub/object_validators/attachment_validator_test.exs | 33 | ||||
-rw-r--r-- | test/pleroma/web/activity_pub/object_validators/like_validation_test.exs | 35 |
4 files changed, 67 insertions, 29 deletions
diff --git a/test/pleroma/web/activity_pub/object_validators/announce_validation_test.exs b/test/pleroma/web/activity_pub/object_validators/announce_validation_test.exs index 939922127..20964e855 100644 --- a/test/pleroma/web/activity_pub/object_validators/announce_validation_test.exs +++ b/test/pleroma/web/activity_pub/object_validators/announce_validation_test.exs @@ -33,6 +33,18 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.AnnounceValidationTest do assert {:ok, _object, _meta} = ObjectValidator.validate(valid_announce, []) end + test "keeps announced object context", %{valid_announce: valid_announce} do + assert %Object{data: %{"context" => object_context}} = + Object.get_cached_by_ap_id(valid_announce["object"]) + + {:ok, %{"context" => context}, _} = + valid_announce + |> Map.put("context", "https://example.org/invalid_context_id") + |> ObjectValidator.validate([]) + + assert context == object_context + end + test "returns an error if the object can't be found", %{valid_announce: valid_announce} do without_object = valid_announce @@ -51,16 +63,6 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.AnnounceValidationTest do assert {:object, {"can't find object", []}} in cng.errors end - test "returns an error if we don't have the actor", %{valid_announce: valid_announce} do - nonexisting_actor = - valid_announce - |> Map.put("actor", "https://gensokyo.2hu/users/raymoo") - - {:error, cng} = ObjectValidator.validate(nonexisting_actor, []) - - assert {:actor, {"can't find user", []}} in cng.errors - end - test "returns an error if the actor already announced the object", %{ valid_announce: valid_announce, announcer: announcer, diff --git a/test/pleroma/web/activity_pub/object_validators/article_note_validator_test.exs b/test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs index e408c85c3..720c17d8d 100644 --- a/test/pleroma/web/activity_pub/object_validators/article_note_validator_test.exs +++ b/test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs @@ -2,10 +2,10 @@ # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/> # SPDX-License-Identifier: AGPL-3.0-only -defmodule Pleroma.Web.ActivityPub.ObjectValidators.ArticleNoteValidatorTest do +defmodule Pleroma.Web.ActivityPub.ObjectValidators.ArticleNotePageValidatorTest do use Pleroma.DataCase, async: true - alias Pleroma.Web.ActivityPub.ObjectValidators.ArticleNoteValidator + alias Pleroma.Web.ActivityPub.ObjectValidators.ArticleNotePageValidator alias Pleroma.Web.ActivityPub.Utils import Pleroma.Factory @@ -29,7 +29,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ArticleNoteValidatorTest do end test "a basic note validates", %{note: note} do - %{valid?: true} = ArticleNoteValidator.cast_and_validate(note) + %{valid?: true} = ArticleNotePageValidator.cast_and_validate(note) end end end diff --git a/test/pleroma/web/activity_pub/object_validators/attachment_validator_test.exs b/test/pleroma/web/activity_pub/object_validators/attachment_validator_test.exs index b775515e0..0e49fda99 100644 --- a/test/pleroma/web/activity_pub/object_validators/attachment_validator_test.exs +++ b/test/pleroma/web/activity_pub/object_validators/attachment_validator_test.exs @@ -72,5 +72,38 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.AttachmentValidatorTest do assert attachment.mediaType == "image/jpeg" end + + test "it handles image dimensions" do + attachment = %{ + "url" => [ + %{ + "type" => "Link", + "mediaType" => "image/jpeg", + "href" => "https://example.com/images/1.jpg", + "width" => 200, + "height" => 100 + } + ], + "type" => "Document", + "name" => nil, + "mediaType" => "image/jpeg" + } + + {:ok, attachment} = + AttachmentValidator.cast_and_validate(attachment) + |> Ecto.Changeset.apply_action(:insert) + + assert [ + %{ + href: "https://example.com/images/1.jpg", + type: "Link", + mediaType: "image/jpeg", + width: 200, + height: 100 + } + ] = attachment.url + + assert attachment.mediaType == "image/jpeg" + end end end diff --git a/test/pleroma/web/activity_pub/object_validators/like_validation_test.exs b/test/pleroma/web/activity_pub/object_validators/like_validation_test.exs index 55f67232e..e9ad817f1 100644 --- a/test/pleroma/web/activity_pub/object_validators/like_validation_test.exs +++ b/test/pleroma/web/activity_pub/object_validators/like_validation_test.exs @@ -40,17 +40,30 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.LikeValidationTest do assert LikeValidator.cast_and_validate(valid_like).valid? end - test "sets the 'to' field to the object actor if no recipients are given", %{ + test "Add object actor from 'to' field if it doesn't owns the like", %{valid_like: valid_like} do + user = insert(:user) + + object_actor = valid_like["actor"] + + valid_like = + valid_like + |> Map.put("actor", user.ap_id) + |> Map.put("to", []) + + {:ok, object, _meta} = ObjectValidator.validate(valid_like, []) + assert object_actor in object["to"] + end + + test "Removes object actor from 'to' field if it owns the like", %{ valid_like: valid_like, user: user } do - without_recipients = + valid_like = valid_like - |> Map.delete("to") + |> Map.put("to", [user.ap_id]) - {:ok, object, _meta} = ObjectValidator.validate(without_recipients, []) - - assert object["to"] == [user.ap_id] + {:ok, object, _meta} = ObjectValidator.validate(valid_like, []) + refute user.ap_id in object["to"] end test "sets the context field to the context of the object if no context is given", %{ @@ -66,16 +79,6 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.LikeValidationTest do assert object["context"] == post_activity.data["context"] end - test "it errors when the actor is missing or not known", %{valid_like: valid_like} do - without_actor = Map.delete(valid_like, "actor") - - refute LikeValidator.cast_and_validate(without_actor).valid? - - with_invalid_actor = Map.put(valid_like, "actor", "invalidactor") - - refute LikeValidator.cast_and_validate(with_invalid_actor).valid? - end - test "it errors when the object is missing or not known", %{valid_like: valid_like} do without_object = Map.delete(valid_like, "object") |