Commit 06d6eb18 authored by Robert Speicher's avatar Robert Speicher

Handle blank file path in UploadedFile.from_params

https://gitlab.com/gitlab-org/security/gitlab-workhorse/-/merge_requests/3
changed Workhorse so that it always provided `file.path` when
`direct_upload` was enabled, even if that path was blank.

Whereas we were checking for `path` not being `nil`, we now need to
check that it's present.

See also https://gitlab.com/gitlab-org/gitlab/-/issues/212424
parent f1dd55e8
...@@ -48,7 +48,7 @@ class UploadedFile ...@@ -48,7 +48,7 @@ class UploadedFile
return if path.blank? && remote_id.blank? return if path.blank? && remote_id.blank?
file_path = nil file_path = nil
if path if path.present?
file_path = File.realpath(path) file_path = File.realpath(path)
paths = Array(upload_paths) << Dir.tmpdir paths = Array(upload_paths) << Dir.tmpdir
......
...@@ -59,6 +59,16 @@ describe UploadedFile do ...@@ -59,6 +59,16 @@ describe UploadedFile do
expect(subject.sha256).to eq('sha256') expect(subject.sha256).to eq('sha256')
expect(subject.remote_id).to eq('remote_id') expect(subject.remote_id).to eq('remote_id')
end end
it 'handles a blank path' do
params['file.path'] = ''
# Not a real file, so can't determine size itself
params['file.size'] = 1.byte
expect { described_class.from_params(params, :file, upload_path) }
.not_to raise_error
end
end end
end end
......
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