Fixes uploading of empty files (#25115).

- prevents creation of attachment records without existing diskfile and empty
  digest
- adds test case to check file upload API response
- also removes the file size check in ActsAsAttachable which still prevented
  attachment of zero size attachments to containers but only for clients
  without Javascript (where save_attachments is called with the actual file
  upload).
  
Patch by Jens Kraemer.

git-svn-id: http://svn.redmine.org/redmine/trunk@16341 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang
2017-02-28 18:05:17 +00:00
parent dcc216002d
commit dac7903da3
3 changed files with 20 additions and 4 deletions

View File

@@ -197,4 +197,23 @@ class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base
end
end
end
test "POST /uploads.json should create an empty file and return a valid token" do
set_tmp_attachments_directory
assert_difference 'Attachment.count' do
post '/uploads.json', '', {"CONTENT_TYPE" => 'application/octet-stream'}.merge(credentials('jsmith'))
assert_response :created
end
json = ActiveSupport::JSON.decode(response.body)
assert_kind_of Hash, json['upload']
token = json['upload']['token']
assert token.present?
assert attachment = Attachment.find_by_token(token)
assert_equal 0, attachment.filesize
assert attachment.digest.present?
assert File.exist? attachment.diskfile
end
end