From ee664acb356f8123f4f6b00b73c1e1cf0866c7fb Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Thu, 20 Oct 2022 09:40:42 +0000 Subject: Add latest changes from gitlab-org/gitlab@15-5-stable-ee --- .../web_upload_strategy_spec.rb | 130 +++++++-------------- spec/lib/gitlab/import_export/all_models.yml | 11 ++ .../import_export/group/tree_restorer_spec.rb | 18 +-- .../gitlab/import_export/group/tree_saver_spec.rb | 11 +- .../import_export/project/relation_factory_spec.rb | 18 +-- .../import_export/project/tree_restorer_spec.rb | 23 ++-- .../gitlab/import_export/safe_model_attributes.yml | 6 + .../gitlab/import_export/uploads_manager_spec.rb | 26 ++++- .../gitlab/import_export/wiki_repo_saver_spec.rb | 2 +- 9 files changed, 122 insertions(+), 123 deletions(-) (limited to 'spec/lib/gitlab/import_export') diff --git a/spec/lib/gitlab/import_export/after_export_strategies/web_upload_strategy_spec.rb b/spec/lib/gitlab/import_export/after_export_strategies/web_upload_strategy_spec.rb index 42cf9c54798..297fe3ade07 100644 --- a/spec/lib/gitlab/import_export/after_export_strategies/web_upload_strategy_spec.rb +++ b/spec/lib/gitlab/import_export/after_export_strategies/web_upload_strategy_spec.rb @@ -9,8 +9,6 @@ RSpec.describe Gitlab::ImportExport::AfterExportStrategies::WebUploadStrategy do allow_next_instance_of(ProjectExportWorker) do |job| allow(job).to receive(:jid).and_return(SecureRandom.hex(8)) end - - stub_feature_flags(import_export_web_upload_stream: false) stub_uploads_object_storage(FileUploader, enabled: false) end @@ -109,108 +107,68 @@ RSpec.describe Gitlab::ImportExport::AfterExportStrategies::WebUploadStrategy do end context 'when object store is enabled' do + let(:object_store_url) { 'http://object-storage/project.tar.gz' } + before do - object_store_url = 'http://object-storage/project.tar.gz' stub_uploads_object_storage(FileUploader) - stub_request(:get, object_store_url) - stub_request(:post, example_url) + allow(import_export_upload.export_file).to receive(:url).and_return(object_store_url) allow(import_export_upload.export_file).to receive(:file_storage?).and_return(false) end - it 'reads file using Gitlab::HttpIO and uploads to external url' do - expect_next_instance_of(Gitlab::HttpIO) do |http_io| - expect(http_io).to receive(:read).and_call_original + it 'uploads file as a remote stream' do + arguments = { + download_url: object_store_url, + upload_url: example_url, + options: { + upload_method: :post, + upload_content_type: 'application/gzip' + } + } + + expect_next_instance_of(Gitlab::ImportExport::RemoteStreamUpload, arguments) do |remote_stream_upload| + expect(remote_stream_upload).to receive(:execute) end - expect(Gitlab::ImportExport::RemoteStreamUpload).not_to receive(:new) + expect(Gitlab::HttpIO).not_to receive(:new) strategy.execute(user, project) - - expect(a_request(:post, example_url)).to have_been_made end - end - - context 'when `import_export_web_upload_stream` feature is enabled' do - before do - stub_feature_flags(import_export_web_upload_stream: true) - end - - context 'when remote object store is disabled' do - it 'reads file from disk and uploads to external url' do - stub_request(:post, example_url).to_return(status: 200) - expect(Gitlab::ImportExport::RemoteStreamUpload).not_to receive(:new) - expect(Gitlab::HttpIO).not_to receive(:new) - - strategy.execute(user, project) - - expect(a_request(:post, example_url)).to have_been_made - end - end - - context 'when object store is enabled' do - let(:object_store_url) { 'http://object-storage/project.tar.gz' } + context 'when upload as remote stream raises an exception' do before do - stub_uploads_object_storage(FileUploader) - - allow(import_export_upload.export_file).to receive(:url).and_return(object_store_url) - allow(import_export_upload.export_file).to receive(:file_storage?).and_return(false) + allow_next_instance_of(Gitlab::ImportExport::RemoteStreamUpload) do |remote_stream_upload| + allow(remote_stream_upload).to receive(:execute).and_raise( + Gitlab::ImportExport::RemoteStreamUpload::StreamError.new('Exception error message', 'Response body') + ) + end end - it 'uploads file as a remote stream' do - arguments = { - download_url: object_store_url, - upload_url: example_url, - options: { - upload_method: :post, - upload_content_type: 'application/gzip' - } - } - - expect_next_instance_of(Gitlab::ImportExport::RemoteStreamUpload, arguments) do |remote_stream_upload| - expect(remote_stream_upload).to receive(:execute) + it 'logs the exception and stores the error message' do + expect_next_instance_of(Gitlab::Export::Logger) do |logger| + expect(logger).to receive(:error).ordered.with( + { + project_id: project.id, + project_name: project.name, + message: 'Exception error message', + response_body: 'Response body' + } + ) + + expect(logger).to receive(:error).ordered.with( + { + project_id: project.id, + project_name: project.name, + message: 'After export strategy failed', + 'exception.class' => 'Gitlab::ImportExport::RemoteStreamUpload::StreamError', + 'exception.message' => 'Exception error message', + 'exception.backtrace' => anything + } + ) end - expect(Gitlab::HttpIO).not_to receive(:new) strategy.execute(user, project) - end - context 'when upload as remote stream raises an exception' do - before do - allow_next_instance_of(Gitlab::ImportExport::RemoteStreamUpload) do |remote_stream_upload| - allow(remote_stream_upload).to receive(:execute).and_raise( - Gitlab::ImportExport::RemoteStreamUpload::StreamError.new('Exception error message', 'Response body') - ) - end - end - - it 'logs the exception and stores the error message' do - expect_next_instance_of(Gitlab::Export::Logger) do |logger| - expect(logger).to receive(:error).ordered.with( - { - project_id: project.id, - project_name: project.name, - message: 'Exception error message', - response_body: 'Response body' - } - ) - - expect(logger).to receive(:error).ordered.with( - { - project_id: project.id, - project_name: project.name, - message: 'After export strategy failed', - 'exception.class' => 'Gitlab::ImportExport::RemoteStreamUpload::StreamError', - 'exception.message' => 'Exception error message', - 'exception.backtrace' => anything - } - ) - end - - strategy.execute(user, project) - - expect(project.import_export_shared.errors.first).to eq('Exception error message') - end + expect(project.import_export_shared.errors.first).to eq('Exception error message') end end end diff --git a/spec/lib/gitlab/import_export/all_models.yml b/spec/lib/gitlab/import_export/all_models.yml index e270ca9ec6a..ccc4f1f7149 100644 --- a/spec/lib/gitlab/import_export/all_models.yml +++ b/spec/lib/gitlab/import_export/all_models.yml @@ -61,6 +61,8 @@ issues: - requirement - incident_management_issuable_escalation_status - incident_management_timeline_events +- incident_management_timeline_event_tags +- incident_management_timeline_event_links - pending_escalations - customer_relations_contacts - issue_customer_relations_contacts @@ -95,6 +97,7 @@ label_links: label: - subscriptions - project +- parent_container - lists - label_links - issues @@ -296,6 +299,10 @@ ci_pipelines: - package_build_infos - package_file_build_infos - build_trace_chunks +- pipeline_metadata +pipeline_metadata: +- project +- pipeline ci_refs: - project - ci_pipelines @@ -541,6 +548,7 @@ project: - path_locks - approver_groups - repository_state +- wiki_repository_state - source_pipelines - sourced_pipelines - prometheus_metrics @@ -567,6 +575,7 @@ project: - project_registry - packages - package_files +- repository_files - packages_cleanup_policy - alerting_setting - project_setting @@ -615,6 +624,7 @@ project: - incident_management_oncall_rotations - incident_management_escalation_policies - incident_management_issuable_escalation_statuses +- incident_management_timeline_event_tags - debian_distributions - merge_request_metrics - security_orchestration_policy_configuration @@ -632,6 +642,7 @@ project: - vulnerability_reads - build_artifacts_size_refresh - project_callouts +- pipeline_metadata award_emoji: - awardable - user 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 89ae869ae86..1444897e136 100644 --- a/spec/lib/gitlab/import_export/group/tree_restorer_spec.rb +++ b/spec/lib/gitlab/import_export/group/tree_restorer_spec.rb @@ -116,15 +116,15 @@ RSpec.describe Gitlab::ImportExport::Group::TreeRestorer do shared_examples 'excluded attributes' do excluded_attributes = %w[ - id - parent_id - owner_id - created_at - updated_at - runners_token - runners_token_encrypted - saml_discovery_token - ] + id + parent_id + owner_id + created_at + updated_at + runners_token + runners_token_encrypted + saml_discovery_token + ] before do group.add_owner(importer_user) 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 de4d193a21c..85d07e3fe63 100644 --- a/spec/lib/gitlab/import_export/group/tree_saver_spec.rb +++ b/spec/lib/gitlab/import_export/group/tree_saver_spec.rb @@ -51,11 +51,12 @@ RSpec.describe Gitlab::ImportExport::Group::TreeSaver do .map { |line| Integer(line) } expect(groups_catalog.size).to eq(3) - expect(groups_catalog).to eq([ - group.id, - group.descendants.first.id, - group.descendants.first.descendants.first.id - ]) + expect(groups_catalog).to eq( + [ + group.id, + group.descendants.first.id, + group.descendants.first.descendants.first.id + ]) end it 'has a file per group' do diff --git a/spec/lib/gitlab/import_export/project/relation_factory_spec.rb b/spec/lib/gitlab/import_export/project/relation_factory_spec.rb index 52b33e22089..936c63fd6cd 100644 --- a/spec/lib/gitlab/import_export/project/relation_factory_spec.rb +++ b/spec/lib/gitlab/import_export/project/relation_factory_spec.rb @@ -41,7 +41,7 @@ RSpec.describe Gitlab::ImportExport::Project::RelationFactory, :use_clean_rails_ context 'hook object' do let(:relation_sym) { :hooks } let(:id) { 999 } - let(:service_id) { 99 } + let(:integration_id) { 99 } let(:original_project_id) { 8 } let(:token) { 'secret' } @@ -52,7 +52,7 @@ RSpec.describe Gitlab::ImportExport::Project::RelationFactory, :use_clean_rails_ 'project_id' => original_project_id, 'created_at' => '2016-08-12T09:41:03.462Z', 'updated_at' => '2016-08-12T09:41:03.462Z', - 'service_id' => service_id, + 'integration_id' => integration_id, 'push_events' => true, 'issues_events' => false, 'confidential_issues_events' => false, @@ -71,8 +71,8 @@ RSpec.describe Gitlab::ImportExport::Project::RelationFactory, :use_clean_rails_ expect(created_object.id).not_to eq(id) end - it 'does not have the original service_id' do - expect(created_object.service_id).not_to eq(service_id) + it 'does not have the original integration_id' do + expect(created_object.integration_id).not_to eq(integration_id) end it 'does not have the original project_id' do @@ -88,10 +88,10 @@ RSpec.describe Gitlab::ImportExport::Project::RelationFactory, :use_clean_rails_ end context 'original service exists' do - let(:service_id) { create(:integration, project: project).id } + let(:integration_id) { create(:integration, project: project).id } - it 'does not have the original service_id' do - expect(created_object.service_id).not_to eq(service_id) + it 'does not have the original integration_id' do + expect(created_object.integration_id).not_to eq(integration_id) end end @@ -302,7 +302,7 @@ RSpec.describe Gitlab::ImportExport::Project::RelationFactory, :use_clean_rails_ let(:relation_sym) { :hazardous_foo_model } let(:relation_hash) do { - 'service_id' => 99, + 'integration_id' => 99, 'moved_to_id' => 99, 'namespace_id' => 99, 'ci_id' => 99, @@ -317,7 +317,7 @@ RSpec.describe Gitlab::ImportExport::Project::RelationFactory, :use_clean_rails_ before do stub_const('HazardousFooModel', Class.new(FooModel)) HazardousFooModel.class_eval do - attr_accessor :service_id, :moved_to_id, :namespace_id, :ci_id, :random_project_id, :random_id, :milestone_id, :project_id + attr_accessor :integration_id, :moved_to_id, :namespace_id, :ci_id, :random_project_id, :random_id, :milestone_id, :project_id end allow(HazardousFooModel).to receive(:reflect_on_association).and_return(nil) 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 299e107c881..fae94a3b544 100644 --- a/spec/lib/gitlab/import_export/project/tree_restorer_spec.rb +++ b/spec/lib/gitlab/import_export/project/tree_restorer_spec.rb @@ -140,13 +140,13 @@ RSpec.describe Gitlab::ImportExport::Project::TreeRestorer do it 'restores pipelines based on ascending id order' do expected_ordered_shas = %w[ - 2ea1f3dec713d940208fb5ce4a38765ecb5d3f73 - ce84140e8b878ce6e7c4d298c7202ff38170e3ac - 048721d90c449b244b7b4c53a9186b04330174ec - sha-notes - 5f923865dde3436854e9ceb9cdb7815618d4e849 - d2d430676773caa88cdaf7c55944073b2fd5561a - 2ea1f3dec713d940208fb5ce4a38765ecb5d3f73 + 2ea1f3dec713d940208fb5ce4a38765ecb5d3f73 + ce84140e8b878ce6e7c4d298c7202ff38170e3ac + 048721d90c449b244b7b4c53a9186b04330174ec + sha-notes + 5f923865dde3436854e9ceb9cdb7815618d4e849 + d2d430676773caa88cdaf7c55944073b2fd5561a + 2ea1f3dec713d940208fb5ce4a38765ecb5d3f73 ] project = Project.find_by_path('project') @@ -156,6 +156,15 @@ RSpec.describe Gitlab::ImportExport::Project::TreeRestorer do end end + it 'restores pipeline metadata' 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.pipeline_id).to eq(pipeline.id) + expect(pipeline_metadata.project_id).to eq(pipeline.project_id) + end + it 'preserves updated_at on issues' do issue = Issue.find_by(description: 'Aliquam enim illo et possimus.') diff --git a/spec/lib/gitlab/import_export/safe_model_attributes.yml b/spec/lib/gitlab/import_export/safe_model_attributes.yml index e591cbd05a0..23eb93a1bce 100644 --- a/spec/lib/gitlab/import_export/safe_model_attributes.yml +++ b/spec/lib/gitlab/import_export/safe_model_attributes.yml @@ -332,6 +332,11 @@ Ci::Pipeline: - iid - merge_request_id - external_pull_request_id +Ci::PipelineMetadata: +- id +- project_id +- pipeline_id +- title Ci::Stage: - id - name @@ -697,6 +702,7 @@ ProjectCiCdSetting: - runner_token_expiration_interval ProjectSetting: - allow_merge_on_skipped_pipeline +- only_allow_merge_if_all_status_checks_passed - has_confluence - has_shimo - has_vulnerabilities diff --git a/spec/lib/gitlab/import_export/uploads_manager_spec.rb b/spec/lib/gitlab/import_export/uploads_manager_spec.rb index 0cfe3a69a09..5fc3a70169a 100644 --- a/spec/lib/gitlab/import_export/uploads_manager_spec.rb +++ b/spec/lib/gitlab/import_export/uploads_manager_spec.rb @@ -78,16 +78,30 @@ RSpec.describe Gitlab::ImportExport::UploadsManager do context 'when upload is in object storage' do before do stub_uploads_object_storage(FileUploader) - allow(manager).to receive(:download_or_copy_upload).and_raise(Errno::ENAMETOOLONG) end - it 'ignores problematic upload and logs exception' do - expect(Gitlab::ErrorTracking).to receive(:log_exception).with(instance_of(Errno::ENAMETOOLONG), project_id: project.id) + shared_examples 'export with invalid upload' do + it 'ignores problematic upload and logs exception' do + allow(manager).to receive(:download_or_copy_upload).and_raise(exception) + expect(Gitlab::ErrorTracking).to receive(:log_exception).with(instance_of(exception), project_id: project.id) - manager.save # rubocop:disable Rails/SaveBang + manager.save # rubocop:disable Rails/SaveBang - expect(shared.errors).to be_empty - expect(File).not_to exist(exported_file_path) + expect(shared.errors).to be_empty + expect(File).not_to exist(exported_file_path) + end + end + + context 'when filename is too long' do + let(:exception) { Errno::ENAMETOOLONG } + + include_examples 'export with invalid upload' + end + + context 'when network exception occurs' do + let(:exception) { Net::OpenTimeout } + + include_examples 'export with invalid upload' end 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 c936d2bc27d..0e6173b611f 100644 --- a/spec/lib/gitlab/import_export/wiki_repo_saver_spec.rb +++ b/spec/lib/gitlab/import_export/wiki_repo_saver_spec.rb @@ -17,7 +17,7 @@ RSpec.describe Gitlab::ImportExport::WikiRepoSaver do allow_next_instance_of(Gitlab::ImportExport) do |instance| allow(instance).to receive(:storage_path).and_return(export_path) end - project_wiki.wiki + project_wiki.create_wiki_repository project_wiki.create_page("index", "test content") end -- cgit v1.2.3