1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ActivityPub.ObjectValidators.AttachmentValidatorTest do
6 use Pleroma.DataCase, async: true
8 alias Pleroma.Web.ActivityPub.ActivityPub
9 alias Pleroma.Web.ActivityPub.ObjectValidators.AttachmentValidator
11 import Pleroma.Factory
13 describe "attachments" do
14 test "works with honkerific attachments" do
18 "summary" => "298p3RG7j27tfsZ9RQ.jpg",
20 "url" => "https://honk.tedunangst.com/d/298p3RG7j27tfsZ9RQ.jpg"
23 assert {:ok, attachment} =
24 AttachmentValidator.cast_and_validate(attachment)
25 |> Ecto.Changeset.apply_action(:insert)
27 assert attachment.mediaType == "application/octet-stream"
30 test "it turns mastodon attachments into our attachments" do
33 "http://mastodon.example.org/system/media_attachments/files/000/000/002/original/334ce029e7bfb920.jpg",
36 "mediaType" => "image/jpeg",
37 "blurhash" => "UD9jJz~VSbR#xT$~%KtQX9R,WAs9RjWBs:of"
41 AttachmentValidator.cast_and_validate(attachment)
42 |> Ecto.Changeset.apply_action(:insert)
47 "http://mastodon.example.org/system/media_attachments/files/000/000/002/original/334ce029e7bfb920.jpg",
49 mediaType: "image/jpeg"
53 assert attachment.mediaType == "image/jpeg"
54 assert attachment.blurhash == "UD9jJz~VSbR#xT$~%KtQX9R,WAs9RjWBs:of"
57 test "it handles our own uploads" do
61 content_type: "image/jpeg",
62 path: Path.absname("test/fixtures/image.jpg"),
63 filename: "an_image.jpg"
66 {:ok, attachment} = ActivityPub.upload(file, actor: user.ap_id)
70 |> AttachmentValidator.cast_and_validate()
71 |> Ecto.Changeset.apply_action(:insert)
73 assert attachment.mediaType == "image/jpeg"