diff options
author | Haelwenn (lanodan) Monnier <contact@hacktivis.me> | 2022-01-09 20:01:16 +0100 |
---|---|---|
committer | Haelwenn (lanodan) Monnier <contact@hacktivis.me> | 2022-11-27 04:21:31 +0100 |
commit | 8640d217b1119b015dbc135a07513466f1c2de8f (patch) | |
tree | 83ebd0b1da23fe06f16e3579f745949c1f54e626 /test | |
parent | da710920039ad892c1d988dc756227411f7a7e63 (diff) | |
download | pleroma-8640d217b1119b015dbc135a07513466f1c2de8f.tar.gz pleroma-8640d217b1119b015dbc135a07513466f1c2de8f.zip |
AttachmentValidator: Use custom ecto type and regex for "mediaType"
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 0e49fda99..a72460296 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" => |