2019-11-26 03:06:24 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-16 15:32:58 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2016-09-02 12:35:33 +00:00
|
|
|
# Part of the test security suite for the Import/Export feature
|
2016-08-16 15:32:58 +00:00
|
|
|
# Checks whether there are new attributes in models that are currently being exported as part of the
|
|
|
|
# project Import/Export feature.
|
|
|
|
# If there are new attributes, these will have to either be added to this spec in case we want them
|
|
|
|
# to be included as part of the export, or blacklist them using the import_export.yml configuration file.
|
|
|
|
# Likewise, new models added to import_export.yml, will need to be added with their correspondent attributes
|
|
|
|
# to this spec.
|
2017-07-10 14:24:02 +00:00
|
|
|
describe 'Import/Export attribute configuration' do
|
2016-09-01 15:59:36 +00:00
|
|
|
include ConfigurationHelper
|
|
|
|
|
2016-09-07 07:14:47 +00:00
|
|
|
let(:safe_attributes_file) { 'spec/lib/gitlab/import_export/safe_model_attributes.yml' }
|
|
|
|
let(:safe_model_attributes) { YAML.load_file(safe_attributes_file) }
|
2016-08-16 15:32:58 +00:00
|
|
|
|
|
|
|
it 'has no new columns' do
|
2019-12-18 00:08:09 +00:00
|
|
|
relation_names_for(:project).each do |relation_name|
|
2016-08-16 15:32:58 +00:00
|
|
|
relation_class = relation_class_for_name(relation_name)
|
2019-01-15 21:05:36 +00:00
|
|
|
relation_attributes = relation_class.new.attributes.keys - relation_class.encrypted_attributes.keys.map(&:to_s)
|
2016-08-16 15:32:58 +00:00
|
|
|
|
2016-10-06 21:17:11 +00:00
|
|
|
current_attributes = parsed_attributes(relation_name, relation_attributes)
|
2018-11-08 07:02:44 +00:00
|
|
|
safe_attributes = safe_model_attributes[relation_class.to_s].dup || []
|
|
|
|
|
|
|
|
expect(safe_attributes).not_to be_nil, "Expected exported class #{relation_class} to exist in safe_model_attributes"
|
|
|
|
|
2016-08-16 15:32:58 +00:00
|
|
|
new_attributes = current_attributes - safe_attributes
|
|
|
|
|
|
|
|
expect(new_attributes).to be_empty, failure_message(relation_class.to_s, new_attributes)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def failure_message(relation_class, new_attributes)
|
|
|
|
<<-MSG
|
|
|
|
It looks like #{relation_class}, which is exported using the project Import/Export, has new attributes: #{new_attributes.join(',')}
|
|
|
|
|
2016-09-07 07:14:47 +00:00
|
|
|
Please add the attribute(s) to SAFE_MODEL_ATTRIBUTES if you consider this can be exported.
|
Backport the EE schema and migrations to CE
This backports all EE schema changes to CE, including EE migrations,
ensuring both use the same schema.
== Updated tests
A spec related to ghost and support bot users had to be modified to make
it pass. The spec in question assumes that the "support_bot" column
exists when defining the spec. In the single codebase setup this is not
the case, as the column is backported in a later migration. Any attempt
to use a different schema version or use of "around" blocks to
conditionally disable specs won't help, as reverting the backport
migration would also drop the "support_bot" column. Removing the
"support_bot" tests entirely appears to be the only solution.
We also need to update some foreign key tests now that we have
backported the EE columns. Fortunately, these changes are very minor.
== Backporting migrations
This commit moves EE specific migrations (except those for the Geo
tracking database) and related files to CE, and also removes any traces
of the ee/db directory.
Some migrations had to be modified or removed, as they no longer work
with the schema being backported. These migrations were all quite old,
so we opted for removing them where modifying them would take too much
time and effort.
Some old migrations were modified in EE, while also existing in CE. In
these cases we took the EE code, and in one case removed them entirely.
It's not worth spending time trying to merge these changes somehow as we
plan to remove old migrations around the release of 12.0, see
https://gitlab.com/gitlab-org/gitlab-ce/issues/59177 for more details.
2019-04-29 12:16:03 +00:00
|
|
|
Please blacklist the attribute(s) in IMPORT_EXPORT_CONFIG by adding it to its correspondent
|
2016-08-16 15:32:58 +00:00
|
|
|
model in the +excluded_attributes+ section.
|
|
|
|
|
2016-09-07 07:14:47 +00:00
|
|
|
SAFE_MODEL_ATTRIBUTES: #{File.expand_path(safe_attributes_file)}
|
2016-08-16 15:32:58 +00:00
|
|
|
IMPORT_EXPORT_CONFIG: #{Gitlab::ImportExport.config_file}
|
|
|
|
MSG
|
|
|
|
end
|
|
|
|
end
|