diff options
author | James Lopez <james@jameslopez.es> | 2017-01-30 14:26:49 +0300 |
---|---|---|
committer | James Lopez <james@jameslopez.es> | 2017-01-30 14:34:32 +0300 |
commit | 1a2d13c821179a2707790d9c0e4585044462cd42 (patch) | |
tree | 45b3044bf8b7d76a757131c5260ed1cb107b6808 | |
parent | eeb13c16d1f627eba10313bf5c4662416392feb3 (diff) |
programmatically remove encrypted attributes. Added relevant spec.
-rw-r--r-- | lib/gitlab/import_export/relation_factory.rb | 9 | ||||
-rw-r--r-- | spec/features/projects/import_export/export_file_spec.rb | 4 | ||||
-rw-r--r-- | spec/lib/gitlab/import_export/relation_factory_spec.rb | 11 |
3 files changed, 22 insertions, 2 deletions
diff --git a/lib/gitlab/import_export/relation_factory.rb b/lib/gitlab/import_export/relation_factory.rb index cb9f20a70a0..dd7f9e2fd65 100644 --- a/lib/gitlab/import_export/relation_factory.rb +++ b/lib/gitlab/import_export/relation_factory.rb @@ -63,6 +63,7 @@ module Gitlab handle_group_label if group_label? reset_tokens! + remove_encrypted_attributes! @relation_hash['data'].deep_symbolize_keys! if @relation_name == :events && @relation_hash['data'] set_st_diffs if @relation_name == :merge_request_diff @@ -152,6 +153,14 @@ module Gitlab end end + def remove_encrypted_attributes! + return if relation_class.encrypted_attributes.empty? + + relation_class.encrypted_attributes.each_key do |key| + @relation_hash[key.to_s] = nil + end + end + def relation_class @relation_class ||= @relation_name.to_s.classify.constantize end diff --git a/spec/features/projects/import_export/export_file_spec.rb b/spec/features/projects/import_export/export_file_spec.rb index 2fbfe045b7f..16dddb2a86b 100644 --- a/spec/features/projects/import_export/export_file_spec.rb +++ b/spec/features/projects/import_export/export_file_spec.rb @@ -74,8 +74,8 @@ feature 'Import/Export - project export integration test', feature: true, js: tr Otherwise, please add the exception to +safe_list+ in CURRENT_SPEC using #{sensitive_word} as the key and the correspondent hash or model as the value. - Also, if the attribute is encrypted, please add it to either the list of excluded attributes in IMPORT_EXPORT_CONFIG - or the model to RelationFactory::TOKEN_RESET_MODELS if it includes a token that can be reset. + Also, if the attribute is a generated unique token, please add it to RelationFactory::TOKEN_RESET_MODELS if it needs to be + reset (to prevent duplicate column problems while importing to the same instance). IMPORT_EXPORT_CONFIG: #{Gitlab::ImportExport.config_file} CURRENT_SPEC: #{__FILE__} diff --git a/spec/lib/gitlab/import_export/relation_factory_spec.rb b/spec/lib/gitlab/import_export/relation_factory_spec.rb index d381316c7fe..c6370f3c164 100644 --- a/spec/lib/gitlab/import_export/relation_factory_spec.rb +++ b/spec/lib/gitlab/import_export/relation_factory_spec.rb @@ -178,4 +178,15 @@ describe Gitlab::ImportExport::RelationFactory, lib: true do expect(created_object.author).to eq(new_user) end end + + context 'encrypted attributes' do + let(:relation_sym) { 'Ci::Variable' } + let(:relation_hash) do + create(:ci_variable).as_json + end + + it 'maps the right author to the imported note' do + expect(created_object.value).to be_nil + end + end end |