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

references_configuration_spec.rb « import_export « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2934d0059ee75f08b6fa210ca051f95058faab82 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# frozen_string_literal: true

require 'spec_helper'

# Part of the test security suite for the Import/Export feature
# Checks whether there are new reference attributes ending with _id in models that are currently being exported as part of the
# project Import/Export feature.
# If there are new references (foreign keys), these will have to either be replaced with actual relation
# or to be blacklisted by using the import_export.yml configuration file.
# Likewise, new models added to import_export.yml, will need to be added with their correspondent relations
# to this spec.
RSpec.describe 'Import/Export Project configuration' do
  include ConfigurationHelper

  where(:relation_path, :relation_name) do
    relation_paths_for(:project).map do |relation_names|
      next if relation_names.last == :author

      [relation_names.join("."), relation_names.last]
    end.compact
  end

  with_them do
    context "where relation #{params[:relation_path]}" do
      it 'does not have prohibited keys' do
        relation_class = relation_class_for_name(relation_name)
        relation_attributes = relation_class.new.attributes.keys - relation_class.encrypted_attributes.keys.map(&:to_s)
        current_attributes = parsed_attributes(relation_name, relation_attributes)
        prohibited_keys = current_attributes.select do |attribute|
          prohibited_key?(attribute) || !relation_class.attribute_method?(attribute)
        end
        expect(prohibited_keys).to be_empty, failure_message(relation_class.to_s, prohibited_keys)
      end
    end
  end

  def failure_message(relation_class, prohibited_keys)
    <<-MSG
      It looks like #{relation_class}, which is exported using the project Import/Export, has references: #{prohibited_keys.join(',')}

      Please replace it with actual relation in IMPORT_EXPORT_CONFIG if you consider this can be exported.
      Please blacklist the attribute(s) in IMPORT_EXPORT_CONFIG by adding it to its correspondent
      model in the +excluded_attributes+ section.

      IMPORT_EXPORT_CONFIG: #{Gitlab::ImportExport.config_file}
    MSG
  end
end