diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 14:59:07 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 14:59:07 +0300 |
commit | 8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca (patch) | |
tree | 544930fb309b30317ae9797a9683768705d664c4 /spec/lib/bulk_imports/common | |
parent | 4b1de649d0168371549608993deac953eb692019 (diff) |
Add latest changes from gitlab-org/gitlab@13-7-stable-eev13.7.0-rc42
Diffstat (limited to 'spec/lib/bulk_imports/common')
4 files changed, 103 insertions, 92 deletions
diff --git a/spec/lib/bulk_imports/common/extractors/graphql_extractor_spec.rb b/spec/lib/bulk_imports/common/extractors/graphql_extractor_spec.rb index cde8e2d5c18..a7a19fb73fc 100644 --- a/spec/lib/bulk_imports/common/extractors/graphql_extractor_spec.rb +++ b/spec/lib/bulk_imports/common/extractors/graphql_extractor_spec.rb @@ -41,12 +41,11 @@ RSpec.describe BulkImports::Common::Extractors::GraphqlExtractor do end context 'when variables are present' do - let(:query) { { query: double(to_s: 'test', variables: { full_path: :source_full_path }) } } + let(:variables) { { foo: :bar } } + let(:query) { { query: double(to_s: 'test', variables: variables) } } it 'builds graphql query variables for import entity' do - expected_variables = { full_path: import_entity.source_full_path } - - expect(graphql_client).to receive(:execute).with(anything, expected_variables) + expect(graphql_client).to receive(:execute).with(anything, variables) subject.extract(context).first end diff --git a/spec/lib/bulk_imports/common/transformers/graphql_cleaner_transformer_spec.rb b/spec/lib/bulk_imports/common/transformers/graphql_cleaner_transformer_spec.rb deleted file mode 100644 index 8f39b6e7c93..00000000000 --- a/spec/lib/bulk_imports/common/transformers/graphql_cleaner_transformer_spec.rb +++ /dev/null @@ -1,88 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe BulkImports::Common::Transformers::GraphqlCleanerTransformer do - describe '#transform' do - let_it_be(:expected_output) do - { - 'name' => 'test', - 'fullName' => 'test', - 'description' => 'test', - 'labels' => [ - { 'title' => 'label1' }, - { 'title' => 'label2' }, - { 'title' => 'label3' } - ] - } - end - - it 'deep cleans hash from GraphQL keys' do - data = { - 'data' => { - 'group' => { - 'name' => 'test', - 'fullName' => 'test', - 'description' => 'test', - 'labels' => { - 'edges' => [ - { 'node' => { 'title' => 'label1' } }, - { 'node' => { 'title' => 'label2' } }, - { 'node' => { 'title' => 'label3' } } - ] - } - } - } - } - - transformed_data = described_class.new.transform(nil, data) - - expect(transformed_data).to eq(expected_output) - end - - context 'when data does not have data/group nesting' do - it 'deep cleans hash from GraphQL keys' do - data = { - 'name' => 'test', - 'fullName' => 'test', - 'description' => 'test', - 'labels' => { - 'edges' => [ - { 'node' => { 'title' => 'label1' } }, - { 'node' => { 'title' => 'label2' } }, - { 'node' => { 'title' => 'label3' } } - ] - } - } - - transformed_data = described_class.new.transform(nil, data) - - expect(transformed_data).to eq(expected_output) - end - end - - context 'when data is not a hash' do - it 'does not perform transformation' do - data = 'test' - - transformed_data = described_class.new.transform(nil, data) - - expect(transformed_data).to eq(data) - end - end - - context 'when nested data is not an array or hash' do - it 'only removes top level data/group keys' do - data = { - 'data' => { - 'group' => 'test' - } - } - - transformed_data = described_class.new.transform(nil, data) - - expect(transformed_data).to eq('test') - end - end - end -end diff --git a/spec/lib/bulk_imports/common/transformers/hash_key_digger_spec.rb b/spec/lib/bulk_imports/common/transformers/hash_key_digger_spec.rb new file mode 100644 index 00000000000..2b33701653e --- /dev/null +++ b/spec/lib/bulk_imports/common/transformers/hash_key_digger_spec.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe BulkImports::Common::Transformers::HashKeyDigger do + describe '#transform' do + it 'when the key_path is an array' do + data = { foo: { bar: :value } } + key_path = %i[foo bar] + transformed = described_class.new(key_path: key_path).transform(nil, data) + + expect(transformed).to eq(:value) + end + + it 'when the key_path is not an array' do + data = { foo: { bar: :value } } + key_path = :foo + transformed = described_class.new(key_path: key_path).transform(nil, data) + + expect(transformed).to eq({ bar: :value }) + end + + it "when the data is not a hash" do + expect { described_class.new(key_path: nil).transform(nil, nil) } + .to raise_error(ArgumentError, "Given data must be a Hash") + end + end +end diff --git a/spec/lib/bulk_imports/common/transformers/prohibited_attributes_transformer_spec.rb b/spec/lib/bulk_imports/common/transformers/prohibited_attributes_transformer_spec.rb new file mode 100644 index 00000000000..03d138b227c --- /dev/null +++ b/spec/lib/bulk_imports/common/transformers/prohibited_attributes_transformer_spec.rb @@ -0,0 +1,72 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe BulkImports::Common::Transformers::ProhibitedAttributesTransformer do + describe '#transform' do + let_it_be(:hash) do + { + 'id' => 101, + 'service_id' => 99, + 'moved_to_id' => 99, + 'namespace_id' => 99, + 'ci_id' => 99, + 'random_project_id' => 99, + 'random_id' => 99, + 'milestone_id' => 99, + 'project_id' => 99, + 'user_id' => 99, + 'random_id_in_the_middle' => 99, + 'notid' => 99, + 'import_source' => 'test', + 'import_type' => 'test', + 'non_existent_attr' => 'test', + 'some_html' => '<p>dodgy html</p>', + 'legit_html' => '<p>legit html</p>', + '_html' => '<p>perfectly ordinary html</p>', + 'cached_markdown_version' => 12345, + 'custom_attributes' => 'test', + 'some_attributes_metadata' => 'test', + 'group_id' => 99, + 'commit_id' => 99, + 'issue_ids' => [1, 2, 3], + 'merge_request_ids' => [1, 2, 3], + 'note_ids' => [1, 2, 3], + 'remote_attachment_url' => 'http://something.dodgy', + 'remote_attachment_request_header' => 'bad value', + 'remote_attachment_urls' => %w(http://something.dodgy http://something.okay), + 'attributes' => { + 'issue_ids' => [1, 2, 3], + 'merge_request_ids' => [1, 2, 3], + 'note_ids' => [1, 2, 3] + }, + 'variables_attributes' => { + 'id' => 1 + }, + 'attr_with_nested_attrs' => { + 'nested_id' => 1, + 'nested_attr' => 2 + } + } + end + + let(:expected_hash) do + { + 'random_id_in_the_middle' => 99, + 'notid' => 99, + 'import_source' => 'test', + 'import_type' => 'test', + 'non_existent_attr' => 'test', + 'attr_with_nested_attrs' => { + 'nested_attr' => 2 + } + } + end + + it 'removes prohibited attributes' do + transformed_hash = subject.transform(nil, hash) + + expect(transformed_hash).to eq(expected_hash) + end + end +end |