diff options
Diffstat (limited to 'spec/lib/gitlab/import_export')
14 files changed, 155 insertions, 30 deletions
diff --git a/spec/lib/gitlab/import_export/all_models.yml b/spec/lib/gitlab/import_export/all_models.yml index ccc4f1f7149..e9dde1c6180 100644 --- a/spec/lib/gitlab/import_export/all_models.yml +++ b/spec/lib/gitlab/import_export/all_models.yml @@ -52,6 +52,7 @@ issues: - user_mentions - system_note_metadata - alert_management_alert +- alert_management_alerts - status_page_published_incident - namespace - note_authors @@ -361,10 +362,12 @@ hooks: - web_hook_logs protected_branches: - project +- group - merge_access_levels - push_access_levels - unprotect_access_levels - approval_project_rules +- external_status_checks - required_code_owners_sections protected_tags: - project @@ -538,6 +541,7 @@ project: - jenkins_integration - index_status - feature_usage +- regular_or_any_approver_approval_rules - approval_rules - approval_merge_request_rules - approval_merge_request_rule_sources @@ -548,6 +552,7 @@ project: - path_locks - approver_groups - repository_state +- wiki_repository - wiki_repository_state - source_pipelines - sourced_pipelines @@ -643,6 +648,7 @@ project: - build_artifacts_size_refresh - project_callouts - pipeline_metadata +- disable_download_button award_emoji: - awardable - user 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 9af72cc0dea..a6cb74c3c9f 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 @@ -112,7 +112,7 @@ RSpec.describe Gitlab::ImportExport::DecompressedArchiveSizeValidator do context 'when archive path is not a string' do let(:filepath) { 123 } - let(:error_message) { 'Archive path is not a string' } + let(:error_message) { 'Invalid path' } it 'returns false' do expect(subject.valid?).to eq(false) 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 346f653acd4..5ef9eb78d3b 100644 --- a/spec/lib/gitlab/import_export/design_repo_restorer_spec.rb +++ b/spec/lib/gitlab/import_export/design_repo_restorer_spec.rb @@ -3,8 +3,6 @@ require 'spec_helper' RSpec.describe Gitlab::ImportExport::DesignRepoRestorer do - include GitHelpers - describe 'bundle a design Git repo' do let(:user) { create(:user) } let!(:project_with_design_repo) { create(:project, :design_repo) } @@ -29,10 +27,8 @@ RSpec.describe Gitlab::ImportExport::DesignRepoRestorer do after do FileUtils.rm_rf(export_path) - Gitlab::GitalyClient::StorageSettings.allow_disk_access do - FileUtils.rm_rf(project_with_design_repo.design_repository.path_to_repo) - FileUtils.rm_rf(project.design_repository.path_to_repo) - end + project_with_design_repo.design_repository.remove + project.design_repository.remove end it 'restores the repo successfully' do diff --git a/spec/lib/gitlab/import_export/fork_spec.rb b/spec/lib/gitlab/import_export/fork_spec.rb index 25c82588c13..9d766eb3af1 100644 --- a/spec/lib/gitlab/import_export/fork_spec.rb +++ b/spec/lib/gitlab/import_export/fork_spec.rb @@ -47,10 +47,8 @@ RSpec.describe 'forked project import' do after do FileUtils.rm_rf(export_path) - Gitlab::GitalyClient::StorageSettings.allow_disk_access do - FileUtils.rm_rf(project_with_repo.repository.path_to_repo) - FileUtils.rm_rf(project.repository.path_to_repo) - end + project_with_repo.repository.remove + project.repository.remove end it 'can access the MR', :sidekiq_might_not_need_inline do diff --git a/spec/lib/gitlab/import_export/group/tree_saver_spec.rb b/spec/lib/gitlab/import_export/group/tree_saver_spec.rb index 85d07e3fe63..79ab1913e7e 100644 --- a/spec/lib/gitlab/import_export/group/tree_saver_spec.rb +++ b/spec/lib/gitlab/import_export/group/tree_saver_spec.rb @@ -106,7 +106,7 @@ RSpec.describe Gitlab::ImportExport::Group::TreeSaver do members milestones ].each do |association| - path = exported_path_for("#{g.id}", "#{association}.ndjson") + path = exported_path_for(g.id.to_s, "#{association}.ndjson") expect(File.exist?(path)).to eq(true), "#{path} does not exist" end end diff --git a/spec/lib/gitlab/import_export/import_test_coverage_spec.rb b/spec/lib/gitlab/import_export/import_test_coverage_spec.rb index 51c0008b2b4..b1f5574fba1 100644 --- a/spec/lib/gitlab/import_export/import_test_coverage_spec.rb +++ b/spec/lib/gitlab/import_export/import_test_coverage_spec.rb @@ -96,11 +96,11 @@ RSpec.describe 'Test coverage of the Project Import' do case item when Hash item.each do |k, v| - if (v.is_a?(Array) || v.is_a?(Hash)) && v.present? - new_path = path + [k] - res << new_path - gather_relations(v, res, new_path) - end + next unless (v.is_a?(Array) || v.is_a?(Hash)) && v.present? + + new_path = path + [k] + res << new_path + gather_relations(v, res, new_path) end when Array item.each { |i| gather_relations(i, res, path) } diff --git a/spec/lib/gitlab/import_export/merge_request_parser_spec.rb b/spec/lib/gitlab/import_export/merge_request_parser_spec.rb index 550cefea805..3ca9f727033 100644 --- a/spec/lib/gitlab/import_export/merge_request_parser_spec.rb +++ b/spec/lib/gitlab/import_export/merge_request_parser_spec.rb @@ -23,9 +23,7 @@ RSpec.describe Gitlab::ImportExport::MergeRequestParser do end after do - Gitlab::GitalyClient::StorageSettings.allow_disk_access do - FileUtils.rm_rf(project.repository.path_to_repo) - end + project.repository.remove end it 'has a source branch' do diff --git a/spec/lib/gitlab/import_export/project/exported_relations_merger_spec.rb b/spec/lib/gitlab/import_export/project/exported_relations_merger_spec.rb new file mode 100644 index 00000000000..a781139acab --- /dev/null +++ b/spec/lib/gitlab/import_export/project/exported_relations_merger_spec.rb @@ -0,0 +1,75 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::ImportExport::Project::ExportedRelationsMerger do + let(:export_job) { create(:project_export_job) } + + let(:shared) { Gitlab::ImportExport::Shared.new(export_job.project) } + + before do + create(:project_relation_export_upload, + relation_export: create(:project_relation_export, relation: 'project', project_export_job: export_job), + export_file: fixture_file_upload("spec/fixtures/gitlab/import_export/project.tar.gz") + ) + + create(:project_relation_export_upload, + relation_export: create(:project_relation_export, relation: 'labels', project_export_job: export_job), + export_file: fixture_file_upload("spec/fixtures/gitlab/import_export/labels.tar.gz") + ) + + create(:project_relation_export_upload, + relation_export: create(:project_relation_export, relation: 'uploads', project_export_job: export_job), + export_file: fixture_file_upload("spec/fixtures/gitlab/import_export/uploads.tar.gz") + ) + end + + describe '#save' do + subject(:service) { described_class.new(export_job: export_job, shared: shared) } + + it 'downloads, extracts, and merges all files into export_path' do + Dir.mktmpdir do |dirpath| + allow(shared).to receive(:export_path).and_return(dirpath) + + result = service.save + + expect(result).to eq(true) + expect(Dir.glob("#{dirpath}/**/*")).to match_array( + [ + "#{dirpath}/project", + "#{dirpath}/project/project.json", + "#{dirpath}/project/labels.ndjson", + "#{dirpath}/uploads", + "#{dirpath}/uploads/70edb596c34ad7795baa6a0f0aa03d44", + "#{dirpath}/uploads/70edb596c34ad7795baa6a0f0aa03d44/file1.txt", + "#{dirpath}/uploads/c8c93c6f546b002cbce4cb8d05d0dfb8", + "#{dirpath}/uploads/c8c93c6f546b002cbce4cb8d05d0dfb8/file2.txt" + ] + ) + end + end + + context 'when exception occurs' do + before do + create(:project_relation_export, relation: 'releases', project_export_job: export_job) + create(:project_relation_export, relation: 'issues', project_export_job: export_job) + end + + it 'registers the exception messages and returns false' do + Dir.mktmpdir do |dirpath| + allow(shared).to receive(:export_path).and_return(dirpath) + + result = service.save + + expect(result).to eq(false) + expect(shared.errors).to match_array( + [ + "undefined method `export_file' for nil:NilClass", + "undefined method `export_file' for nil:NilClass" + ] + ) + end + end + end + end +end diff --git a/spec/lib/gitlab/import_export/project/relation_saver_spec.rb b/spec/lib/gitlab/import_export/project/relation_saver_spec.rb index dec51b3afd1..0467b63e918 100644 --- a/spec/lib/gitlab/import_export/project/relation_saver_spec.rb +++ b/spec/lib/gitlab/import_export/project/relation_saver_spec.rb @@ -28,14 +28,14 @@ RSpec.describe Gitlab::ImportExport::Project::RelationSaver do it 'serializes the root node as a json file in the export path' do relation_saver.save # rubocop:disable Rails/SaveBang - json = read_json(File.join(shared.export_path, 'project.json')) + json = read_json(File.join(shared.export_path, 'tree', 'project.json')) expect(json).to include({ 'description' => 'Project description' }) end it 'serializes only allowed attributes' do relation_saver.save # rubocop:disable Rails/SaveBang - json = read_json(File.join(shared.export_path, 'project.json')) + json = read_json(File.join(shared.export_path, 'tree', 'project.json')) expect(json).to include({ 'description' => 'Project description' }) expect(json.keys).not_to include('name') end @@ -54,7 +54,7 @@ RSpec.describe Gitlab::ImportExport::Project::RelationSaver do it 'serializes the child node as a ndjson file in the export path inside the project folder' do relation_saver.save # rubocop:disable Rails/SaveBang - ndjson = read_ndjson(File.join(shared.export_path, 'project', "#{relation}.ndjson")) + ndjson = read_ndjson(File.join(shared.export_path, 'tree', 'project', "#{relation}.ndjson")) expect(ndjson.first).to include({ 'title' => 'Label 1' }) expect(ndjson.second).to include({ 'title' => 'Label 2' }) end @@ -62,7 +62,7 @@ RSpec.describe Gitlab::ImportExport::Project::RelationSaver do it 'serializes only allowed attributes' do relation_saver.save # rubocop:disable Rails/SaveBang - ndjson = read_ndjson(File.join(shared.export_path, 'project', "#{relation}.ndjson")) + ndjson = read_ndjson(File.join(shared.export_path, 'tree', 'project', "#{relation}.ndjson")) expect(ndjson.first.keys).not_to include('description_html') end diff --git a/spec/lib/gitlab/import_export/project/tree_restorer_spec.rb b/spec/lib/gitlab/import_export/project/tree_restorer_spec.rb index fae94a3b544..b753746cd8c 100644 --- a/spec/lib/gitlab/import_export/project/tree_restorer_spec.rb +++ b/spec/lib/gitlab/import_export/project/tree_restorer_spec.rb @@ -160,7 +160,7 @@ RSpec.describe Gitlab::ImportExport::Project::TreeRestorer do pipeline = Ci::Pipeline.find_by_sha('sha-notes') pipeline_metadata = pipeline.pipeline_metadata - expect(pipeline_metadata.title).to eq('Build pipeline') + expect(pipeline_metadata.name).to eq('Build pipeline') expect(pipeline_metadata.pipeline_id).to eq(pipeline.id) expect(pipeline_metadata.project_id).to eq(pipeline.project_id) end diff --git a/spec/lib/gitlab/import_export/recursive_merge_folders_spec.rb b/spec/lib/gitlab/import_export/recursive_merge_folders_spec.rb new file mode 100644 index 00000000000..6e5be0b2829 --- /dev/null +++ b/spec/lib/gitlab/import_export/recursive_merge_folders_spec.rb @@ -0,0 +1,54 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::ImportExport::RecursiveMergeFolders do + describe '.merge' do + it 'merge folder and ignore symlinks' do + Dir.mktmpdir do |tmpdir| + source = "#{tmpdir}/source" + FileUtils.mkdir_p("#{source}/folder/folder") + FileUtils.touch("#{source}/file1.txt") + FileUtils.touch("#{source}/folder/file2.txt") + FileUtils.touch("#{source}/folder/folder/file3.txt") + FileUtils.ln_s("#{source}/file1.txt", "#{source}/symlink-file1.txt") + FileUtils.ln_s("#{source}/folder", "#{source}/symlink-folder") + + target = "#{tmpdir}/target" + FileUtils.mkdir_p("#{target}/folder/folder") + FileUtils.mkdir_p("#{target}/folderA") + FileUtils.touch("#{target}/fileA.txt") + + described_class.merge(source, target) + + expect(Dir.children("#{tmpdir}/target")).to match_array(%w[folder file1.txt folderA fileA.txt]) + expect(Dir.children("#{tmpdir}/target/folder")).to match_array(%w[folder file2.txt]) + expect(Dir.children("#{tmpdir}/target/folder/folder")).to match_array(%w[file3.txt]) + end + end + + it 'raises an error for invalid source path' do + Dir.mktmpdir do |tmpdir| + expect do + described_class.merge("#{tmpdir}/../", tmpdir) + end.to raise_error(Gitlab::Utils::PathTraversalAttackError) + end + end + + it 'raises an error for source path outside temp dir' do + Dir.mktmpdir do |tmpdir| + expect do + described_class.merge('/', tmpdir ) + end.to raise_error(StandardError, 'path / is not allowed') + end + end + + it 'raises an error for invalid target path' do + Dir.mktmpdir do |tmpdir| + expect do + described_class.merge(tmpdir, "#{tmpdir}/../") + end.to raise_error(Gitlab::Utils::PathTraversalAttackError) + end + end + end +end diff --git a/spec/lib/gitlab/import_export/repo_restorer_spec.rb b/spec/lib/gitlab/import_export/repo_restorer_spec.rb index c0215ff5843..727ca4f630b 100644 --- a/spec/lib/gitlab/import_export/repo_restorer_spec.rb +++ b/spec/lib/gitlab/import_export/repo_restorer_spec.rb @@ -3,8 +3,6 @@ require 'spec_helper' RSpec.describe Gitlab::ImportExport::RepoRestorer do - include GitHelpers - let_it_be(:project_with_repo) do create(:project, :repository, :wiki_repo, name: 'test-repo-restorer', path: 'test-repo-restorer').tap do |p| p.wiki.create_page('page', 'foobar', :markdown, 'created page') diff --git a/spec/lib/gitlab/import_export/safe_model_attributes.yml b/spec/lib/gitlab/import_export/safe_model_attributes.yml index 23eb93a1bce..75d980cd5f4 100644 --- a/spec/lib/gitlab/import_export/safe_model_attributes.yml +++ b/spec/lib/gitlab/import_export/safe_model_attributes.yml @@ -336,7 +336,7 @@ Ci::PipelineMetadata: - id - project_id - pipeline_id -- title +- name Ci::Stage: - id - name @@ -568,6 +568,7 @@ Project: - suggestion_commit_message - merge_commit_template - squash_commit_template +- issue_branch_template Author: - name ProjectFeature: @@ -592,6 +593,7 @@ ProjectFeature: - feature_flags_access_level - releases_access_level - monitor_access_level +- infrastructure_access_level - created_at - updated_at ProtectedBranch::MergeAccessLevel: diff --git a/spec/lib/gitlab/import_export/snippets_repo_restorer_spec.rb b/spec/lib/gitlab/import_export/snippets_repo_restorer_spec.rb index e529d36fd11..ebb0d62afa0 100644 --- a/spec/lib/gitlab/import_export/snippets_repo_restorer_spec.rb +++ b/spec/lib/gitlab/import_export/snippets_repo_restorer_spec.rb @@ -3,8 +3,6 @@ require 'spec_helper' RSpec.describe Gitlab::ImportExport::SnippetsRepoRestorer do - include GitHelpers - describe 'bundle a snippet Git repo' do let_it_be(:user) { create(:user) } let_it_be(:project) { create(:project, namespace: user.namespace) } |