2016-11-03 12:29:30 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
describe Gitlab::ImportExport::FileImporter do
|
2018-12-21 20:21:59 +05:30
|
|
|
include ExportFileHelper
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
let(:shared) { Gitlab::ImportExport::Shared.new(nil) }
|
2018-11-20 20:47:30 +05:30
|
|
|
let(:storage_path) { "#{Dir.tmpdir}/file_importer_spec" }
|
2016-11-03 12:29:30 +05:30
|
|
|
let(:valid_file) { "#{shared.export_path}/valid.json" }
|
|
|
|
let(:symlink_file) { "#{shared.export_path}/invalid.json" }
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:hidden_symlink_file) { "#{shared.export_path}/.hidden" }
|
2016-11-03 12:29:30 +05:30
|
|
|
let(:subfolder_symlink_file) { "#{shared.export_path}/subfolder/invalid.json" }
|
2018-08-20 21:37:37 +05:30
|
|
|
let(:evil_symlink_file) { "#{shared.export_path}/.\nevil" }
|
2018-12-21 20:21:59 +05:30
|
|
|
let(:custom_mode_symlink_file) { "#{shared.export_path}/symlink.mode" }
|
2016-11-03 12:29:30 +05:30
|
|
|
|
|
|
|
before do
|
|
|
|
stub_const('Gitlab::ImportExport::FileImporter::MAX_RETRIES', 0)
|
2018-11-20 20:47:30 +05:30
|
|
|
stub_uploads_object_storage(FileUploader)
|
|
|
|
|
|
|
|
allow_any_instance_of(Gitlab::ImportExport).to receive(:storage_path).and_return(storage_path)
|
2016-11-03 12:29:30 +05:30
|
|
|
allow_any_instance_of(Gitlab::ImportExport::CommandLineUtil).to receive(:untar_zxf).and_return(true)
|
2018-03-27 19:54:05 +05:30
|
|
|
allow_any_instance_of(Gitlab::ImportExport::Shared).to receive(:relative_archive_path).and_return('test')
|
2018-03-17 18:26:18 +05:30
|
|
|
allow(SecureRandom).to receive(:hex).and_return('abcd')
|
2016-11-03 12:29:30 +05:30
|
|
|
setup_files
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
2018-11-20 20:47:30 +05:30
|
|
|
FileUtils.rm_rf(storage_path)
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
context 'normal run' do
|
|
|
|
before do
|
2018-11-20 20:47:30 +05:30
|
|
|
described_class.import(project: build(:project), archive_file: '', shared: shared)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
2016-11-03 12:29:30 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it 'removes symlinks in root folder' do
|
|
|
|
expect(File.exist?(symlink_file)).to be false
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'removes hidden symlinks in root folder' do
|
|
|
|
expect(File.exist?(hidden_symlink_file)).to be false
|
|
|
|
end
|
|
|
|
|
2018-08-20 21:37:37 +05:30
|
|
|
it 'removes evil symlinks in root folder' do
|
|
|
|
expect(File.exist?(evil_symlink_file)).to be false
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it 'removes symlinks in subfolders' do
|
|
|
|
expect(File.exist?(subfolder_symlink_file)).to be false
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-12-21 20:21:59 +05:30
|
|
|
it 'removes symlinks without any file permissions' do
|
|
|
|
expect(File.exist?(custom_mode_symlink_file)).to be false
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it 'does not remove a valid file' do
|
|
|
|
expect(File.exist?(valid_file)).to be true
|
|
|
|
end
|
|
|
|
|
2018-12-21 20:21:59 +05:30
|
|
|
it 'does not change a valid file permissions' do
|
|
|
|
expect(file_permissions(valid_file)).not_to eq(0000)
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it 'creates the file in the right subfolder' do
|
|
|
|
expect(shared.export_path).to include('test/abcd')
|
|
|
|
end
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
context 'error' do
|
|
|
|
before do
|
|
|
|
allow_any_instance_of(described_class).to receive(:wait_for_archived_file).and_raise(StandardError)
|
2018-11-20 20:47:30 +05:30
|
|
|
described_class.import(project: build(:project), archive_file: '', shared: shared)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'removes symlinks in root folder' do
|
|
|
|
expect(File.exist?(symlink_file)).to be false
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'removes hidden symlinks in root folder' do
|
|
|
|
expect(File.exist?(hidden_symlink_file)).to be false
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'removes symlinks in subfolders' do
|
|
|
|
expect(File.exist?(subfolder_symlink_file)).to be false
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not remove a valid file' do
|
|
|
|
expect(File.exist?(valid_file)).to be true
|
|
|
|
end
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def setup_files
|
|
|
|
FileUtils.mkdir_p("#{shared.export_path}/subfolder/")
|
|
|
|
FileUtils.touch(valid_file)
|
|
|
|
FileUtils.ln_s(valid_file, symlink_file)
|
|
|
|
FileUtils.ln_s(valid_file, subfolder_symlink_file)
|
2018-08-20 21:37:37 +05:30
|
|
|
FileUtils.ln_s(valid_file, hidden_symlink_file)
|
|
|
|
FileUtils.ln_s(valid_file, evil_symlink_file)
|
2018-12-21 20:21:59 +05:30
|
|
|
FileUtils.ln_s(valid_file, custom_mode_symlink_file)
|
|
|
|
FileUtils.chmod_R(0000, custom_mode_symlink_file)
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
|
|
|
end
|