Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-03-18 23:02:30 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-03-18 23:02:30 +0300
commit41fe97390ceddf945f3d967b8fdb3de4c66b7dea (patch)
tree9c8d89a8624828992f06d892cd2f43818ff5dcc8 /spec/lib/gitlab/import_export
parent0804d2dc31052fb45a1efecedc8e06ce9bc32862 (diff)
Add latest changes from gitlab-org/gitlab@14-9-stable-eev14.9.0-rc42
Diffstat (limited to 'spec/lib/gitlab/import_export')
-rw-r--r--spec/lib/gitlab/import_export/all_models.yml8
-rw-r--r--spec/lib/gitlab/import_export/base/relation_object_saver_spec.rb132
-rw-r--r--spec/lib/gitlab/import_export/command_line_util_spec.rb153
-rw-r--r--spec/lib/gitlab/import_export/file_importer_spec.rb25
-rw-r--r--spec/lib/gitlab/import_export/group/object_builder_spec.rb12
-rw-r--r--spec/lib/gitlab/import_export/group/tree_restorer_spec.rb282
-rw-r--r--spec/lib/gitlab/import_export/json/streaming_serializer_spec.rb22
-rw-r--r--spec/lib/gitlab/import_export/project/relation_factory_spec.rb16
-rw-r--r--spec/lib/gitlab/import_export/project/tree_restorer_spec.rb32
-rw-r--r--spec/lib/gitlab/import_export/safe_model_attributes.yml1
10 files changed, 514 insertions, 169 deletions
diff --git a/spec/lib/gitlab/import_export/all_models.yml b/spec/lib/gitlab/import_export/all_models.yml
index ce13f405459..29a19e4cafd 100644
--- a/spec/lib/gitlab/import_export/all_models.yml
+++ b/spec/lib/gitlab/import_export/all_models.yml
@@ -34,6 +34,7 @@ issues:
- issuable_severity
- issuable_sla
- issue_assignees
+- search_data
- closed_by
- epic_issue
- epic
@@ -54,6 +55,7 @@ issues:
- status_page_published_incident
- namespace
- note_authors
+- user_note_authors
- issue_email_participants
- test_reports
- requirement
@@ -199,6 +201,7 @@ merge_requests:
- user_mentions
- system_note_metadata
- note_authors
+- user_note_authors
- cleanup_schedule
- compliance_violations
external_pull_requests:
@@ -392,6 +395,7 @@ project:
- mattermost_slash_commands_integration
- shimo_integration
- slack_slash_commands_integration
+- harbor_integration
- irker_integration
- packagist_integration
- pivotaltracker_integration
@@ -607,6 +611,7 @@ project:
- sync_events
- secure_files
- security_trainings
+- vulnerability_reads
award_emoji:
- awardable
- user
@@ -627,6 +632,8 @@ issuable_severity:
issue_assignees:
- issue
- assignee
+search_data:
+- issue
merge_request_assignees:
- merge_request
- assignee
@@ -771,6 +778,7 @@ epic:
- resource_state_events
- user_mentions
- note_authors
+- user_note_authors
- boards_epic_user_preferences
- epic_board_positions
epic_issue:
diff --git a/spec/lib/gitlab/import_export/base/relation_object_saver_spec.rb b/spec/lib/gitlab/import_export/base/relation_object_saver_spec.rb
new file mode 100644
index 00000000000..7c84b9604a6
--- /dev/null
+++ b/spec/lib/gitlab/import_export/base/relation_object_saver_spec.rb
@@ -0,0 +1,132 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::ImportExport::Base::RelationObjectSaver do
+ let(:project) { create(:project) }
+ let(:relation_object) { build(:issue, project: project) }
+ let(:relation_definition) { {} }
+ let(:importable) { project }
+ let(:relation_key) { 'issues' }
+
+ subject(:saver) do
+ described_class.new(
+ relation_object: relation_object,
+ relation_key: relation_key,
+ relation_definition: relation_definition,
+ importable: importable
+ )
+ end
+
+ describe '#save' do
+ before do
+ expect(relation_object).to receive(:save!).and_call_original
+ end
+
+ it 'saves relation object' do
+ expect { saver.execute }.to change(project.issues, :count).by(1)
+ end
+
+ context 'when subrelation is present' do
+ let(:notes) { build_list(:note, 6, project: project, importing: true) }
+ let(:relation_object) { build(:issue, project: project, notes: notes) }
+ let(:relation_definition) { { 'notes' => {} } }
+
+ it 'saves relation object with subrelations' do
+ expect(relation_object.notes).to receive(:<<).and_call_original
+
+ saver.execute
+
+ issue = project.issues.last
+ expect(issue.notes.count).to eq(6)
+ end
+ end
+
+ context 'when subrelation is not a collection' do
+ let(:sentry_issue) { build(:sentry_issue, importing: true) }
+ let(:relation_object) { build(:issue, project: project, sentry_issue: sentry_issue) }
+ let(:relation_definition) { { 'sentry_issue' => {} } }
+
+ it 'saves subrelation as part of the relation object itself' do
+ expect(relation_object.notes).not_to receive(:<<)
+
+ saver.execute
+
+ issue = project.issues.last
+ expect(issue.sentry_issue.persisted?).to eq(true)
+ end
+ end
+
+ context 'when subrelation collection count is small' do
+ let(:notes) { build_list(:note, 2, project: project, importing: true) }
+ let(:relation_object) { build(:issue, project: project, notes: notes) }
+ let(:relation_definition) { { 'notes' => {} } }
+
+ it 'saves subrelation as part of the relation object itself' do
+ expect(relation_object.notes).not_to receive(:<<)
+
+ saver.execute
+
+ issue = project.issues.last
+ expect(issue.notes.count).to eq(2)
+ end
+ end
+
+ context 'when some subrelations are invalid' do
+ let(:notes) { build_list(:note, 5, project: project, importing: true) }
+ let(:invalid_note) { build(:note) }
+ let(:relation_object) { build(:issue, project: project, notes: notes + [invalid_note]) }
+ let(:relation_definition) { { 'notes' => {} } }
+
+ it 'saves valid subrelations and logs invalid subrelation' do
+ expect(relation_object.notes).to receive(:<<).and_call_original
+ expect(Gitlab::Import::Logger)
+ .to receive(:info)
+ .with(
+ message: '[Project/Group Import] Invalid subrelation',
+ project_id: project.id,
+ relation_key: 'issues',
+ error_messages: "Noteable can't be blank and Project does not match noteable project"
+ )
+
+ saver.execute
+
+ issue = project.issues.last
+ import_failure = project.import_failures.last
+
+ expect(issue.notes.count).to eq(5)
+ expect(import_failure.source).to eq('RelationObjectSaver#save!')
+ expect(import_failure.exception_message).to eq("Noteable can't be blank and Project does not match noteable project")
+ end
+
+ context 'when importable is group' do
+ let(:relation_key) { 'labels' }
+ let(:relation_definition) { { 'priorities' => {} } }
+ let(:importable) { create(:group) }
+ let(:valid_priorities) { build_list(:label_priority, 5, importing: true) }
+ let(:invalid_priority) { build(:label_priority, priority: -1) }
+ let(:relation_object) { build(:group_label, group: importable, title: 'test', priorities: valid_priorities + [invalid_priority]) }
+
+ it 'logs invalid subrelation for a group' do
+ expect(Gitlab::Import::Logger)
+ .to receive(:info)
+ .with(
+ message: '[Project/Group Import] Invalid subrelation',
+ group_id: importable.id,
+ relation_key: 'labels',
+ error_messages: 'Priority must be greater than or equal to 0'
+ )
+
+ saver.execute
+
+ label = importable.labels.last
+ import_failure = importable.import_failures.last
+
+ expect(label.priorities.count).to eq(5)
+ expect(import_failure.source).to eq('RelationObjectSaver#save!')
+ expect(import_failure.exception_message).to eq('Priority must be greater than or equal to 0')
+ end
+ end
+ end
+ end
+end
diff --git a/spec/lib/gitlab/import_export/command_line_util_spec.rb b/spec/lib/gitlab/import_export/command_line_util_spec.rb
index 738a76d3360..f5913da08ba 100644
--- a/spec/lib/gitlab/import_export/command_line_util_spec.rb
+++ b/spec/lib/gitlab/import_export/command_line_util_spec.rb
@@ -17,6 +17,9 @@ RSpec.describe Gitlab::ImportExport::CommandLineUtil do
def initialize
@shared = Gitlab::ImportExport::Shared.new(nil)
end
+
+ # Make the included methods public for testing
+ public :download_or_copy_upload, :download
end.new
end
@@ -38,6 +41,156 @@ RSpec.describe Gitlab::ImportExport::CommandLineUtil do
expect(file_permissions("#{path}/uploads")).to eq(0755) # originally 555
end
+ describe '#download_or_copy_upload' do
+ let(:upload) { instance_double(Upload, local?: local) }
+ let(:uploader) { instance_double(ImportExportUploader, path: :path, url: :url, upload: upload) }
+ let(:upload_path) { '/some/path' }
+
+ context 'when the upload is local' do
+ let(:local) { true }
+
+ it 'copies the file' do
+ expect(subject).to receive(:copy_files).with(:path, upload_path)
+
+ subject.download_or_copy_upload(uploader, upload_path)
+ end
+ end
+
+ context 'when the upload is remote' do
+ let(:local) { false }
+
+ it 'downloads the file' do
+ expect(subject).to receive(:download).with(:url, upload_path, size_limit: nil)
+
+ subject.download_or_copy_upload(uploader, upload_path)
+ end
+ end
+ end
+
+ describe '#download' do
+ let(:content) { File.open('spec/fixtures/rails_sample.tif') }
+
+ context 'a non-localhost uri' do
+ before do
+ stub_request(:get, url)
+ .to_return(
+ status: status,
+ body: content
+ )
+ end
+
+ let(:url) { 'https://gitlab.com/file' }
+
+ context 'with ok status code' do
+ let(:status) { HTTP::Status::OK }
+
+ it 'gets the contents' do
+ Tempfile.create('test') do |file|
+ subject.download(url, file.path)
+ expect(file.read).to eq(File.open('spec/fixtures/rails_sample.tif').read)
+ end
+ end
+
+ it 'streams the contents via Gitlab::HTTP' do
+ expect(Gitlab::HTTP).to receive(:get).with(url, hash_including(stream_body: true))
+
+ Tempfile.create('test') do |file|
+ subject.download(url, file.path)
+ end
+ end
+
+ it 'does not get the content over the size_limit' do
+ Tempfile.create('test') do |file|
+ subject.download(url, file.path, size_limit: 300.kilobytes)
+ expect(file.read).to eq('')
+ end
+ end
+
+ it 'gets the content within the size_limit' do
+ Tempfile.create('test') do |file|
+ subject.download(url, file.path, size_limit: 400.kilobytes)
+ expect(file.read).to eq(File.open('spec/fixtures/rails_sample.tif').read)
+ end
+ end
+ end
+
+ %w[MOVED_PERMANENTLY FOUND TEMPORARY_REDIRECT].each do |code|
+ context "with a redirect status code #{code}" do
+ let(:status) { HTTP::Status.const_get(code, false) }
+
+ it 'logs the redirect' do
+ expect(Gitlab::Import::Logger).to receive(:warn)
+
+ Tempfile.create('test') do |file|
+ subject.download(url, file.path)
+ end
+ end
+ end
+ end
+
+ %w[ACCEPTED UNAUTHORIZED BAD_REQUEST].each do |code|
+ context "with an invalid status code #{code}" do
+ let(:status) { HTTP::Status.const_get(code, false) }
+
+ it 'throws an error' do
+ Tempfile.create('test') do |file|
+ expect { subject.download(url, file.path) }.to raise_error(Gitlab::ImportExport::Error)
+ end
+ end
+ end
+ end
+ end
+
+ context 'a localhost uri' do
+ include StubRequests
+
+ let(:status) { HTTP::Status::OK }
+ let(:url) { "#{host}/foo/bar" }
+ let(:host) { 'http://localhost:8081' }
+
+ before do
+ # Note: the hostname gets changed to an ip address due to dns_rebind_protection
+ stub_dns(url, ip_address: '127.0.0.1')
+ stub_request(:get, 'http://127.0.0.1:8081/foo/bar')
+ .to_return(
+ status: status,
+ body: content
+ )
+ end
+
+ it 'throws a blocked url error' do
+ Tempfile.create('test') do |file|
+ expect { subject.download(url, file.path) }.to raise_error((Gitlab::HTTP::BlockedUrlError))
+ end
+ end
+
+ context 'for object_storage uri' do
+ let(:enabled_object_storage_setting) do
+ {
+ 'object_store' =>
+ {
+ 'enabled' => true,
+ 'connection' => {
+ 'endpoint' => host
+ }
+ }
+ }
+ end
+
+ before do
+ allow(Settings).to receive(:external_diffs).and_return(enabled_object_storage_setting)
+ end
+
+ it 'gets the content' do
+ Tempfile.create('test') do |file|
+ subject.download(url, file.path)
+ expect(file.read).to eq(File.open('spec/fixtures/rails_sample.tif').read)
+ end
+ end
+ end
+ end
+ end
+
describe '#gzip' do
it 'compresses specified file' do
tempfile = Tempfile.new('test', path)
diff --git a/spec/lib/gitlab/import_export/file_importer_spec.rb b/spec/lib/gitlab/import_export/file_importer_spec.rb
index ed4436b7257..7b27f7183b0 100644
--- a/spec/lib/gitlab/import_export/file_importer_spec.rb
+++ b/spec/lib/gitlab/import_export/file_importer_spec.rb
@@ -72,6 +72,25 @@ RSpec.describe Gitlab::ImportExport::FileImporter do
expect(shared.export_path).to include('test/abcd')
end
+ context 'when the import file is not remote' do
+ include AfterNextHelpers
+
+ it 'downloads the file from a remote object storage' do
+ import_export_upload = build(:import_export_upload)
+ project = build( :project, import_export_upload: import_export_upload)
+
+ expect_next(described_class)
+ .to receive(:download_or_copy_upload)
+ .with(
+ import_export_upload.import_file,
+ kind_of(String),
+ size_limit: ::Import::GitlabProjects::RemoteFileValidator::FILE_SIZE_LIMIT
+ )
+
+ described_class.import(importable: project, archive_file: nil, shared: shared)
+ end
+ end
+
context 'when the import file is remote' do
include AfterNextHelpers
@@ -82,7 +101,11 @@ RSpec.describe Gitlab::ImportExport::FileImporter do
expect_next(described_class)
.to receive(:download)
- .with(file_url, kind_of(String))
+ .with(
+ file_url,
+ kind_of(String),
+ size_limit: ::Import::GitlabProjects::RemoteFileValidator::FILE_SIZE_LIMIT
+ )
described_class.import(importable: project, archive_file: nil, shared: shared)
end
diff --git a/spec/lib/gitlab/import_export/group/object_builder_spec.rb b/spec/lib/gitlab/import_export/group/object_builder_spec.rb
index 028bd5463a1..09f40199b31 100644
--- a/spec/lib/gitlab/import_export/group/object_builder_spec.rb
+++ b/spec/lib/gitlab/import_export/group/object_builder_spec.rb
@@ -51,16 +51,4 @@ RSpec.describe Gitlab::ImportExport::Group::ObjectBuilder do
expect(milestone.persisted?).to be true
end
end
-
- describe '#initialize' do
- context 'when attributes contain description as empty string' do
- let(:attributes) { base_attributes.merge('description' => '') }
-
- it 'converts empty string to nil' do
- builder = described_class.new(Label, attributes)
-
- expect(builder.send(:attributes)).to include({ 'description' => nil })
- end
- end
- end
end
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 b67d42d1b71..9b01005c2e9 100644
--- a/spec/lib/gitlab/import_export/group/tree_restorer_spec.rb
+++ b/spec/lib/gitlab/import_export/group/tree_restorer_spec.rb
@@ -5,116 +5,117 @@ require 'spec_helper'
RSpec.describe Gitlab::ImportExport::Group::TreeRestorer do
include ImportExport::CommonUtil
- describe 'restore group tree' do
- before_all do
- # Using an admin for import, so we can check assignment of existing members
- user = create(:admin, email: 'root@gitlabexample.com')
- create(:user, email: 'adriene.mcclure@gitlabexample.com')
- create(:user, email: 'gwendolyn_robel@gitlabexample.com')
+ shared_examples 'group restoration' do
+ describe 'restore group tree' do
+ before_all do
+ # Using an admin for import, so we can check assignment of existing members
+ user = create(:admin, email: 'root@gitlabexample.com')
+ create(:user, email: 'adriene.mcclure@gitlabexample.com')
+ create(:user, email: 'gwendolyn_robel@gitlabexample.com')
- RSpec::Mocks.with_temporary_scope do
- @group = create(:group, name: 'group', path: 'group')
- @shared = Gitlab::ImportExport::Shared.new(@group)
+ RSpec::Mocks.with_temporary_scope do
+ @group = create(:group, name: 'group', path: 'group')
+ @shared = Gitlab::ImportExport::Shared.new(@group)
- setup_import_export_config('group_exports/complex')
+ setup_import_export_config('group_exports/complex')
- group_tree_restorer = described_class.new(user: user, shared: @shared, group: @group)
+ 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
+ expect(group_tree_restorer.restore).to be_truthy
+ expect(group_tree_restorer.groups_mapping).not_to be_empty
+ end
end
- end
-
- it 'has the group description' do
- expect(Group.find_by_path('group').description).to eq('Group Description')
- end
- it 'has group labels' do
- expect(@group.labels.count).to eq(10)
- end
+ it 'has the group description' do
+ expect(Group.find_by_path('group').description).to eq('Group Description')
+ end
- context 'issue boards' do
- it 'has issue boards' do
- expect(@group.boards.count).to eq(1)
+ it 'has group labels' do
+ expect(@group.labels.count).to eq(10)
end
- it 'has board label lists' do
- lists = @group.boards.find_by(name: 'first board').lists
+ context 'issue boards' do
+ it 'has issue boards' do
+ expect(@group.boards.count).to eq(1)
+ end
+
+ it 'has board label lists' do
+ lists = @group.boards.find_by(name: 'first board').lists
- expect(lists.count).to eq(3)
- expect(lists.first.label.title).to eq('TSL')
- expect(lists.second.label.title).to eq('Sosync')
+ expect(lists.count).to eq(3)
+ expect(lists.first.label.title).to eq('TSL')
+ expect(lists.second.label.title).to eq('Sosync')
+ end
end
- end
- it 'has badges' do
- expect(@group.badges.count).to eq(1)
- end
+ it 'has badges' do
+ expect(@group.badges.count).to eq(1)
+ end
- it 'has milestones' do
- expect(@group.milestones.count).to eq(5)
- end
+ it 'has milestones' do
+ expect(@group.milestones.count).to eq(5)
+ end
- it 'has group children' do
- expect(@group.children.count).to eq(2)
- end
+ it 'has group children' do
+ expect(@group.children.count).to eq(2)
+ end
- it 'has group members' do
- expect(@group.members.map(&:user).map(&:email)).to contain_exactly(
- 'root@gitlabexample.com',
- 'adriene.mcclure@gitlabexample.com',
- 'gwendolyn_robel@gitlabexample.com'
- )
+ it 'has group members' do
+ expect(@group.members.map(&:user).map(&:email)).to contain_exactly(
+ 'root@gitlabexample.com',
+ 'adriene.mcclure@gitlabexample.com',
+ 'gwendolyn_robel@gitlabexample.com'
+ )
+ end
end
- end
- context 'child with no parent' do
- let(:user) { create(:user) }
- let(:group) { create(:group) }
- let(:shared) { Gitlab::ImportExport::Shared.new(group) }
- let(:group_tree_restorer) { described_class.new(user: user, shared: shared, group: group) }
+ context 'child with no parent' do
+ let(:user) { create(:user) }
+ let(:group) { create(:group) }
+ let(:shared) { Gitlab::ImportExport::Shared.new(group) }
+ let(:group_tree_restorer) { described_class.new(user: user, shared: shared, group: group) }
- before do
- setup_import_export_config('group_exports/child_with_no_parent')
- end
+ before do
+ setup_import_export_config('group_exports/child_with_no_parent')
+ end
- it 'captures import failures when a child group does not have a valid parent_id' do
- group_tree_restorer.restore
+ it 'captures import failures when a child group does not have a valid parent_id' do
+ group_tree_restorer.restore
- expect(group.import_failures.first.exception_message).to eq('Parent group not found')
+ expect(group.import_failures.first.exception_message).to eq('Parent group not found')
+ end
end
- end
- context 'when child group creation fails' do
- let(:user) { create(:user) }
- let(:group) { create(:group) }
- let(:shared) { Gitlab::ImportExport::Shared.new(group) }
- let(:group_tree_restorer) { described_class.new(user: user, shared: shared, group: group) }
+ context 'when child group creation fails' do
+ let(:user) { create(:user) }
+ let(:group) { create(:group) }
+ let(:shared) { Gitlab::ImportExport::Shared.new(group) }
+ let(:group_tree_restorer) { described_class.new(user: user, shared: shared, group: group) }
- before do
- setup_import_export_config('group_exports/child_short_name')
- end
+ before do
+ setup_import_export_config('group_exports/child_short_name')
+ end
- it 'captures import failure' do
- exception_message = 'Validation failed: Group URL is too short (minimum is 2 characters)'
+ it 'captures import failure' do
+ exception_message = 'Validation failed: Group URL is too short (minimum is 2 characters)'
- group_tree_restorer.restore
+ group_tree_restorer.restore
- expect(group.import_failures.first.exception_message).to eq(exception_message)
+ expect(group.import_failures.first.exception_message).to eq(exception_message)
+ end
end
- end
- context 'excluded attributes' do
- let!(:source_user) { create(:user, id: 123) }
- let!(:importer_user) { create(:user) }
- let(:group) { create(:group, name: 'user-inputed-name', path: 'user-inputed-path') }
- let(:shared) { Gitlab::ImportExport::Shared.new(group) }
- let(:group_tree_restorer) { described_class.new(user: importer_user, shared: shared, group: group) }
- let(:exported_file) { File.join(shared.export_path, 'tree/groups/4352.json') }
- let(:group_json) { Gitlab::Json.parse(IO.read(exported_file)) }
-
- shared_examples 'excluded attributes' do
- excluded_attributes = %w[
+ context 'excluded attributes' do
+ let!(:source_user) { create(:user, id: 123) }
+ let!(:importer_user) { create(:user) }
+ let(:group) { create(:group, name: 'user-inputed-name', path: 'user-inputed-path') }
+ let(:shared) { Gitlab::ImportExport::Shared.new(group) }
+ let(:group_tree_restorer) { described_class.new(user: importer_user, shared: shared, group: group) }
+ let(:exported_file) { File.join(shared.export_path, 'tree/groups/4352.json') }
+ let(:group_json) { Gitlab::Json.parse(IO.read(exported_file)) }
+
+ shared_examples 'excluded attributes' do
+ excluded_attributes = %w[
id
parent_id
owner_id
@@ -125,80 +126,97 @@ RSpec.describe Gitlab::ImportExport::Group::TreeRestorer do
saml_discovery_token
]
- before do
- group.add_owner(importer_user)
+ before do
+ group.add_owner(importer_user)
- setup_import_export_config('group_exports/complex')
+ setup_import_export_config('group_exports/complex')
- expect(File.exist?(exported_file)).to be_truthy
+ expect(File.exist?(exported_file)).to be_truthy
- group_tree_restorer.restore
- group.reload
- end
+ group_tree_restorer.restore
+ group.reload
+ end
- it 'does not import root group name' do
- expect(group.name).to eq('user-inputed-name')
- end
+ it 'does not import root group name' do
+ expect(group.name).to eq('user-inputed-name')
+ end
- it 'does not import root group path' do
- expect(group.path).to eq('user-inputed-path')
- end
+ it 'does not import root group path' do
+ expect(group.path).to eq('user-inputed-path')
+ end
- excluded_attributes.each do |excluded_attribute|
- it 'does not allow override of excluded attributes' do
- unless group.public_send(excluded_attribute).nil?
- expect(group_json[excluded_attribute]).not_to eq(group.public_send(excluded_attribute))
+ excluded_attributes.each do |excluded_attribute|
+ it 'does not allow override of excluded attributes' do
+ unless group.public_send(excluded_attribute).nil?
+ expect(group_json[excluded_attribute]).not_to eq(group.public_send(excluded_attribute))
+ end
end
end
end
- end
- include_examples 'excluded attributes'
- end
+ include_examples 'excluded attributes'
+ end
- context 'group.json file access check' do
- let(:user) { create(:user) }
- let!(:group) { create(:group, name: 'group2', path: 'group2') }
- let(:shared) { Gitlab::ImportExport::Shared.new(group) }
- let(:group_tree_restorer) { described_class.new(user: user, shared: shared, group: group) }
+ context 'group.json file access check' do
+ let(:user) { create(:user) }
+ let!(:group) { create(:group, name: 'group2', path: 'group2') }
+ let(:shared) { Gitlab::ImportExport::Shared.new(group) }
+ let(:group_tree_restorer) { described_class.new(user: user, shared: shared, group: group) }
- it 'does not read a symlink' do
- Dir.mktmpdir do |tmpdir|
- FileUtils.mkdir_p(File.join(tmpdir, 'tree', 'groups'))
- setup_symlink(tmpdir, 'tree/groups/_all.ndjson')
+ it 'does not read a symlink' do
+ Dir.mktmpdir do |tmpdir|
+ FileUtils.mkdir_p(File.join(tmpdir, 'tree', 'groups'))
+ setup_symlink(tmpdir, 'tree/groups/_all.ndjson')
- allow(shared).to receive(:export_path).and_return(tmpdir)
+ allow(shared).to receive(:export_path).and_return(tmpdir)
- expect(group_tree_restorer.restore).to eq(false)
- expect(shared.errors).to include('Incorrect JSON format')
+ expect(group_tree_restorer.restore).to eq(false)
+ expect(shared.errors).to include('Incorrect JSON format')
+ end
end
end
- end
- context 'group visibility levels' do
- let(:user) { create(:user) }
- let(:shared) { Gitlab::ImportExport::Shared.new(group) }
- let(:group_tree_restorer) { described_class.new(user: user, shared: shared, group: group) }
+ context 'group visibility levels' do
+ let(:user) { create(:user) }
+ let(:shared) { Gitlab::ImportExport::Shared.new(group) }
+ let(:group_tree_restorer) { described_class.new(user: user, shared: shared, group: group) }
- before do
- setup_import_export_config(filepath)
+ before do
+ setup_import_export_config(filepath)
- group_tree_restorer.restore
- end
+ group_tree_restorer.restore
+ end
- shared_examples 'with visibility level' do |visibility_level, expected_visibilities|
- context "when visibility level is #{visibility_level}" do
- let(:group) { create(:group, visibility_level) }
- let(:filepath) { "group_exports/visibility_levels/#{visibility_level}" }
+ shared_examples 'with visibility level' do |visibility_level, expected_visibilities|
+ context "when visibility level is #{visibility_level}" do
+ let(:group) { create(:group, visibility_level) }
+ let(:filepath) { "group_exports/visibility_levels/#{visibility_level}" }
- it "imports all subgroups as #{visibility_level}" do
- expect(group.children.map(&:visibility_level)).to match_array(expected_visibilities)
+ it "imports all subgroups as #{visibility_level}" do
+ expect(group.children.map(&:visibility_level)).to match_array(expected_visibilities)
+ end
end
end
+
+ include_examples 'with visibility level', :public, [20, 10, 0]
+ include_examples 'with visibility level', :private, [0, 0, 0]
+ include_examples 'with visibility level', :internal, [10, 10, 0]
+ end
+ end
+
+ context 'when import_relation_object_persistence feature flag is enabled' do
+ before do
+ stub_feature_flags(import_relation_object_persistence: true)
+ end
+
+ include_examples 'group restoration'
+ end
+
+ context 'when import_relation_object_persistence feature flag is disabled' do
+ before do
+ stub_feature_flags(import_relation_object_persistence: false)
end
- include_examples 'with visibility level', :public, [20, 10, 0]
- include_examples 'with visibility level', :private, [0, 0, 0]
- include_examples 'with visibility level', :internal, [10, 10, 0]
+ include_examples 'group restoration'
end
end
diff --git a/spec/lib/gitlab/import_export/json/streaming_serializer_spec.rb b/spec/lib/gitlab/import_export/json/streaming_serializer_spec.rb
index 352af18c822..ba1cccf87ce 100644
--- a/spec/lib/gitlab/import_export/json/streaming_serializer_spec.rb
+++ b/spec/lib/gitlab/import_export/json/streaming_serializer_spec.rb
@@ -158,26 +158,10 @@ RSpec.describe Gitlab::ImportExport::Json::StreamingSerializer do
end
describe 'load balancing' do
- context 'when feature flag load_balancing_for_export_workers is enabled' do
- before do
- stub_feature_flags(load_balancing_for_export_workers: true)
- end
-
- it 'reads from replica' do
- expect(Gitlab::Database::LoadBalancing::Session.current).to receive(:use_replicas_for_read_queries).and_call_original
-
- subject.execute
- end
- end
+ it 'reads from replica' do
+ expect(Gitlab::Database::LoadBalancing::Session.current).to receive(:use_replicas_for_read_queries).and_call_original
- context 'when feature flag load_balancing_for_export_workers is disabled' do
- it 'reads from primary' do
- stub_feature_flags(load_balancing_for_export_workers: false)
-
- expect(Gitlab::Database::LoadBalancing::Session.current).not_to receive(:use_replicas_for_read_queries)
-
- subject.execute
- end
+ subject.execute
end
end
end
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 ffbbf9326ec..240d86077c4 100644
--- a/spec/lib/gitlab/import_export/project/relation_factory_spec.rb
+++ b/spec/lib/gitlab/import_export/project/relation_factory_spec.rb
@@ -401,4 +401,20 @@ RSpec.describe Gitlab::ImportExport::Project::RelationFactory, :use_clean_rails_
expect(created_object.value).to be_nil
end
end
+
+ context 'event object' do
+ let(:relation_sym) { :events }
+ let(:relation_hash) do
+ {
+ 'project_id' => project.id,
+ 'author_id' => admin.id,
+ 'action' => 'created',
+ 'target_type' => 'Issue'
+ }
+ end
+
+ it 'has preloaded project' do
+ expect(created_object.project).to equal(project)
+ end
+ end
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 8884722254d..fdf8260c058 100644
--- a/spec/lib/gitlab/import_export/project/tree_restorer_spec.rb
+++ b/spec/lib/gitlab/import_export/project/tree_restorer_spec.rb
@@ -1058,13 +1058,35 @@ RSpec.describe Gitlab::ImportExport::Project::TreeRestorer do
end
end
- context 'enable ndjson import' do
- it_behaves_like 'project tree restorer work properly', :legacy_reader, true
+ context 'when import_relation_object_persistence feature flag is enabled' do
+ before do
+ stub_feature_flags(import_relation_object_persistence: true)
+ end
+
+ context 'enable ndjson import' do
+ it_behaves_like 'project tree restorer work properly', :legacy_reader, true
+
+ it_behaves_like 'project tree restorer work properly', :ndjson_reader, true
+ end
- it_behaves_like 'project tree restorer work properly', :ndjson_reader, true
+ context 'disable ndjson import' do
+ it_behaves_like 'project tree restorer work properly', :legacy_reader, false
+ end
end
- context 'disable ndjson import' do
- it_behaves_like 'project tree restorer work properly', :legacy_reader, false
+ context 'when import_relation_object_persistence feature flag is disabled' do
+ before do
+ stub_feature_flags(import_relation_object_persistence: false)
+ end
+
+ context 'enable ndjson import' do
+ it_behaves_like 'project tree restorer work properly', :legacy_reader, true
+
+ it_behaves_like 'project tree restorer work properly', :ndjson_reader, true
+ end
+
+ context 'disable ndjson import' do
+ it_behaves_like 'project tree restorer work properly', :legacy_reader, false
+ end
end
end
diff --git a/spec/lib/gitlab/import_export/safe_model_attributes.yml b/spec/lib/gitlab/import_export/safe_model_attributes.yml
index f019883a91e..e06fcb0cd3f 100644
--- a/spec/lib/gitlab/import_export/safe_model_attributes.yml
+++ b/spec/lib/gitlab/import_export/safe_model_attributes.yml
@@ -857,6 +857,7 @@ Epic:
- health_status
- external_key
- confidential
+ - color
EpicIssue:
- id
- relative_position