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
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"
40 AttachmentValidator.cast_and_validate(attachment)
41 |> Ecto.Changeset.apply_action(:insert)
46 "http://mastodon.example.org/system/media_attachments/files/000/000/002/original/334ce029e7bfb920.jpg",
48 mediaType: "image/jpeg"
52 assert attachment.mediaType == "image/jpeg"
55 test "it handles our own uploads" do
59 content_type: "image/jpg",
60 path: Path.absname("test/fixtures/image.jpg"),
61 filename: "an_image.jpg"
64 {:ok, attachment} = ActivityPub.upload(file, actor: user.ap_id)
68 |> AttachmentValidator.cast_and_validate()
69 |> Ecto.Changeset.apply_action(:insert)
71 assert attachment.mediaType == "image/jpeg"