diff options
author | duponin <duponin@locahlo.st> | 2022-12-11 22:54:47 +0100 |
---|---|---|
committer | duponin <duponin@locahlo.st> | 2022-12-11 22:54:47 +0100 |
commit | 452595baeda8327b862d03e450ac004679efe86e (patch) | |
tree | 4291fd61bbdbe96c3501d888995b1c4164237d0f /test | |
parent | 204fd6faae8c39706a5ded42c7cc4fbc71a733bc (diff) | |
download | pleroma-452595baeda8327b862d03e450ac004679efe86e.tar.gz pleroma-452595baeda8327b862d03e450ac004679efe86e.zip |
Uploading an avatar media exceeding max size returns a 413
Until now it was returning a 500 because the upload plug were going
through the changeset and ending in the JSON encoder, which raised
because struct has to @derive the encoder.
Diffstat (limited to 'test')
-rw-r--r-- | test/pleroma/web/mastodon_api/update_credentials_test.exs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/test/pleroma/web/mastodon_api/update_credentials_test.exs b/test/pleroma/web/mastodon_api/update_credentials_test.exs index f5211a60e..57bca897c 100644 --- a/test/pleroma/web/mastodon_api/update_credentials_test.exs +++ b/test/pleroma/web/mastodon_api/update_credentials_test.exs @@ -259,6 +259,34 @@ defmodule Pleroma.Web.MastodonAPI.UpdateCredentialsTest do assert user.avatar == nil end + test "updates the user's avatar, upload_limit, returns a HTTP 413", %{conn: conn, user: user} do + upload_limit = Config.get([:instance, :upload_limit]) * 8 + 8 + + assert :ok == + File.write(Path.absname("test/tmp/large_binary.data"), <<0::size(upload_limit)>>) + + new_avatar_oversized = %Plug.Upload{ + content_type: nil, + path: Path.absname("test/tmp/large_binary.data"), + filename: "large_binary.data" + } + + assert user.avatar == %{} + + res = + patch(conn, "/api/v1/accounts/update_credentials", %{"avatar" => new_avatar_oversized}) + + assert user_response = json_response_and_validate_schema(res, 413) + assert user_response["avatar"] != User.avatar_url(user) + + user = User.get_by_id(user.id) + assert user.avatar == %{} + + clear_config([:instance, :upload_limit], upload_limit) + + assert :ok == File.rm(Path.absname("test/tmp/large_binary.data")) + end + test "updates the user's banner", %{user: user, conn: conn} do new_header = %Plug.Upload{ content_type: "image/jpeg", |