diff options
author | Francis Dinh <normandy@firemail.cc> | 2018-06-21 14:04:12 -0400 |
---|---|---|
committer | Francis Dinh <normandy@firemail.cc> | 2018-06-21 14:04:12 -0400 |
commit | 082920044abeadb9daf593d7e58d210634f8b4a5 (patch) | |
tree | f8b6fa864ab01ebdc2a47a02076fc1e95007db34 /test | |
parent | 90cf75f4a781f2eb7016a4a165a8617d4352451b (diff) | |
download | pleroma-082920044abeadb9daf593d7e58d210634f8b4a5.tar.gz pleroma-082920044abeadb9daf593d7e58d210634f8b4a5.zip |
Normalize file extension for uploaded files
Diffstat (limited to 'test')
-rw-r--r-- | test/fixtures/test.txt | 1 | ||||
-rw-r--r-- | test/upload_test.exs | 26 |
2 files changed, 27 insertions, 0 deletions
diff --git a/test/fixtures/test.txt b/test/fixtures/test.txt new file mode 100644 index 000000000..e9ea42a12 --- /dev/null +++ b/test/fixtures/test.txt @@ -0,0 +1 @@ +this is a text file diff --git a/test/upload_test.exs b/test/upload_test.exs index 09aa5e068..d273ea5f6 100644 --- a/test/upload_test.exs +++ b/test/upload_test.exs @@ -56,5 +56,31 @@ defmodule Pleroma.UploadTest do data = Upload.store(file, false) assert data["name"] == "an [image.jpg" end + + test "fixes incorrect file extension" do + File.cp!("test/fixtures/image.jpg", "test/fixtures/image_tmp.jpg") + + file = %Plug.Upload{ + content_type: "image/jpg", + path: Path.absname("test/fixtures/image_tmp.jpg"), + filename: "an [image.blah" + } + + data = Upload.store(file, false) + assert data["name"] == "an [image.jpg" + end + + test "don't modify filename of an unknown type" do + File.cp("test/fixtures/test.txt", "test/fixtures/test_tmp.txt") + + file = %Plug.Upload{ + content_type: "text/plain", + path: Path.absname("test/fixtures/test_tmp.txt"), + filename: "test.txt" + } + + data = Upload.store(file, false) + assert data["name"] == "test.txt" + end end end |