diff options
author | Haelwenn <contact+git.pleroma.social@hacktivis.me> | 2022-07-03 21:04:41 +0000 |
---|---|---|
committer | Haelwenn <contact+git.pleroma.social@hacktivis.me> | 2022-07-03 21:04:41 +0000 |
commit | a15b45a5897817a5a5accfb8fd0fa5bcf8515e2b (patch) | |
tree | 786bbe5eb2219249ea87b44eae9089fdeb204152 /test | |
parent | 6b937d14737c07312595bb79c35c49b2e9c14fdb (diff) | |
parent | 83338c25a570e842944a5765cfbec55822ff4ae7 (diff) | |
download | pleroma-a15b45a5897817a5a5accfb8fd0fa5bcf8515e2b.tar.gz pleroma-a15b45a5897817a5a5accfb8fd0fa5bcf8515e2b.zip |
Merge branch 'bugfix/mime-validation-no-list' into 'develop'
Bugfix: Validate mediaType only by it's format
See merge request pleroma/pleroma!3597
Diffstat (limited to 'test')
-rw-r--r-- | test/pleroma/web/activity_pub/object_validators/attachment_validator_test.exs | 40 |
1 files changed, 40 insertions, 0 deletions
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 b07011b76..9a17e277e 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 @@ -27,6 +27,46 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.AttachmentValidatorTest do assert attachment.mediaType == "application/octet-stream" end + test "works with an unknown but valid mime type" do + attachment = %{ + "mediaType" => "x-custom/x-type", + "type" => "Document", + "url" => "https://example.org" + } + + assert {:ok, attachment} = + AttachmentValidator.cast_and_validate(attachment) + |> Ecto.Changeset.apply_action(:insert) + + assert attachment.mediaType == "x-custom/x-type" + end + + test "works with invalid mime types" do + attachment = %{ + "mediaType" => "x-customx-type", + "type" => "Document", + "url" => "https://example.org" + } + + assert {:ok, attachment} = + AttachmentValidator.cast_and_validate(attachment) + |> Ecto.Changeset.apply_action(:insert) + + assert attachment.mediaType == "application/octet-stream" + + attachment = %{ + "mediaType" => "https://example.org", + "type" => "Document", + "url" => "https://example.org" + } + + assert {:ok, attachment} = + AttachmentValidator.cast_and_validate(attachment) + |> Ecto.Changeset.apply_action(:insert) + + assert attachment.mediaType == "application/octet-stream" + end + test "it turns mastodon attachments into our attachments" do attachment = %{ "url" => |