Commit 1ead057d authored by Darby Frey's avatar Darby Frey

Adding custom error response for when file upload is too large

parent b7b5f4c9
......@@ -60,6 +60,7 @@ module API
route_setting :authentication, basic_auth_personal_access_token: true, job_token_allowed: true
post ':id/secure_files' do
secure_file = user_project.secure_files.new(
name: params[:name],
permissions: params[:permissions] || :read_only
......@@ -67,6 +68,8 @@ module API
secure_file.file = params[:file]
file_too_large! unless secure_file.file.size < ::Ci::SecureFile::FILE_SIZE_LIMIT.to_i
if secure_file.save
present secure_file, with: Entities::Ci::SecureFile
else
......
......@@ -226,6 +226,21 @@ RSpec.describe API::Ci::SecureFiles do
expect(response).to have_gitlab_http_status(:bad_request)
end
it 'returns a 413 error when the file size is too large' do
allow_next_instance_of(Ci::SecureFile) do |instance|
allow(instance).to receive_message_chain(:file, :size).and_return(6.megabytes.to_i)
end
post_params = {
file: fixture_file_upload('spec/fixtures/ci_secure_files/upload-keystore.jks'),
name: 'upload-keystore.jks'
}
post api("/projects/#{project.id}/secure_files", user), params: post_params
expect(response).to have_gitlab_http_status(:payload_too_large)
end
end
context 'authorized user with invalid permissions' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment