summaryrefslogtreecommitdiff
path: root/spec/finders/uploader_finder_spec.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-06-18 11:18:50 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-06-18 11:18:50 +0000
commit8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781 (patch)
treea77e7fe7a93de11213032ed4ab1f33a3db51b738 /spec/finders/uploader_finder_spec.rb
parent00b35af3db1abfe813a778f643dad221aad51fca (diff)
downloadgitlab-ce-8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781.tar.gz
Add latest changes from gitlab-org/gitlab@13-1-stable-ee
Diffstat (limited to 'spec/finders/uploader_finder_spec.rb')
-rw-r--r--spec/finders/uploader_finder_spec.rb55
1 files changed, 55 insertions, 0 deletions
diff --git a/spec/finders/uploader_finder_spec.rb b/spec/finders/uploader_finder_spec.rb
new file mode 100644
index 00000000000..814d4b88b57
--- /dev/null
+++ b/spec/finders/uploader_finder_spec.rb
@@ -0,0 +1,55 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe UploaderFinder do
+ describe '#execute' do
+ let(:project) { build(:project) }
+ let(:upload) { create(:upload, :issuable_upload, :with_file) }
+ let(:secret) { upload.secret }
+ let(:file_name) { upload.path }
+
+ subject { described_class.new(project, secret, file_name).execute }
+
+ before do
+ upload.save
+ end
+
+ context 'when successful' do
+ before do
+ allow_next_instance_of(FileUploader) do |uploader|
+ allow(uploader).to receive(:retrieve_from_store!).with(upload.path).and_return(uploader)
+ end
+ end
+
+ it 'gets the file-like uploader' do
+ expect(subject).to be_an_instance_of(FileUploader)
+ expect(subject.model).to eq(project)
+ expect(subject.secret).to eq(secret)
+ end
+ end
+
+ context 'when path traversal in file name' do
+ before do
+ upload.path = '/uploads/11111111111111111111111111111111/../../../../../../../../../../../../../../etc/passwd)'
+ upload.save
+ end
+
+ it 'returns nil' do
+ expect(subject).to be(nil)
+ end
+ end
+
+ context 'when unexpected failure' do
+ before do
+ allow_next_instance_of(FileUploader) do |uploader|
+ allow(uploader).to receive(:retrieve_from_store!).and_raise(StandardError)
+ end
+ end
+
+ it 'returns nil when unexpected error is raised' do
+ expect { subject }.to raise_error(StandardError)
+ end
+ end
+ end
+end