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
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-12-18 03:08:09 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2019-12-18 03:08:09 +0300
commit2a65a97e12a0754b9f0d91ee996a6e61e00c80c8 (patch)
treef439c93cc95a324ba7422b0b650431a628be9b07 /spec
parent2d96e61ceb1a3f26283dfba43f85d99488752296 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/features/admin/clusters/eks_spec.rb2
-rw-r--r--spec/features/groups/clusters/eks_spec.rb2
-rw-r--r--spec/features/projects/clusters/eks_spec.rb2
-rw-r--r--spec/features/projects/clusters/gcp_spec.rb2
-rw-r--r--spec/features/projects/clusters_spec.rb2
-rw-r--r--spec/features/projects/import_export/export_file_spec.rb2
-rw-r--r--spec/helpers/clusters_helper_spec.rb8
-rw-r--r--spec/lib/gitlab/import_export/attribute_configuration_spec.rb12
-rw-r--r--spec/lib/gitlab/import_export/model_configuration_spec.rb11
-rw-r--r--spec/lib/gitlab/import_export/references_configuration_spec.rb48
-rw-r--r--spec/lib/gitlab/import_export/safe_model_attributes.yml19
-rw-r--r--spec/models/ci/build_spec.rb21
-rw-r--r--spec/models/commit_status_spec.rb66
-rw-r--r--spec/support/import_export/configuration_helper.rb41
14 files changed, 183 insertions, 55 deletions
diff --git a/spec/features/admin/clusters/eks_spec.rb b/spec/features/admin/clusters/eks_spec.rb
index b262db1ad7c..40561aa508c 100644
--- a/spec/features/admin/clusters/eks_spec.rb
+++ b/spec/features/admin/clusters/eks_spec.rb
@@ -22,7 +22,7 @@ describe 'Instance-level AWS EKS Cluster', :js do
end
it 'user sees a form to create an EKS cluster' do
- expect(page).to have_content('Create new Cluster on EKS')
+ expect(page).to have_content('Create new cluster on EKS')
end
end
end
diff --git a/spec/features/groups/clusters/eks_spec.rb b/spec/features/groups/clusters/eks_spec.rb
index b6942304c22..a9267d58739 100644
--- a/spec/features/groups/clusters/eks_spec.rb
+++ b/spec/features/groups/clusters/eks_spec.rb
@@ -28,7 +28,7 @@ describe 'Group AWS EKS Cluster', :js do
end
it 'user sees a form to create an EKS cluster' do
- expect(page).to have_content('Create new Cluster on EKS')
+ expect(page).to have_content('Create new cluster on EKS')
end
end
end
diff --git a/spec/features/projects/clusters/eks_spec.rb b/spec/features/projects/clusters/eks_spec.rb
index e0ebccd85ac..bb0072fc8dd 100644
--- a/spec/features/projects/clusters/eks_spec.rb
+++ b/spec/features/projects/clusters/eks_spec.rb
@@ -28,7 +28,7 @@ describe 'AWS EKS Cluster', :js do
end
it 'user sees a form to create an EKS cluster' do
- expect(page).to have_content('Create new Cluster on EKS')
+ expect(page).to have_content('Create new cluster on EKS')
end
end
end
diff --git a/spec/features/projects/clusters/gcp_spec.rb b/spec/features/projects/clusters/gcp_spec.rb
index 142aaaffb7d..4bc0aef0cd4 100644
--- a/spec/features/projects/clusters/gcp_spec.rb
+++ b/spec/features/projects/clusters/gcp_spec.rb
@@ -29,7 +29,7 @@ describe 'Gcp Cluster', :js, :do_not_mock_admin_mode do
visit project_clusters_path(project)
click_link 'Add Kubernetes cluster'
- click_link 'Create new Cluster'
+ click_link 'Create new cluster'
click_link 'Google GKE'
end
diff --git a/spec/features/projects/clusters_spec.rb b/spec/features/projects/clusters_spec.rb
index 9b02991cd53..ad51533c42c 100644
--- a/spec/features/projects/clusters_spec.rb
+++ b/spec/features/projects/clusters_spec.rb
@@ -54,7 +54,7 @@ describe 'Clusters', :js do
visit project_clusters_path(project)
click_link 'Add Kubernetes cluster'
- click_link 'Create new Cluster'
+ click_link 'Create new cluster'
end
it 'user sees a link to create a GKE cluster' do
diff --git a/spec/features/projects/import_export/export_file_spec.rb b/spec/features/projects/import_export/export_file_spec.rb
index c15a3250221..54a6ac1551b 100644
--- a/spec/features/projects/import_export/export_file_spec.rb
+++ b/spec/features/projects/import_export/export_file_spec.rb
@@ -12,8 +12,6 @@ describe 'Import/Export - project export integration test', :js do
let(:user) { create(:admin) }
let(:export_path) { "#{Dir.tmpdir}/import_file_spec" }
- let(:config_hash) { Gitlab::ImportExport::Config.new.to_h.deep_stringify_keys }
-
let(:sensitive_words) { %w[pass secret token key encrypted html] }
let(:safe_list) do
{
diff --git a/spec/helpers/clusters_helper_spec.rb b/spec/helpers/clusters_helper_spec.rb
index 1ee638ddf04..ff8394b9475 100644
--- a/spec/helpers/clusters_helper_spec.rb
+++ b/spec/helpers/clusters_helper_spec.rb
@@ -37,25 +37,25 @@ describe ClustersHelper do
context 'GCP provider' do
let(:provider) { 'gcp' }
- it { is_expected.to eq('Create new Cluster on GKE') }
+ it { is_expected.to eq('Create new cluster on GKE') }
end
context 'AWS provider' do
let(:provider) { 'aws' }
- it { is_expected.to eq('Create new Cluster on EKS') }
+ it { is_expected.to eq('Create new cluster on EKS') }
end
context 'other provider' do
let(:provider) { 'other' }
- it { is_expected.to eq('Create new Cluster') }
+ it { is_expected.to eq('Create new cluster') }
end
context 'no provider' do
let(:provider) { nil }
- it { is_expected.to eq('Create new Cluster') }
+ it { is_expected.to eq('Create new cluster') }
end
end
diff --git a/spec/lib/gitlab/import_export/attribute_configuration_spec.rb b/spec/lib/gitlab/import_export/attribute_configuration_spec.rb
index 41da1383f74..58da25bbedb 100644
--- a/spec/lib/gitlab/import_export/attribute_configuration_spec.rb
+++ b/spec/lib/gitlab/import_export/attribute_configuration_spec.rb
@@ -12,21 +12,11 @@ require 'spec_helper'
describe 'Import/Export attribute configuration' do
include ConfigurationHelper
- let(:config_hash) { Gitlab::ImportExport::Config.new.to_h.deep_stringify_keys }
- let(:relation_names) do
- names = names_from_tree(config_hash.dig('tree', 'project'))
-
- # Remove duplicated or add missing models
- # - project is not part of the tree, so it has to be added manually.
- # - milestone, labels have both singular and plural versions in the tree, so remove the duplicates.
- names.flatten.uniq - %w(milestones labels) + ['project']
- end
-
let(:safe_attributes_file) { 'spec/lib/gitlab/import_export/safe_model_attributes.yml' }
let(:safe_model_attributes) { YAML.load_file(safe_attributes_file) }
it 'has no new columns' do
- relation_names.each do |relation_name|
+ relation_names_for(:project).each do |relation_name|
relation_class = relation_class_for_name(relation_name)
relation_attributes = relation_class.new.attributes.keys - relation_class.encrypted_attributes.keys.map(&:to_s)
diff --git a/spec/lib/gitlab/import_export/model_configuration_spec.rb b/spec/lib/gitlab/import_export/model_configuration_spec.rb
index d97e76f3cbd..cfbfe244988 100644
--- a/spec/lib/gitlab/import_export/model_configuration_spec.rb
+++ b/spec/lib/gitlab/import_export/model_configuration_spec.rb
@@ -8,19 +8,10 @@ require 'spec_helper'
describe 'Import/Export model configuration' do
include ConfigurationHelper
- let(:config_hash) { Gitlab::ImportExport::Config.new.to_h.deep_stringify_keys }
- let(:model_names) do
- names = names_from_tree(config_hash.dig('tree', 'project'))
-
- # Remove duplicated or add missing models
- # - project is not part of the tree, so it has to be added manually.
- # - milestone, labels, merge_request have both singular and plural versions in the tree, so remove the duplicates.
- # - User, Author... Models we do not care about for checking models
- names.flatten.uniq - %w(milestones labels user author merge_request) + ['project']
- end
let(:all_models_yml) { 'spec/lib/gitlab/import_export/all_models.yml' }
let(:all_models_hash) { YAML.load_file(all_models_yml) }
let(:current_models) { setup_models }
+ let(:model_names) { relation_names_for(:project) }
it 'has no new models' do
model_names.each do |model_name|
diff --git a/spec/lib/gitlab/import_export/references_configuration_spec.rb b/spec/lib/gitlab/import_export/references_configuration_spec.rb
new file mode 100644
index 00000000000..91cf9f964c0
--- /dev/null
+++ b/spec/lib/gitlab/import_export/references_configuration_spec.rb
@@ -0,0 +1,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.
+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
diff --git a/spec/lib/gitlab/import_export/safe_model_attributes.yml b/spec/lib/gitlab/import_export/safe_model_attributes.yml
index bf8c079f027..79442c35797 100644
--- a/spec/lib/gitlab/import_export/safe_model_attributes.yml
+++ b/spec/lib/gitlab/import_export/safe_model_attributes.yml
@@ -33,7 +33,6 @@ Issue:
Event:
- id
- target_type
-- target_id
- project_id
- group_id
- created_at
@@ -60,7 +59,6 @@ Note:
- attachment
- line_code
- commit_id
-- noteable_id
- system
- st_diff
- updated_by_id
@@ -73,11 +71,8 @@ Note:
- resolved_by_push
- discussion_id
- original_discussion_id
-- review_id
LabelLink:
- id
-- label_id
-- target_id
- target_type
- created_at
- updated_at
@@ -130,13 +125,11 @@ Release:
- released_at
Evidence:
- id
-- release_id
- summary
- created_at
- updated_at
Releases::Link:
- id
-- release_id
- url
- name
- created_at
@@ -144,7 +137,6 @@ Releases::Link:
ProjectMember:
- id
- access_level
-- source_id
- source_type
- user_id
- notification_level
@@ -600,7 +592,6 @@ AwardEmoji:
LabelPriority:
- id
- project_id
-- label_id
- priority
- created_at
- updated_at
@@ -608,7 +599,6 @@ Timelog:
- id
- time_spent
- merge_request_id
-- issue_id
- user_id
- spent_at
- created_at
@@ -623,7 +613,6 @@ ProjectAutoDevops:
- updated_at
IssueAssignee:
- user_id
-- issue_id
ProjectCustomAttribute:
- id
- created_at
@@ -679,7 +668,6 @@ ProtectedEnvironment::DeployAccessLevel:
ResourceLabelEvent:
- id
- action
-- issue_id
- merge_request_id
- label_id
- user_id
@@ -691,11 +679,9 @@ ErrorTracking::ProjectErrorTrackingSetting:
- organization_name
SentryIssue:
- id
-- issue_id
- sentry_issue_identifier
Suggestion:
- id
-- note_id
- relative_order
- applied
- commit_id
@@ -750,21 +736,16 @@ ExternalPullRequest:
DesignManagement::Design:
- id
- project_id
-- issue_id
- filename
DesignManagement::Action:
-- design_id
- event
-- version_id
DesignManagement::Version:
- id
- created_at
- sha
-- issue_id
- author_id
ZoomMeeting:
- id
-- issue_id
- project_id
- issue_status
- url
diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb
index 8a701a461c0..900e0feaccc 100644
--- a/spec/models/ci/build_spec.rb
+++ b/spec/models/ci/build_spec.rb
@@ -815,6 +815,27 @@ describe Ci::Build do
it { is_expected.to contain_exactly(build, rspec_test, rubocop_test, staging) }
end
end
+
+ describe '#all_dependencies' do
+ let!(:final_build) do
+ create(:ci_build,
+ pipeline: pipeline, name: 'deploy',
+ stage_idx: 3, stage: 'deploy'
+ )
+ end
+
+ subject { final_build.all_dependencies }
+
+ it 'returns dependencies and cross_dependencies' do
+ dependencies = [1, 2, 3]
+ cross_dependencies = [3, 4]
+
+ allow(final_build).to receive(:dependencies).and_return(dependencies)
+ allow(final_build).to receive(:cross_dependencies).and_return(cross_dependencies)
+
+ is_expected.to match(a_collection_containing_exactly(1, 2, 3, 4))
+ end
+ end
end
describe '#triggered_by?' do
diff --git a/spec/models/commit_status_spec.rb b/spec/models/commit_status_spec.rb
index 1e1b679a32c..31aebac54e1 100644
--- a/spec/models/commit_status_spec.rb
+++ b/spec/models/commit_status_spec.rb
@@ -312,6 +312,72 @@ describe CommitStatus do
end
end
+ describe '.for_ref' do
+ subject { described_class.for_ref('bb').order(:id) }
+
+ let(:statuses) do
+ [create_status(ref: 'aa'),
+ create_status(ref: 'bb'),
+ create_status(ref: 'cc')]
+ end
+
+ it 'returns statuses with the specified ref' do
+ is_expected.to eq(statuses.values_at(1))
+ end
+ end
+
+ describe '.by_name' do
+ subject { described_class.by_name('bb').order(:id) }
+
+ let(:statuses) do
+ [create_status(name: 'aa'),
+ create_status(name: 'bb'),
+ create_status(name: 'cc')]
+ end
+
+ it 'returns statuses with the specified name' do
+ is_expected.to eq(statuses.values_at(1))
+ end
+ end
+
+ describe '.for_project_paths' do
+ subject do
+ described_class
+ .for_project_paths(paths)
+ .order(:id)
+ end
+
+ context 'with a single path' do
+ let(:other_project) { create(:project, :repository) }
+ let(:paths) { other_project.full_path }
+
+ let(:other_pipeline) do
+ create(:ci_pipeline, project: other_project, sha: other_project.commit.id)
+ end
+
+ let(:statuses) do
+ [create_status(pipeline: pipeline),
+ create_status(pipeline: other_pipeline)]
+ end
+
+ it 'returns statuses for other_project' do
+ is_expected.to eq(statuses.values_at(1))
+ end
+ end
+
+ context 'with array of paths' do
+ let(:paths) { [project.full_path] }
+
+ let(:statuses) do
+ [create_status(pipeline: pipeline)]
+ end
+
+ it 'returns statuses for project' do
+ is_expected.to eq(statuses.values_at(0))
+ end
+ end
+ end
+
describe '.status' do
context 'when there are multiple statuses present' do
before do
diff --git a/spec/support/import_export/configuration_helper.rb b/spec/support/import_export/configuration_helper.rb
index 122df7f27f0..2e5a99bb8b2 100644
--- a/spec/support/import_export/configuration_helper.rb
+++ b/spec/support/import_export/configuration_helper.rb
@@ -10,21 +10,54 @@ module ConfigurationHelper
end
end
+ def all_relations(tree, tree_path = [])
+ tree.flat_map do |relation_name, relations|
+ relation_path = tree_path + [relation_name]
+ [relation_path] + all_relations(relations, relation_path)
+ end
+ end
+
+ def config_hash(config = Gitlab::ImportExport.config_file)
+ Gitlab::ImportExport::Config.new(config: config).to_h
+ end
+
+ def relation_paths_for(key, config: Gitlab::ImportExport.config_file)
+ # - project is not part of the tree, so it has to be added manually.
+ all_relations({ project: config_hash(config).dig(:tree, key) })
+ end
+
+ def relation_names_for(key, config: Gitlab::ImportExport.config_file)
+ names = names_from_tree(config_hash(config).dig(:tree, key))
+ # Remove duplicated or add missing models
+ # - project is not part of the tree, so it has to be added manually.
+ # - milestone, labels, merge_request have both singular and plural versions in the tree, so remove the duplicates.
+ # - User, Author... Models we do not care about for checking models
+ names.flatten.uniq - %w(milestones labels user author merge_request design) + [key.to_s]
+ end
+
def relation_class_for_name(relation_name)
relation_name = Gitlab::ImportExport::RelationFactory.overrides[relation_name.to_sym] || relation_name
Gitlab::ImportExport::RelationFactory.relation_class(relation_name)
end
- def parsed_attributes(relation_name, attributes)
- excluded_attributes = config_hash['excluded_attributes'][relation_name]
- included_attributes = config_hash['included_attributes'][relation_name]
-
+ def parsed_attributes(relation_name, attributes, config: Gitlab::ImportExport.config_file)
+ import_export_config = config_hash(config)
+ excluded_attributes = import_export_config[:excluded_attributes][relation_name.to_sym]
+ included_attributes = import_export_config[:included_attributes][relation_name.to_sym]
attributes = attributes - JSON[excluded_attributes.to_json] if excluded_attributes
attributes = attributes & JSON[included_attributes.to_json] if included_attributes
attributes
end
+ def prohibited_key?(key)
+ key =~ Gitlab::ImportExport::AttributeCleaner::PROHIBITED_REFERENCES && !permitted_key?(key)
+ end
+
+ def permitted_key?(key)
+ Gitlab::ImportExport::AttributeCleaner::ALLOWED_REFERENCES.include?(key)
+ end
+
def associations_for(safe_model)
safe_model.reflect_on_all_associations.map { |assoc| assoc.name.to_s }
end