Merge branch 'support/2255_posix_errors' into 'develop'
[#2255] added error messages for posix error code See merge request pleroma/pleroma!3138
This commit is contained in:
commit
6bb4f4e172
10 changed files with 504 additions and 58 deletions
|
|
@ -5,6 +5,7 @@
|
|||
defmodule Pleroma.Web.PleromaAPI.EmojiFileControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
import Mock
|
||||
import Tesla.Mock
|
||||
import Pleroma.Factory
|
||||
|
||||
|
|
@ -200,6 +201,31 @@ 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/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")
|
||||
|
|
|
|||
|
|
@ -3,8 +3,9 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.PleromaAPI.EmojiPackControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
use Pleroma.Web.ConnCase, async: false
|
||||
|
||||
import Mock
|
||||
import Tesla.Mock
|
||||
import Pleroma.Factory
|
||||
|
||||
|
|
@ -346,7 +347,7 @@ defmodule Pleroma.Web.PleromaAPI.EmojiPackControllerTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "PATCH /api/pleroma/emoji/pack?name=:name" do
|
||||
describe "PATCH/update /api/pleroma/emoji/pack?name=:name" do
|
||||
setup do
|
||||
pack_file = "#{@emoji_path}/test_pack/pack.json"
|
||||
original_content = File.read!(pack_file)
|
||||
|
|
@ -365,6 +366,20 @@ defmodule Pleroma.Web.PleromaAPI.EmojiPackControllerTest do
|
|||
}}
|
||||
end
|
||||
|
||||
test "returns error when file system not writable", %{admin_conn: conn} = ctx do
|
||||
with_mocks([
|
||||
{File, [:passthrough], [stat: fn _ -> {:error, :eacces} end]}
|
||||
]) do
|
||||
assert conn
|
||||
|> put_req_header("content-type", "multipart/form-data")
|
||||
|> patch(
|
||||
"/api/pleroma/emoji/pack?name=test_pack",
|
||||
%{"metadata" => ctx[:new_data]}
|
||||
)
|
||||
|> json_response_and_validate_schema(500)
|
||||
end
|
||||
end
|
||||
|
||||
test "for a pack without a fallback source", ctx do
|
||||
assert ctx[:admin_conn]
|
||||
|> put_req_header("content-type", "multipart/form-data")
|
||||
|
|
@ -424,6 +439,46 @@ defmodule Pleroma.Web.PleromaAPI.EmojiPackControllerTest do
|
|||
end
|
||||
|
||||
describe "POST/DELETE /api/pleroma/emoji/pack?name=:name" do
|
||||
test "returns an error on creates pack when file system not writable", %{
|
||||
admin_conn: admin_conn
|
||||
} do
|
||||
path_pack = Path.join(@emoji_path, "test_pack")
|
||||
|
||||
with_mocks([
|
||||
{File, [:passthrough], [mkdir: fn ^path_pack -> {:error, :eacces} end]}
|
||||
]) do
|
||||
assert admin_conn
|
||||
|> post("/api/pleroma/emoji/pack?name=test_pack")
|
||||
|> json_response_and_validate_schema(500) == %{
|
||||
"error" =>
|
||||
"Unexpected error occurred while creating pack. (POSIX error: Permission denied)"
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
test "returns an error on deletes pack when the file system is not writable", %{
|
||||
admin_conn: admin_conn
|
||||
} do
|
||||
path_pack = Path.join(@emoji_path, "test_emoji_pack")
|
||||
|
||||
try do
|
||||
{:ok, _pack} = Pleroma.Emoji.Pack.create("test_emoji_pack")
|
||||
|
||||
with_mocks([
|
||||
{File, [:passthrough], [rm_rf: fn ^path_pack -> {:error, :eacces, path_pack} end]}
|
||||
]) do
|
||||
assert admin_conn
|
||||
|> delete("/api/pleroma/emoji/pack?name=test_emoji_pack")
|
||||
|> json_response_and_validate_schema(500) == %{
|
||||
"error" =>
|
||||
"Couldn't delete the `test_emoji_pack` pack (POSIX error: Permission denied)"
|
||||
}
|
||||
end
|
||||
after
|
||||
File.rm_rf(path_pack)
|
||||
end
|
||||
end
|
||||
|
||||
test "creating and deleting a pack", %{admin_conn: admin_conn} do
|
||||
assert admin_conn
|
||||
|> post("/api/pleroma/emoji/pack?name=test_created")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue