diff options
Diffstat (limited to 'spec/lib/gitlab/import_export')
12 files changed, 81 insertions, 29 deletions
diff --git a/spec/lib/gitlab/import_export/all_models.yml b/spec/lib/gitlab/import_export/all_models.yml index 825513bdfc5..d0282e14d5f 100644 --- a/spec/lib/gitlab/import_export/all_models.yml +++ b/spec/lib/gitlab/import_export/all_models.yml @@ -146,6 +146,7 @@ merge_requests: - merge_user - merge_request_diffs - merge_request_diff +- merge_head_diff - merge_request_context_commits - merge_request_context_commit_diff_files - events @@ -544,7 +545,7 @@ project: - daily_build_group_report_results - jira_imports - compliance_framework_setting -- compliance_management_frameworks +- compliance_management_framework - metrics_users_starred_dashboards - alert_management_alerts - repository_storage_moves @@ -560,7 +561,10 @@ project: - alert_management_http_integrations - exported_protected_branches - incident_management_oncall_schedules +- incident_management_oncall_rotations - debian_distributions +- merge_request_metrics +- security_orchestration_policy_configuration award_emoji: - awardable - user @@ -589,6 +593,7 @@ lfs_file_locks: project_badges: - project metrics: +- target_project - merge_request - latest_closed_by - merged_by 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 efb271086a0..96c467e78d6 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 @@ -27,25 +27,55 @@ RSpec.describe Gitlab::ImportExport::DecompressedArchiveSizeValidator do end context 'when file exceeds allowed decompressed size' do - it 'returns false' do + it 'logs error message returns false' do + expect(Gitlab::Import::Logger) + .to receive(:info) + .with( + import_upload_archive_path: filepath, + import_upload_archive_size: File.size(filepath), + message: 'Decompressed archive size limit reached' + ) expect(subject.valid?).to eq(false) end end - context 'when something goes wrong during decompression' do - before do - allow(subject.archive_file).to receive(:eof?).and_raise(StandardError) + context 'when exception occurs during decompression' do + shared_examples 'logs raised exception and terminates validator process group' do + let(:std) { double(:std, close: nil, value: nil) } + let(:wait_thr) { double } + + before do + allow(Process).to receive(:getpgid).and_return(2) + allow(Open3).to receive(:popen3).and_return([std, std, std, wait_thr]) + allow(wait_thr).to receive(:[]).with(:pid).and_return(1) + allow(wait_thr).to receive(:value).and_raise(exception) + end + + it 'logs raised exception and terminates validator process group' do + expect(Gitlab::Import::Logger) + .to receive(:info) + .with( + import_upload_archive_path: filepath, + import_upload_archive_size: File.size(filepath), + message: error_message + ) + expect(Process).to receive(:kill).with(-1, 2) + expect(subject.valid?).to eq(false) + end end - it 'logs and tracks raised exception' do - expect(Gitlab::ErrorTracking).to receive(:track_exception).with(instance_of(StandardError)) - expect(Gitlab::Import::Logger).to receive(:info).with(hash_including(message: 'Decompressed archive size validation failed.')) + context 'when timeout occurs' do + let(:error_message) { 'Timeout reached during archive decompression' } + let(:exception) { Timeout::Error } - subject.valid? + include_examples 'logs raised exception and terminates validator process group' end - it 'returns false' do - expect(subject.valid?).to eq(false) + context 'when exception occurs' do + let(:error_message) { 'Error!' } + let(:exception) { StandardError.new(error_message) } + + include_examples 'logs raised exception and terminates validator process group' end end end diff --git a/spec/lib/gitlab/import_export/design_repo_restorer_spec.rb b/spec/lib/gitlab/import_export/design_repo_restorer_spec.rb index b311a02833c..6680f4e7a03 100644 --- a/spec/lib/gitlab/import_export/design_repo_restorer_spec.rb +++ b/spec/lib/gitlab/import_export/design_repo_restorer_spec.rb @@ -11,12 +11,12 @@ RSpec.describe Gitlab::ImportExport::DesignRepoRestorer do let!(:project) { create(:project) } let(:export_path) { "#{Dir.tmpdir}/project_tree_saver_spec" } let(:shared) { project.import_export_shared } - let(:bundler) { Gitlab::ImportExport::DesignRepoSaver.new(project: project_with_design_repo, shared: shared) } + let(:bundler) { Gitlab::ImportExport::DesignRepoSaver.new(exportable: project_with_design_repo, shared: shared) } let(:bundle_path) { File.join(shared.export_path, Gitlab::ImportExport.design_repo_bundle_filename) } let(:restorer) do described_class.new(path_to_bundle: bundle_path, shared: shared, - project: project) + importable: project) end before do diff --git a/spec/lib/gitlab/import_export/design_repo_saver_spec.rb b/spec/lib/gitlab/import_export/design_repo_saver_spec.rb index 2575d209db5..5501e3dee5a 100644 --- a/spec/lib/gitlab/import_export/design_repo_saver_spec.rb +++ b/spec/lib/gitlab/import_export/design_repo_saver_spec.rb @@ -9,7 +9,7 @@ RSpec.describe Gitlab::ImportExport::DesignRepoSaver do let!(:project) { create(:project, :design_repo) } let(:export_path) { "#{Dir.tmpdir}/project_tree_saver_spec" } let(:shared) { project.import_export_shared } - let(:design_bundler) { described_class.new(project: project, shared: shared) } + let(:design_bundler) { described_class.new(exportable: project, shared: shared) } before do project.add_maintainer(user) diff --git a/spec/lib/gitlab/import_export/fork_spec.rb b/spec/lib/gitlab/import_export/fork_spec.rb index ef7394053b9..65c28a8b8a2 100644 --- a/spec/lib/gitlab/import_export/fork_spec.rb +++ b/spec/lib/gitlab/import_export/fork_spec.rb @@ -12,11 +12,11 @@ RSpec.describe 'forked project import' do let(:shared) { project.import_export_shared } let(:forked_from_project) { create(:project, :repository) } let(:forked_project) { fork_project(project_with_repo, nil, repository: true) } - let(:repo_saver) { Gitlab::ImportExport::RepoSaver.new(project: project_with_repo, shared: shared) } + let(:repo_saver) { Gitlab::ImportExport::RepoSaver.new(exportable: project_with_repo, shared: shared) } let(:bundle_path) { File.join(shared.export_path, Gitlab::ImportExport.project_bundle_filename) } let(:repo_restorer) do - Gitlab::ImportExport::RepoRestorer.new(path_to_bundle: bundle_path, shared: shared, project: project) + Gitlab::ImportExport::RepoRestorer.new(path_to_bundle: bundle_path, shared: shared, importable: project) end let!(:merge_request) do diff --git a/spec/lib/gitlab/import_export/group/tree_restorer_spec.rb b/spec/lib/gitlab/import_export/group/tree_restorer_spec.rb index 2794acb8980..d2153221e8f 100644 --- a/spec/lib/gitlab/import_export/group/tree_restorer_spec.rb +++ b/spec/lib/gitlab/import_export/group/tree_restorer_spec.rb @@ -21,6 +21,7 @@ RSpec.describe Gitlab::ImportExport::Group::TreeRestorer do group_tree_restorer = described_class.new(user: user, shared: @shared, group: @group) expect(group_tree_restorer.restore).to be_truthy + expect(group_tree_restorer.groups_mapping).not_to be_empty end end diff --git a/spec/lib/gitlab/import_export/importer_spec.rb b/spec/lib/gitlab/import_export/importer_spec.rb index 75db3167ebc..20f0f6af6f3 100644 --- a/spec/lib/gitlab/import_export/importer_spec.rb +++ b/spec/lib/gitlab/import_export/importer_spec.rb @@ -69,8 +69,8 @@ RSpec.describe Gitlab::ImportExport::Importer do repo_path = File.join(shared.export_path, Gitlab::ImportExport.project_bundle_filename) restorer = double(Gitlab::ImportExport::RepoRestorer) - expect(Gitlab::ImportExport::RepoRestorer).to receive(:new).with(path_to_bundle: repo_path, shared: shared, project: project).and_return(restorer) - expect(Gitlab::ImportExport::RepoRestorer).to receive(:new).with(path_to_bundle: wiki_repo_path, shared: shared, project: ProjectWiki.new(project)).and_return(restorer) + expect(Gitlab::ImportExport::RepoRestorer).to receive(:new).with(path_to_bundle: repo_path, shared: shared, importable: project).and_return(restorer) + expect(Gitlab::ImportExport::RepoRestorer).to receive(:new).with(path_to_bundle: wiki_repo_path, shared: shared, importable: ProjectWiki.new(project)).and_return(restorer) expect(Gitlab::ImportExport::RepoRestorer).to receive(:new).and_call_original expect(restorer).to receive(:restore).and_return(true).twice diff --git a/spec/lib/gitlab/import_export/repo_restorer_spec.rb b/spec/lib/gitlab/import_export/repo_restorer_spec.rb index a6b917457c2..fe43a23e242 100644 --- a/spec/lib/gitlab/import_export/repo_restorer_spec.rb +++ b/spec/lib/gitlab/import_export/repo_restorer_spec.rb @@ -27,10 +27,10 @@ RSpec.describe Gitlab::ImportExport::RepoRestorer do end describe 'bundle a project Git repo' do - let(:bundler) { Gitlab::ImportExport::RepoSaver.new(project: project_with_repo, shared: shared) } + let(:bundler) { Gitlab::ImportExport::RepoSaver.new(exportable: project_with_repo, shared: shared) } let(:bundle_path) { File.join(shared.export_path, Gitlab::ImportExport.project_bundle_filename) } - subject { described_class.new(path_to_bundle: bundle_path, shared: shared, project: project) } + subject { described_class.new(path_to_bundle: bundle_path, shared: shared, importable: project) } after do Gitlab::Shell.new.remove_repository(project.repository_storage, project.disk_path) @@ -62,10 +62,10 @@ RSpec.describe Gitlab::ImportExport::RepoRestorer do end describe 'restore a wiki Git repo' do - let(:bundler) { Gitlab::ImportExport::WikiRepoSaver.new(project: project_with_repo, shared: shared) } + let(:bundler) { Gitlab::ImportExport::WikiRepoSaver.new(exportable: project_with_repo, shared: shared) } let(:bundle_path) { File.join(shared.export_path, Gitlab::ImportExport.wiki_repo_bundle_filename) } - subject { described_class.new(path_to_bundle: bundle_path, shared: shared, project: ProjectWiki.new(project)) } + subject { described_class.new(path_to_bundle: bundle_path, shared: shared, importable: ProjectWiki.new(project)) } after do Gitlab::Shell.new.remove_repository(project.wiki.repository_storage, project.wiki.disk_path) @@ -83,7 +83,7 @@ RSpec.describe Gitlab::ImportExport::RepoRestorer do describe 'no wiki in the bundle' do let!(:project_without_wiki) { create(:project) } - let(:bundler) { Gitlab::ImportExport::WikiRepoSaver.new(project: project_without_wiki, shared: shared) } + let(:bundler) { Gitlab::ImportExport::WikiRepoSaver.new(exportable: project_without_wiki, shared: shared) } it 'does not creates an empty wiki' do expect(subject.restore).to be true diff --git a/spec/lib/gitlab/import_export/repo_saver_spec.rb b/spec/lib/gitlab/import_export/repo_saver_spec.rb index 73d51000c67..52001e778d6 100644 --- a/spec/lib/gitlab/import_export/repo_saver_spec.rb +++ b/spec/lib/gitlab/import_export/repo_saver_spec.rb @@ -8,7 +8,7 @@ RSpec.describe Gitlab::ImportExport::RepoSaver do let!(:project) { create(:project, :repository) } let(:export_path) { "#{Dir.tmpdir}/project_tree_saver_spec" } let(:shared) { project.import_export_shared } - let(:bundler) { described_class.new(project: project, shared: shared) } + let(:bundler) { described_class.new(exportable: project, shared: shared) } before do project.add_maintainer(user) @@ -25,6 +25,14 @@ RSpec.describe Gitlab::ImportExport::RepoSaver do expect(bundler.save).to be true end + it 'creates the directory for the repository' do + allow(bundler).to receive(:bundle_full_path).and_return('/foo/bar/file.tar.gz') + + expect(FileUtils).to receive(:mkdir_p).with('/foo/bar', anything) + + bundler.save # rubocop:disable Rails/SaveBang + end + context 'when the repo is empty' do let!(:project) { create(:project) } diff --git a/spec/lib/gitlab/import_export/safe_model_attributes.yml b/spec/lib/gitlab/import_export/safe_model_attributes.yml index a93ee051ccf..e301be47d68 100644 --- a/spec/lib/gitlab/import_export/safe_model_attributes.yml +++ b/spec/lib/gitlab/import_export/safe_model_attributes.yml @@ -220,6 +220,7 @@ MergeRequestDiff: - commits_count - files_count - sorted +- diff_type MergeRequestDiffCommit: - merge_request_diff_id - relative_order @@ -231,6 +232,7 @@ MergeRequestDiffCommit: - committer_name - committer_email - message +- trailers MergeRequestDiffFile: - merge_request_diff_id - relative_order @@ -255,6 +257,7 @@ MergeRequestContextCommit: - committer_email - message - merge_request_id +- trailers MergeRequestContextCommitDiffFile: - sha - relative_order @@ -580,6 +583,7 @@ ProjectFeature: - requirements_access_level - analytics_access_level - operations_access_level +- security_and_compliance_access_level - created_at - updated_at ProtectedBranch::MergeAccessLevel: diff --git a/spec/lib/gitlab/import_export/saver_spec.rb b/spec/lib/gitlab/import_export/saver_spec.rb index 865c7e57b5a..877474dd862 100644 --- a/spec/lib/gitlab/import_export/saver_spec.rb +++ b/spec/lib/gitlab/import_export/saver_spec.rb @@ -6,7 +6,8 @@ require 'fileutils' RSpec.describe Gitlab::ImportExport::Saver do let!(:project) { create(:project, :public, name: 'project') } let(:base_path) { "#{Dir.tmpdir}/project_tree_saver_spec" } - let(:export_path) { "#{base_path}/project_tree_saver_spec/export" } + let(:archive_path) { "#{base_path}/archive" } + let(:export_path) { "#{archive_path}/export" } let(:shared) { project.import_export_shared } subject { described_class.new(exportable: project, shared: shared) } @@ -35,10 +36,13 @@ RSpec.describe Gitlab::ImportExport::Saver do .to match(%r[\/uploads\/-\/system\/import_export_upload\/export_file.*]) end - it 'removes tmp files' do + it 'removes archive path and keeps base path untouched' do + allow(shared).to receive(:archive_path).and_return(archive_path) + subject.save - expect(FileUtils).to have_received(:rm_rf).with(base_path) - expect(Dir.exist?(base_path)).to eq(false) + expect(FileUtils).not_to have_received(:rm_rf).with(base_path) + expect(FileUtils).to have_received(:rm_rf).with(archive_path) + expect(Dir.exist?(archive_path)).to eq(false) end end diff --git a/spec/lib/gitlab/import_export/wiki_repo_saver_spec.rb b/spec/lib/gitlab/import_export/wiki_repo_saver_spec.rb index 778d0859bf1..540f90e7804 100644 --- a/spec/lib/gitlab/import_export/wiki_repo_saver_spec.rb +++ b/spec/lib/gitlab/import_export/wiki_repo_saver_spec.rb @@ -8,7 +8,7 @@ RSpec.describe Gitlab::ImportExport::WikiRepoSaver do let_it_be(:project) { create(:project, :wiki_repo) } let(:export_path) { "#{Dir.tmpdir}/project_tree_saver_spec" } let(:shared) { project.import_export_shared } - let(:wiki_bundler) { described_class.new(project: project, shared: shared) } + let(:wiki_bundler) { described_class.new(exportable: project, shared: shared) } let!(:project_wiki) { ProjectWiki.new(project, user) } before do |