Commit b6d8d327 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch 'sh-handle-zero-maximum-upload-size' into 'master'

Fix division by error when upload max size is set to 0

See merge request gitlab-org/gitlab!49482
parents b5aee638 27c27b46
---
title: Fix division by error when upload max size is set to 0
merge_request: 49482
author:
type: fixed
......@@ -184,15 +184,20 @@ module ObjectStorage
private
def rounded_multipart_part_size
# round multipart_part_size up to minimum_mulitpart_size
# round multipart_part_size up to minimum_multipart_size
(multipart_part_size + MINIMUM_MULTIPART_SIZE - 1) / MINIMUM_MULTIPART_SIZE * MINIMUM_MULTIPART_SIZE
end
def multipart_part_size
return MINIMUM_MULTIPART_SIZE if maximum_size == 0
maximum_size / number_of_multipart_parts
end
def number_of_multipart_parts
# If we don't have max length, we can only assume the file is as large as possible.
return MAXIMUM_MULTIPART_PARTS if maximum_size == 0
[
# round maximum_size up to minimum_mulitpart_size
(maximum_size + MINIMUM_MULTIPART_SIZE - 1) / MINIMUM_MULTIPART_SIZE,
......@@ -201,7 +206,7 @@ module ObjectStorage
end
def requires_multipart_upload?
config.aws? && !has_length
config.aws? && !has_length && !use_workhorse_s3_client?
end
def upload_id
......
......@@ -162,6 +162,10 @@ RSpec.describe ObjectStorage::DirectUpload do
it 'enables the Workhorse client' do
expect(subject[:UseWorkhorseClient]).to be true
end
it 'omits the multipart upload URLs' do
expect(subject).not_to include(:MultipartUpload)
end
end
context 'when only server side encryption is used' do
......@@ -340,6 +344,30 @@ RSpec.describe ObjectStorage::DirectUpload do
stub_object_storage_multipart_init(storage_url, "myUpload")
end
context 'when maximum upload size is 0' do
let(:maximum_size) { 0 }
it 'returns maximum number of parts' do
expect(subject[:MultipartUpload][:PartURLs].length).to eq(100)
end
it 'part size is minimum, 5MB' do
expect(subject[:MultipartUpload][:PartSize]).to eq(5.megabyte)
end
end
context 'when maximum upload size is < 5 MB' do
let(:maximum_size) { 1024 }
it 'returns only 1 part' do
expect(subject[:MultipartUpload][:PartURLs].length).to eq(1)
end
it 'part size is minimum, 5MB' do
expect(subject[:MultipartUpload][:PartSize]).to eq(5.megabyte)
end
end
context 'when maximum upload size is 10MB' do
let(:maximum_size) { 10.megabyte }
......
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