1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Upload.Filter.Exiftool.ReadDescriptionTest do
6 use Pleroma.DataCase, async: true
7 alias Pleroma.Upload.Filter
9 @uploads %Pleroma.Upload{
10 name: "image_with_imagedescription_and_caption-abstract.jpg",
11 content_type: "image/jpeg",
12 path: Path.absname("test/fixtures/image_with_imagedescription_and_caption-abstract.jpg"),
13 tempfile: Path.absname("test/fixtures/image_with_imagedescription_and_caption-abstract.jpg"),
17 test "keeps description when not empty" do
18 uploads = %Pleroma.Upload{
19 name: "image_with_imagedescription_and_caption-abstract.jpg",
20 content_type: "image/jpeg",
21 path: Path.absname("test/fixtures/image_with_imagedescription_and_caption-abstract.jpg"),
23 Path.absname("test/fixtures/image_with_imagedescription_and_caption-abstract.jpg"),
24 description: "Some description"
27 assert Filter.Exiftool.ReadDescription.filter(uploads) ==
31 test "otherwise returns ImageDescription when present" do
32 uploads_after = %Pleroma.Upload{
33 name: "image_with_imagedescription_and_caption-abstract.jpg",
34 content_type: "image/jpeg",
35 path: Path.absname("test/fixtures/image_with_imagedescription_and_caption-abstract.jpg"),
37 Path.absname("test/fixtures/image_with_imagedescription_and_caption-abstract.jpg"),
38 description: "a descriptive white pixel"
41 assert Filter.Exiftool.ReadDescription.filter(@uploads) ==
42 {:ok, :filtered, uploads_after}
45 test "Ignores warnings" do
46 uploads = %Pleroma.Upload{
47 name: "image_with_imagedescription_and_caption-abstract_and_stray_data_after.png",
48 content_type: "image/png",
51 "test/fixtures/image_with_imagedescription_and_caption-abstract_and_stray_data_after.png"
55 "test/fixtures/image_with_imagedescription_and_caption-abstract_and_stray_data_after.png"
59 assert {:ok, :filtered, %{description: "a descriptive white pixel"}} =
60 Filter.Exiftool.ReadDescription.filter(uploads)
62 uploads = %Pleroma.Upload{
63 name: "image_with_stray_data_after.png",
64 content_type: "image/png",
65 path: Path.absname("test/fixtures/image_with_stray_data_after.png"),
66 tempfile: Path.absname("test/fixtures/image_with_stray_data_after.png")
69 assert {:ok, :filtered, %{description: nil}} = Filter.Exiftool.ReadDescription.filter(uploads)
72 test "otherwise returns iptc:Caption-Abstract when present" do
73 upload = %Pleroma.Upload{
74 name: "image_with_caption-abstract.jpg",
75 content_type: "image/jpeg",
76 path: Path.absname("test/fixtures/image_with_caption-abstract.jpg"),
77 tempfile: Path.absname("test/fixtures/image_with_caption-abstract.jpg"),
81 upload_after = %Pleroma.Upload{
82 name: "image_with_caption-abstract.jpg",
83 content_type: "image/jpeg",
84 path: Path.absname("test/fixtures/image_with_caption-abstract.jpg"),
85 tempfile: Path.absname("test/fixtures/image_with_caption-abstract.jpg"),
86 description: "an abstract white pixel"
89 assert Filter.Exiftool.ReadDescription.filter(upload) ==
90 {:ok, :filtered, upload_after}
93 test "otherwise returns nil" do
94 uploads = %Pleroma.Upload{
95 name: "image_with_no_description.jpg",
96 content_type: "image/jpeg",
97 path: Path.absname("test/fixtures/image_with_no_description.jpg"),
98 tempfile: Path.absname("test/fixtures/image_with_no_description.jpg"),
102 assert Filter.Exiftool.ReadDescription.filter(uploads) ==
103 {:ok, :filtered, uploads}
106 test "Return nil when image description from EXIF data exceeds the maximum length" do
107 clear_config([:instance, :description_limit], 5)
109 assert Filter.Exiftool.ReadDescription.filter(@uploads) ==
110 {:ok, :filtered, @uploads}
113 test "Ignores content with only whitespace" do
114 uploads = %Pleroma.Upload{
115 name: "non-existant.jpg",
116 content_type: "image/jpeg",
119 "test/fixtures/image_with_imagedescription_and_caption-abstract_whitespaces.jpg"
123 "test/fixtures/image_with_imagedescription_and_caption-abstract_whitespaces.jpg"
128 assert Filter.Exiftool.ReadDescription.filter(uploads) ==
129 {:ok, :filtered, uploads}
132 test "Return nil when image description from EXIF data can't be read" do
133 uploads = %Pleroma.Upload{
134 name: "non-existant.jpg",
135 content_type: "image/jpeg",
136 path: Path.absname("test/fixtures/non-existant.jpg"),
137 tempfile: Path.absname("test/fixtures/non-existant_tmp.jpg"),
141 assert Filter.Exiftool.ReadDescription.filter(uploads) ==
142 {:ok, :filtered, uploads}