Tests: Make as many tests as possible async.
[akkoma] / test / pleroma / upload / filter / exiftool_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Upload.Filter.ExiftoolTest do
6 use Pleroma.DataCase, async: true
7 alias Pleroma.Upload.Filter
8
9 test "apply exiftool filter" do
10 assert Pleroma.Utils.command_available?("exiftool")
11
12 File.cp!(
13 "test/fixtures/DSCN0010.jpg",
14 "test/fixtures/DSCN0010_tmp.jpg"
15 )
16
17 upload = %Pleroma.Upload{
18 name: "image_with_GPS_data.jpg",
19 content_type: "image/jpeg",
20 path: Path.absname("test/fixtures/DSCN0010.jpg"),
21 tempfile: Path.absname("test/fixtures/DSCN0010_tmp.jpg")
22 }
23
24 assert Filter.Exiftool.filter(upload) == {:ok, :filtered}
25
26 {exif_original, 0} = System.cmd("exiftool", ["test/fixtures/DSCN0010.jpg"])
27 {exif_filtered, 0} = System.cmd("exiftool", ["test/fixtures/DSCN0010_tmp.jpg"])
28
29 refute exif_original == exif_filtered
30 assert String.match?(exif_original, ~r/GPS/)
31 refute String.match?(exif_filtered, ~r/GPS/)
32 end
33
34 test "verify webp files are skipped" do
35 upload = %Pleroma.Upload{
36 name: "sample.webp",
37 content_type: "image/webp"
38 }
39
40 assert Filter.Exiftool.filter(upload) == {:ok, :noop}
41 end
42 end