X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=test%2Fpleroma%2Fweb%2Fpleroma_api%2Fcontrollers%2Femoji_file_controller_test.exs;h=0d3d38b33c76733e83764a0d6a794f66026f5c6d;hb=df03d64dc529e73c0424625a2a75d350f1d29680;hp=82de86ee31e4031f3e094a2b9a8f04e57f09aa21;hpb=b3d6cf90229ff3e9a5bd0028d4a6cbd3b68da9fe;p=akkoma
diff --git a/test/pleroma/web/pleroma_api/controllers/emoji_file_controller_test.exs b/test/pleroma/web/pleroma_api/controllers/emoji_file_controller_test.exs
index 82de86ee3..0d3d38b33 100644
--- a/test/pleroma/web/pleroma_api/controllers/emoji_file_controller_test.exs
+++ b/test/pleroma/web/pleroma_api/controllers/emoji_file_controller_test.exs
@@ -1,10 +1,11 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors
+# Copyright © 2017-2021 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.PleromaAPI.EmojiFileControllerTest do
- use Pleroma.Web.ConnCase
+ use Pleroma.Web.ConnCase, async: false
+ import Mock
import Tesla.Mock
import Pleroma.Factory
@@ -12,8 +13,6 @@ defmodule Pleroma.Web.PleromaAPI.EmojiFileControllerTest do
Pleroma.Config.get!([:instance, :static_dir]),
"emoji"
)
- setup do: clear_config([:auth, :enforce_oauth_admin_scope_usage], false)
-
setup do: clear_config([:instance, :public], true)
setup do
@@ -29,7 +28,7 @@ defmodule Pleroma.Web.PleromaAPI.EmojiFileControllerTest do
{:ok, %{admin_conn: admin_conn}}
end
- describe "POST/PATCH/DELETE /api/pleroma/emoji/packs/files?name=:name" do
+ describe "POST/PATCH/DELETE /api/v1/pleroma/emoji/packs/files?name=:name" do
setup do
pack_file = "#{@emoji_path}/test_pack/pack.json"
original_content = File.read!(pack_file)
@@ -56,7 +55,7 @@ defmodule Pleroma.Web.PleromaAPI.EmojiFileControllerTest do
resp =
admin_conn
|> put_req_header("content-type", "multipart/form-data")
- |> post("/api/pleroma/emoji/packs/files?name=test_pack", %{
+ |> post("/api/v1/pleroma/emoji/packs/files?name=test_pack", %{
file: %Plug.Upload{
content_type: "application/zip",
filename: "emojis.zip",
@@ -83,7 +82,7 @@ defmodule Pleroma.Web.PleromaAPI.EmojiFileControllerTest do
test "create shortcode exists", %{admin_conn: admin_conn} do
assert admin_conn
|> put_req_header("content-type", "multipart/form-data")
- |> post("/api/pleroma/emoji/packs/files?name=test_pack", %{
+ |> post("/api/v1/pleroma/emoji/packs/files?name=test_pack", %{
shortcode: "blank",
filename: "dir/blank.png",
file: %Plug.Upload{
@@ -101,7 +100,7 @@ defmodule Pleroma.Web.PleromaAPI.EmojiFileControllerTest do
assert admin_conn
|> put_req_header("content-type", "multipart/form-data")
- |> post("/api/pleroma/emoji/packs/files?name=test_pack", %{
+ |> post("/api/v1/pleroma/emoji/packs/files?name=test_pack", %{
shortcode: "blank3",
filename: "dir/blank.png",
file: %Plug.Upload{
@@ -119,7 +118,7 @@ defmodule Pleroma.Web.PleromaAPI.EmojiFileControllerTest do
assert admin_conn
|> put_req_header("content-type", "multipart/form-data")
- |> patch("/api/pleroma/emoji/packs/files?name=test_pack", %{
+ |> patch("/api/v1/pleroma/emoji/packs/files?name=test_pack", %{
shortcode: "blank",
new_shortcode: "blank2",
new_filename: "dir_2/blank_3.png"
@@ -135,7 +134,7 @@ defmodule Pleroma.Web.PleromaAPI.EmojiFileControllerTest do
assert admin_conn
|> put_req_header("content-type", "multipart/form-data")
- |> post("/api/pleroma/emoji/packs/files?name=test_pack", %{
+ |> post("/api/v1/pleroma/emoji/packs/files?name=test_pack", %{
shortcode: "blank3",
filename: "dir/blank.png",
file: %Plug.Upload{
@@ -153,7 +152,7 @@ defmodule Pleroma.Web.PleromaAPI.EmojiFileControllerTest do
assert admin_conn
|> put_req_header("content-type", "multipart/form-data")
- |> patch("/api/pleroma/emoji/packs/files?name=test_pack", %{
+ |> patch("/api/v1/pleroma/emoji/packs/files?name=test_pack", %{
shortcode: "blank3",
new_shortcode: "blank4",
new_filename: "dir_2/blank_3.png",
@@ -171,7 +170,7 @@ defmodule Pleroma.Web.PleromaAPI.EmojiFileControllerTest do
test "with empty filename", %{admin_conn: admin_conn} do
assert admin_conn
|> put_req_header("content-type", "multipart/form-data")
- |> post("/api/pleroma/emoji/packs/files?name=test_pack", %{
+ |> post("/api/v1/pleroma/emoji/packs/files?name=test_pack", %{
shortcode: "blank2",
filename: "",
file: %Plug.Upload{
@@ -187,7 +186,7 @@ defmodule Pleroma.Web.PleromaAPI.EmojiFileControllerTest do
test "add file with not loaded pack", %{admin_conn: admin_conn} do
assert admin_conn
|> put_req_header("content-type", "multipart/form-data")
- |> post("/api/pleroma/emoji/packs/files?name=not_loaded", %{
+ |> post("/api/v1/pleroma/emoji/packs/files?name=not_loaded", %{
shortcode: "blank3",
filename: "dir/blank.png",
file: %Plug.Upload{
@@ -200,9 +199,34 @@ defmodule Pleroma.Web.PleromaAPI.EmojiFileControllerTest do
}
end
+ test "returns an error on add file when file system is not writable", %{
+ admin_conn: admin_conn
+ } do
+ pack_file = Path.join([@emoji_path, "not_loaded", "pack.json"])
+
+ with_mocks([
+ {File, [:passthrough], [stat: fn ^pack_file -> {:error, :eacces} end]}
+ ]) do
+ assert admin_conn
+ |> put_req_header("content-type", "multipart/form-data")
+ |> post("/api/v1/pleroma/emoji/packs/files?name=not_loaded", %{
+ shortcode: "blank3",
+ filename: "dir/blank.png",
+ file: %Plug.Upload{
+ filename: "blank.png",
+ path: "#{@emoji_path}/test_pack/blank.png"
+ }
+ })
+ |> json_response_and_validate_schema(500) == %{
+ "error" =>
+ "Unexpected error occurred while adding file to pack. (POSIX error: Permission denied)"
+ }
+ end
+ end
+
test "remove file with not loaded pack", %{admin_conn: admin_conn} do
assert admin_conn
- |> delete("/api/pleroma/emoji/packs/files?name=not_loaded&shortcode=blank3")
+ |> delete("/api/v1/pleroma/emoji/packs/files?name=not_loaded&shortcode=blank3")
|> json_response_and_validate_schema(:not_found) == %{
"error" => "pack \"not_loaded\" is not found"
}
@@ -210,7 +234,7 @@ defmodule Pleroma.Web.PleromaAPI.EmojiFileControllerTest do
test "remove file with empty shortcode", %{admin_conn: admin_conn} do
assert admin_conn
- |> delete("/api/pleroma/emoji/packs/files?name=not_loaded&shortcode=")
+ |> delete("/api/v1/pleroma/emoji/packs/files?name=not_loaded&shortcode=")
|> json_response_and_validate_schema(:not_found) == %{
"error" => "pack \"not_loaded\" is not found"
}
@@ -219,7 +243,7 @@ defmodule Pleroma.Web.PleromaAPI.EmojiFileControllerTest do
test "update file with not loaded pack", %{admin_conn: admin_conn} do
assert admin_conn
|> put_req_header("content-type", "multipart/form-data")
- |> patch("/api/pleroma/emoji/packs/files?name=not_loaded", %{
+ |> patch("/api/v1/pleroma/emoji/packs/files?name=not_loaded", %{
shortcode: "blank4",
new_shortcode: "blank3",
new_filename: "dir_2/blank_3.png"
@@ -232,7 +256,7 @@ defmodule Pleroma.Web.PleromaAPI.EmojiFileControllerTest do
test "new with shortcode as file with update", %{admin_conn: admin_conn} do
assert admin_conn
|> put_req_header("content-type", "multipart/form-data")
- |> post("/api/pleroma/emoji/packs/files?name=test_pack", %{
+ |> post("/api/v1/pleroma/emoji/packs/files?name=test_pack", %{
shortcode: "blank4",
filename: "dir/blank.png",
file: %Plug.Upload{
@@ -250,7 +274,7 @@ defmodule Pleroma.Web.PleromaAPI.EmojiFileControllerTest do
assert admin_conn
|> put_req_header("content-type", "multipart/form-data")
- |> patch("/api/pleroma/emoji/packs/files?name=test_pack", %{
+ |> patch("/api/v1/pleroma/emoji/packs/files?name=test_pack", %{
shortcode: "blank4",
new_shortcode: "blank3",
new_filename: "dir_2/blank_3.png"
@@ -265,7 +289,7 @@ defmodule Pleroma.Web.PleromaAPI.EmojiFileControllerTest do
assert File.exists?("#{@emoji_path}/test_pack/dir_2/blank_3.png")
assert admin_conn
- |> delete("/api/pleroma/emoji/packs/files?name=test_pack&shortcode=blank3")
+ |> delete("/api/v1/pleroma/emoji/packs/files?name=test_pack&shortcode=blank3")
|> json_response_and_validate_schema(200) == %{
"blank" => "blank.png",
"blank2" => "blank2.png"
@@ -287,7 +311,7 @@ defmodule Pleroma.Web.PleromaAPI.EmojiFileControllerTest do
assert admin_conn
|> put_req_header("content-type", "multipart/form-data")
- |> post("/api/pleroma/emoji/packs/files?name=test_pack", %{
+ |> post("/api/v1/pleroma/emoji/packs/files?name=test_pack", %{
shortcode: "blank_url",
file: "https://test-blank/blank_url.png"
})
@@ -307,7 +331,7 @@ defmodule Pleroma.Web.PleromaAPI.EmojiFileControllerTest do
assert admin_conn
|> put_req_header("content-type", "multipart/form-data")
- |> post("/api/pleroma/emoji/packs/files?name=test_pack", %{
+ |> post("/api/v1/pleroma/emoji/packs/files?name=test_pack", %{
file: %Plug.Upload{
filename: "shortcode.png",
path: "#{Pleroma.Config.get([:instance, :static_dir])}/add/shortcode.png"
@@ -322,7 +346,7 @@ defmodule Pleroma.Web.PleromaAPI.EmojiFileControllerTest do
test "remove non existing shortcode in pack.json", %{admin_conn: admin_conn} do
assert admin_conn
- |> delete("/api/pleroma/emoji/packs/files?name=test_pack&shortcode=blank3")
+ |> delete("/api/v1/pleroma/emoji/packs/files?name=test_pack&shortcode=blank3")
|> json_response_and_validate_schema(:bad_request) == %{
"error" => "Emoji \"blank3\" does not exist"
}
@@ -331,7 +355,7 @@ defmodule Pleroma.Web.PleromaAPI.EmojiFileControllerTest do
test "update non existing emoji", %{admin_conn: admin_conn} do
assert admin_conn
|> put_req_header("content-type", "multipart/form-data")
- |> patch("/api/pleroma/emoji/packs/files?name=test_pack", %{
+ |> patch("/api/v1/pleroma/emoji/packs/files?name=test_pack", %{
shortcode: "blank3",
new_shortcode: "blank4",
new_filename: "dir_2/blank_3.png"
@@ -347,7 +371,7 @@ defmodule Pleroma.Web.PleromaAPI.EmojiFileControllerTest do
} =
admin_conn
|> put_req_header("content-type", "multipart/form-data")
- |> patch("/api/pleroma/emoji/packs/files?name=test_pack", %{
+ |> patch("/api/v1/pleroma/emoji/packs/files?name=test_pack", %{
shortcode: "blank",
new_filename: "dir_2/blank_3.png"
})