summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-06-29 14:14:01 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-06-29 14:14:01 +0000
commita5baa12bfff6c41f6c9cf156edcf8e621f71848e (patch)
tree1a7f51da1300bca04a1bd070f12e66bc4955c832 /spec/lib/gitlab
parentbb51b8a098aa17b226d1e7941218512f8c835e08 (diff)
downloadgitlab-ce-a5baa12bfff6c41f6c9cf156edcf8e621f71848e.tar.gz
Add latest changes from gitlab-org/security/gitlab@15-1-stable-ee
Diffstat (limited to 'spec/lib/gitlab')
-rw-r--r--spec/lib/gitlab/import_export/decompressed_archive_size_validator_spec.rb59
1 files changed, 59 insertions, 0 deletions
diff --git a/spec/lib/gitlab/import_export/decompressed_archive_size_validator_spec.rb b/spec/lib/gitlab/import_export/decompressed_archive_size_validator_spec.rb
index fe3b638d20f..dea584e5019 100644
--- a/spec/lib/gitlab/import_export/decompressed_archive_size_validator_spec.rb
+++ b/spec/lib/gitlab/import_export/decompressed_archive_size_validator_spec.rb
@@ -86,6 +86,65 @@ RSpec.describe Gitlab::ImportExport::DecompressedArchiveSizeValidator do
include_examples 'logs raised exception and terminates validator process group'
end
end
+
+ context 'archive path validation' do
+ let(:filesize) { nil }
+
+ before do
+ expect(Gitlab::Import::Logger)
+ .to receive(:info)
+ .with(
+ import_upload_archive_path: filepath,
+ import_upload_archive_size: filesize,
+ message: error_message
+ )
+ end
+
+ context 'when archive path is traversed' do
+ let(:filepath) { '/foo/../bar' }
+ let(:error_message) { 'Invalid path' }
+
+ it 'returns false' do
+ expect(subject.valid?).to eq(false)
+ end
+ end
+
+ context 'when archive path is not a string' do
+ let(:filepath) { 123 }
+ let(:error_message) { 'Archive path is not a string' }
+
+ it 'returns false' do
+ expect(subject.valid?).to eq(false)
+ end
+ end
+
+ context 'which archive path is a symlink' do
+ let(:filepath) { File.join(Dir.tmpdir, 'symlink') }
+ let(:error_message) { 'Archive path is a symlink' }
+
+ before do
+ FileUtils.ln_s(filepath, filepath, force: true)
+ end
+
+ it 'returns false' do
+ expect(subject.valid?).to eq(false)
+ end
+ end
+
+ context 'when archive path is not a file' do
+ let(:filepath) { Dir.mktmpdir }
+ let(:filesize) { File.size(filepath) }
+ let(:error_message) { 'Archive path is not a file' }
+
+ after do
+ FileUtils.rm_rf(filepath)
+ end
+
+ it 'returns false' do
+ expect(subject.valid?).to eq(false)
+ end
+ end
+ end
end
def create_compressed_file