Page MenuHomePhorge

No OneTemporary

Authored By
Unknown
Size
3 KB
Referenced Files
None
Subscribers
None
diff --git a/test/fixtures/strip_location_gps.jpg b/test/fixtures/strip_location_gps.jpg
new file mode 100644
index 000000000..d1072c92a
Binary files /dev/null and b/test/fixtures/strip_location_gps.jpg differ
diff --git a/test/fixtures/strip_location_gps.png b/test/fixtures/strip_location_gps.png
new file mode 100644
index 000000000..fafb4a92f
Binary files /dev/null and b/test/fixtures/strip_location_gps.png differ
diff --git a/test/pleroma/upload/filter/exiftool/strip_location_test.exs b/test/pleroma/upload/filter/exiftool/strip_location_test.exs
index 485060215..1d6b0683d 100644
--- a/test/pleroma/upload/filter/exiftool/strip_location_test.exs
+++ b/test/pleroma/upload/filter/exiftool/strip_location_test.exs
@@ -1,51 +1,85 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Upload.Filter.Exiftool.StripLocationTest do
use Pleroma.DataCase, async: true
alias Pleroma.Upload.Filter
test "apply exiftool filter" do
- assert Pleroma.Utils.command_available?("exiftool")
-
~w{jpg png}
|> Enum.map(fn type ->
- File.cp!(
- "test/fixtures/DSCN0010.#{type}",
- "test/fixtures/DSCN0010_tmp.#{type}"
- )
+ source = Path.absname("test/fixtures/strip_location_gps.#{type}")
+ tmp_path = copy_to_tmp(source)
upload = %Pleroma.Upload{
name: "image_with_GPS_data.#{type}",
- content_type: "image/jpeg",
- path: Path.absname("test/fixtures/DSCN0010.#{type}"),
- tempfile: Path.absname("test/fixtures/DSCN0010_tmp.#{type}")
+ content_type: if(type == "png", do: "image/png", else: "image/jpeg"),
+ path: source,
+ tempfile: tmp_path
}
assert Filter.Exiftool.StripLocation.filter(upload) == {:ok, :filtered}
- {exif_original, 0} = System.cmd("exiftool", ["-m", "test/fixtures/DSCN0010.#{type}"])
- {exif_filtered, 0} = System.cmd("exiftool", ["-m", "test/fixtures/DSCN0010_tmp.#{type}"])
-
- assert String.match?(exif_original, ~r/GPS/)
- refute String.match?(exif_filtered, ~r/GPS/)
+ assert exiftool_gps_tags(source) != ""
+ assert exiftool_gps_tags(tmp_path) == ""
end)
end
+ describe "ExifGpsStripper.strip_gps_data/2" do
+ test "strips GPS data from JPEG and PNG" do
+ for type <- ~w{jpg png} do
+ source_path = Path.absname("test/fixtures/strip_location_gps.#{type}")
+ tmp_path = copy_to_tmp(source_path)
+
+ assert exiftool_gps_tags(tmp_path) != ""
+ assert :ok = ExifGpsStripper.strip_gps_data(tmp_path, tmp_path)
+ assert exiftool_gps_tags(tmp_path) == ""
+ end
+ end
+
+ test "returns :noop for images without GPS metadata" do
+ for fixture <- ["test/fixtures/image.jpg", "test/fixtures/image.png"] do
+ source_path = Path.absname(fixture)
+ original = File.read!(source_path)
+ tmp_path = copy_to_tmp(source_path)
+
+ assert exiftool_gps_tags(tmp_path) == ""
+ assert :noop = ExifGpsStripper.strip_gps_data(tmp_path, tmp_path)
+ assert File.read!(tmp_path) == original
+ end
+ end
+ end
+
test "verify webp, heic, svg files are skipped" do
uploads =
~w{webp heic svg svg+xml}
|> Enum.map(fn type ->
%Pleroma.Upload{
name: "sample.#{type}",
content_type: "image/#{type}"
}
end)
uploads
|> Enum.each(fn upload ->
assert Filter.Exiftool.StripLocation.filter(upload) == {:ok, :noop}
end)
end
+
+ defp copy_to_tmp(source_path) do
+ tmp_path =
+ Path.join(
+ System.tmp_dir!(),
+ "strip_location_#{System.unique_integer([:positive])}#{Path.extname(source_path)}"
+ )
+
+ File.cp!(source_path, tmp_path)
+ tmp_path
+ end
+
+ defp exiftool_gps_tags(file_path) do
+ {output, 0} = System.cmd("exiftool", ["-m", "-gps:all", file_path])
+ String.trim(output)
+ end
end

File Metadata

Mime Type
text/x-diff
Expires
Fri, Oct 30, 12:39 AM (1 d, 12 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1799015
Default Alt Text
(3 KB)

Event Timeline