diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-05 17:35:52 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-05 17:35:52 +0000 |
commit | c87bc054dd5e573709f5ee6eeb540f2555f56078 (patch) | |
tree | 3c2a2f1b132ac2b535d62d6d04316489a01f2727 | |
parent | d978f080ed958c36d99c408a1044326e632fff51 (diff) | |
download | gitlab-ce-c87bc054dd5e573709f5ee6eeb540f2555f56078.tar.gz |
Add latest changes from gitlab-org/gitlab@14-0-stable-ee
-rw-r--r-- | app/models/project.rb | 47 | ||||
-rw-r--r-- | qa/qa.rb | 2 | ||||
-rw-r--r-- | qa/qa/page/project/import/github.rb | 4 | ||||
-rw-r--r-- | qa/qa/scenario/test/integration/registry.rb | 13 | ||||
-rw-r--r-- | qa/qa/scenario/test/integration/registry_tls.rb | 13 | ||||
-rw-r--r-- | qa/qa/specs/features/browser_ui/1_manage/group/bulk_import_group_spec.rb | 15 | ||||
-rw-r--r-- | spec/models/project_spec.rb | 47 | ||||
-rw-r--r-- | spec/support/shared_examples/models/project_ci_cd_settings_shared_examples.rb | 54 |
8 files changed, 183 insertions, 12 deletions
diff --git a/app/models/project.rb b/app/models/project.rb index 55009bce678..41fc9a2bcdf 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -424,17 +424,16 @@ class Project < ApplicationRecord delegate :members, to: :team, prefix: true delegate :add_user, :add_users, to: :team delegate :add_guest, :add_reporter, :add_developer, :add_maintainer, :add_role, to: :team - delegate :group_runners_enabled, :group_runners_enabled=, :group_runners_enabled?, to: :ci_cd_settings + delegate :group_runners_enabled, :group_runners_enabled=, to: :ci_cd_settings, allow_nil: true delegate :root_ancestor, to: :namespace, allow_nil: true delegate :last_pipeline, to: :commit, allow_nil: true delegate :external_dashboard_url, to: :metrics_setting, allow_nil: true, prefix: true delegate :dashboard_timezone, to: :metrics_setting, allow_nil: true, prefix: true delegate :default_git_depth, :default_git_depth=, to: :ci_cd_settings, prefix: :ci, allow_nil: true - delegate :forward_deployment_enabled, :forward_deployment_enabled=, :forward_deployment_enabled?, to: :ci_cd_settings, prefix: :ci, allow_nil: true - delegate :job_token_scope_enabled, :job_token_scope_enabled=, :job_token_scope_enabled?, to: :ci_cd_settings, prefix: :ci - delegate :keep_latest_artifact, :keep_latest_artifact=, :keep_latest_artifact?, :keep_latest_artifacts_available?, to: :ci_cd_settings, allow_nil: true - delegate :restrict_user_defined_variables, :restrict_user_defined_variables=, :restrict_user_defined_variables?, - to: :ci_cd_settings, allow_nil: true + delegate :forward_deployment_enabled, :forward_deployment_enabled=, to: :ci_cd_settings, prefix: :ci, allow_nil: true + delegate :job_token_scope_enabled, :job_token_scope_enabled=, to: :ci_cd_settings, prefix: :ci, allow_nil: true + delegate :keep_latest_artifact, :keep_latest_artifact=, to: :ci_cd_settings, allow_nil: true + delegate :restrict_user_defined_variables, :restrict_user_defined_variables=, to: :ci_cd_settings, allow_nil: true delegate :actual_limits, :actual_plan_name, to: :namespace, allow_nil: true delegate :allow_merge_on_skipped_pipeline, :allow_merge_on_skipped_pipeline?, :allow_merge_on_skipped_pipeline=, :has_confluence?, :allow_editing_commit_messages?, @@ -2634,6 +2633,42 @@ class Project < ApplicationRecord end alias_method :container_registry_enabled?, :container_registry_enabled + def ci_forward_deployment_enabled? + return false unless ci_cd_settings + + ci_cd_settings.forward_deployment_enabled? + end + + def ci_job_token_scope_enabled? + return false unless ci_cd_settings + + ci_cd_settings.job_token_scope_enabled? + end + + def restrict_user_defined_variables? + return false unless ci_cd_settings + + ci_cd_settings.restrict_user_defined_variables? + end + + def keep_latest_artifacts_available? + return false unless ci_cd_settings + + ci_cd_settings.keep_latest_artifacts_available? + end + + def keep_latest_artifact? + return false unless ci_cd_settings + + ci_cd_settings.keep_latest_artifact? + end + + def group_runners_enabled? + return false unless ci_cd_settings + + ci_cd_settings.group_runners_enabled? + end + private def set_container_registry_access_level @@ -169,6 +169,8 @@ module QA autoload :ObjectStorage, 'qa/scenario/test/integration/object_storage' autoload :SMTP, 'qa/scenario/test/integration/smtp' autoload :SSHTunnel, 'qa/scenario/test/integration/ssh_tunnel' + autoload :RegistryTLS, 'qa/scenario/test/integration/registry_tls' + autoload :Registry, 'qa/scenario/test/integration/registry' end module Sanity diff --git a/qa/qa/page/project/import/github.rb b/qa/qa/page/project/import/github.rb index dc683f7314b..83d9b160c8f 100644 --- a/qa/qa/page/project/import/github.rb +++ b/qa/qa/page/project/import/github.rb @@ -77,7 +77,9 @@ module QA reload: true, skip_finished_loading_check_on_refresh: true ) do - page.has_no_content?('Importing 1 repository') + # TODO: Refactor to explicitly wait for specific project import successful status + # This check can create false positive if main importing message appears with delay and check exits early + page.has_no_content?('Importing 1 repository', wait: 3) end end diff --git a/qa/qa/scenario/test/integration/registry.rb b/qa/qa/scenario/test/integration/registry.rb new file mode 100644 index 00000000000..28b74c99ab3 --- /dev/null +++ b/qa/qa/scenario/test/integration/registry.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module QA + module Scenario + module Test + module Integration + class Registry < Test::Instance::All + tags :registry + end + end + end + end +end diff --git a/qa/qa/scenario/test/integration/registry_tls.rb b/qa/qa/scenario/test/integration/registry_tls.rb new file mode 100644 index 00000000000..4e9d6b6ea97 --- /dev/null +++ b/qa/qa/scenario/test/integration/registry_tls.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module QA + module Scenario + module Test + module Integration + class RegistryTLS < Test::Instance::All + tags :registry_tls + end + end + end + end +end diff --git a/qa/qa/specs/features/browser_ui/1_manage/group/bulk_import_group_spec.rb b/qa/qa/specs/features/browser_ui/1_manage/group/bulk_import_group_spec.rb index d4c4ec5611a..ef9507e16bc 100644 --- a/qa/qa/specs/features/browser_ui/1_manage/group/bulk_import_group_spec.rb +++ b/qa/qa/specs/features/browser_ui/1_manage/group/bulk_import_group_spec.rb @@ -14,20 +14,20 @@ module QA let!(:api_client) { Runtime::API::Client.new(user: user) } let!(:personal_access_token) { api_client.personal_access_token } - let!(:sandbox) do + let(:sandbox) do Resource::Sandbox.fabricate_via_api! do |group| group.api_client = admin_api_client end end - let!(:source_group) do + let(:source_group) do Resource::Sandbox.fabricate_via_api! do |group| group.api_client = api_client group.path = "source-group-for-import-#{SecureRandom.hex(4)}" end end - let!(:subgroup) do + let(:subgroup) do Resource::Group.fabricate_via_api! do |group| group.api_client = api_client group.sandbox = source_group @@ -63,6 +63,10 @@ module QA before do sandbox.add_member(user, Resource::Members::AccessLevel::MAINTAINER) + # create groups explicitly before connecting gitlab instance + source_group + subgroup + Flow::Login.sign_in(as: user) Page::Main::Menu.perform(&:go_to_create_group) Page::Group::New.perform do |group| @@ -73,6 +77,7 @@ module QA # Non blocking issues: # https://gitlab.com/gitlab-org/gitlab/-/issues/331252 + # https://gitlab.com/gitlab-org/gitlab/-/issues/333678 <- can cause 500 when creating user and group back to back it( 'imports group with subgroups and labels', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/1785', @@ -96,9 +101,9 @@ module QA Page::Group::BulkImport.perform do |import_page| import_page.import_group(source_group.path, sandbox.path) - aggregate_failures do - expect(import_page).to have_imported_group(source_group.path, wait: 180) + expect(import_page).to have_imported_group(source_group.path, wait: 180) + aggregate_failures do expect { imported_group.reload! }.to eventually_eq(source_group).within(duration: 10) expect { imported_group.labels }.to eventually_include(*source_group.labels).within(duration: 10) diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 144b00e1d2e..588bcc7ef94 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -656,6 +656,53 @@ RSpec.describe Project, factory_default: :keep do it { is_expected.to delegate_method(:container_registry_enabled?).to(:project_feature) } it { is_expected.to delegate_method(:container_registry_access_level).to(:project_feature) } + include_examples 'ci_cd_settings delegation' do + # Skip attributes defined in EE code + let(:exclude_attributes) do + %w( + merge_pipelines_enabled + merge_trains_enabled + auto_rollback_enabled + ) + end + end + + describe '#ci_forward_deployment_enabled?' do + it_behaves_like 'a ci_cd_settings predicate method', prefix: 'ci_' do + let(:delegated_method) { :forward_deployment_enabled? } + end + end + + describe '#ci_job_token_scope_enabled?' do + it_behaves_like 'a ci_cd_settings predicate method', prefix: 'ci_' do + let(:delegated_method) { :job_token_scope_enabled? } + end + end + + describe '#restrict_user_defined_variables?' do + it_behaves_like 'a ci_cd_settings predicate method' do + let(:delegated_method) { :restrict_user_defined_variables? } + end + end + + describe '#keep_latest_artifacts_available?' do + it_behaves_like 'a ci_cd_settings predicate method' do + let(:delegated_method) { :keep_latest_artifacts_available? } + end + end + + describe '#keep_latest_artifact?' do + it_behaves_like 'a ci_cd_settings predicate method' do + let(:delegated_method) { :keep_latest_artifact? } + end + end + + describe '#group_runners_enabled?' do + it_behaves_like 'a ci_cd_settings predicate method' do + let(:delegated_method) { :group_runners_enabled? } + end + end + context 'when read_container_registry_access_level is disabled' do before do stub_feature_flags(read_container_registry_access_level: false) diff --git a/spec/support/shared_examples/models/project_ci_cd_settings_shared_examples.rb b/spec/support/shared_examples/models/project_ci_cd_settings_shared_examples.rb new file mode 100644 index 00000000000..c92e819db19 --- /dev/null +++ b/spec/support/shared_examples/models/project_ci_cd_settings_shared_examples.rb @@ -0,0 +1,54 @@ +# frozen_string_literal: true + +RSpec.shared_examples 'ci_cd_settings delegation' do + let(:exclude_attributes) { [] } + + context 'when ci_cd_settings is destroyed but project is not' do + it 'allows methods delegated to ci_cd_settings to be nil', :aggregate_failures do + project = create(:project) + attributes = project.ci_cd_settings.attributes.keys - %w(id project_id) - exclude_attributes + project.ci_cd_settings.destroy! + project.reload + attributes.each do |attr| + method = project.respond_to?("ci_#{attr}") ? "ci_#{attr}" : attr + expect(project.send(method)).to be_nil, "#{attr} was not nil" + end + end + end +end + +RSpec.shared_examples 'a ci_cd_settings predicate method' do |prefix: ''| + using RSpec::Parameterized::TableSyntax + + let_it_be(:project) { create(:project) } + + context 'when ci_cd_settings is nil' do + before do + allow(project).to receive(:ci_cd_settings).and_return(nil) + end + + it 'returns false' do + expect(project.send("#{prefix}#{delegated_method}")).to be(false) + end + end + + context 'when ci_cd_settings is not nil' do + where(:delegated_method_return, :subject_return) do + true | true + false | false + end + + with_them do + let(:ci_cd_settings_double) { double('ProjectCiCdSetting') } + + before do + allow(project).to receive(:ci_cd_settings).and_return(ci_cd_settings_double) + allow(ci_cd_settings_double).to receive(delegated_method).and_return(delegated_method_return) + end + + it 'returns the expected boolean value' do + expect(project.send("#{prefix}#{delegated_method}")).to be(subject_return) + end + end + end +end |