diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2024-01-16 21:09:25 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2024-01-16 21:09:25 +0300 |
commit | e18006fc6313b1d04128416cdb5f1533adcdb53e (patch) | |
tree | ad418c4afbfcc8f83bcf5b4a9c897a2139e79e13 /spec/lib | |
parent | cb8835f38a3e4c188e9a73adf45936e2a95f40ae (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/gitlab/auth_spec.rb | 76 | ||||
-rw-r--r-- | spec/lib/gitlab/bitbucket_server_import/importers/pull_request_importer_spec.rb | 5 | ||||
-rw-r--r-- | spec/lib/gitlab/bitbucket_server_import/importers/pull_request_notes_importer_spec.rb | 4 | ||||
-rw-r--r-- | spec/lib/gitlab/checks/lfs_check_spec.rb | 12 | ||||
-rw-r--r-- | spec/lib/gitlab/import/mentions_converter_spec.rb (renamed from spec/lib/gitlab/bitbucket_server_import/mentions_converter_spec.rb) | 5 | ||||
-rw-r--r-- | spec/lib/gitlab/import/user_from_mention_spec.rb (renamed from spec/lib/gitlab/bitbucket_server_import/user_from_mention_spec.rb) | 14 | ||||
-rw-r--r-- | spec/lib/gitlab/observability_spec.rb | 47 | ||||
-rw-r--r-- | spec/lib/gitlab/protocol_access_spec.rb | 47 | ||||
-rw-r--r-- | spec/lib/google_cloud_platform/artifact_registry/client_spec.rb (renamed from spec/lib/integrations/google_cloud_platform/artifact_registry/client_spec.rb) | 2 | ||||
-rw-r--r-- | spec/lib/google_cloud_platform/jwt_spec.rb (renamed from spec/lib/integrations/google_cloud_platform/jwt_spec.rb) | 2 |
10 files changed, 98 insertions, 116 deletions
diff --git a/spec/lib/gitlab/auth_spec.rb b/spec/lib/gitlab/auth_spec.rb index fd51ebbc8fa..3c87ac258b3 100644 --- a/spec/lib/gitlab/auth_spec.rb +++ b/spec/lib/gitlab/auth_spec.rb @@ -75,10 +75,12 @@ RSpec.describe Gitlab::Auth, :use_clean_rails_memory_store_caching, feature_cate expect(subject.optional_scopes).to match_array %i[read_user read_api read_repository write_repository read_registry read_service_ping write_registry sudo admin_mode openid profile email read_observability write_observability create_runner k8s_proxy ai_features] end - context 'with observability_tracing feature flag' do - context 'when disabled' do + context 'with observability feature flags' do + feature_flags = [:observability_tracing, :observability_metrics] + + context 'when all disabled' do before do - stub_feature_flags(observability_tracing: false) + stub_feature_flags(feature_flags.index_with { false }) end it 'contains for group all resource bot scopes without observability scopes' do @@ -99,49 +101,55 @@ RSpec.describe Gitlab::Auth, :use_clean_rails_memory_store_caching, feature_cate end end - context 'when enabled for specific root group' do - let(:parent) { build_stubbed(:group) } - let(:group) do - build_stubbed(:group, parent: parent).tap { |g| g.namespace_settings = build_stubbed(:namespace_settings, namespace: g) } - end + flag_states = [true, false].repeated_permutation(feature_flags.length) + flag_tests = flag_states.filter(&:any?).map { |flags| Hash[feature_flags.zip(flags)] } - let(:project) { build_stubbed(:project, namespace: group) } + flag_tests.each do |flags| + context "with flags #{flags} enabled for specific root group" do + let(:parent) { build_stubbed(:group) } + let(:group) do + build_stubbed(:group, parent: parent).tap { |g| g.namespace_settings = build_stubbed(:namespace_settings, namespace: g) } + end - before do - stub_feature_flags(observability_tracing: parent) - end + let(:project) { build_stubbed(:project, namespace: group) } - it 'contains for group all resource bot scopes including observability scopes' do - expect(subject.available_scopes_for(group)).to match_array %i[api read_api read_repository write_repository read_registry write_registry read_observability write_observability create_runner k8s_proxy ai_features] - end + before do + flags.transform_values! { |v| v ? parent : false } + stub_feature_flags(flags) + end - it 'contains for admin user all non-default scopes with ADMIN access and without observability scopes' do - user = build_stubbed(:user, admin: true) + it 'contains for group all resource bot scopes including observability scopes' do + expect(subject.available_scopes_for(group)).to match_array %i[api read_api read_repository write_repository read_registry write_registry read_observability write_observability create_runner k8s_proxy ai_features] + end - expect(subject.available_scopes_for(user)).to match_array %i[api read_user read_api read_repository write_repository read_registry write_registry read_service_ping sudo admin_mode create_runner k8s_proxy ai_features] - end + it 'contains for admin user all non-default scopes with ADMIN access and without observability scopes' do + user = build_stubbed(:user, admin: true) - it 'contains for project all resource bot scopes including observability scopes' do - expect(subject.available_scopes_for(project)).to match_array %i[api read_api read_repository write_repository read_registry write_registry read_observability write_observability create_runner k8s_proxy ai_features] - end + expect(subject.available_scopes_for(user)).to match_array %i[api read_user read_api read_repository write_repository read_registry write_registry read_service_ping sudo admin_mode create_runner k8s_proxy ai_features] + end - it 'contains for other group all resource bot scopes without observability scopes' do - other_parent = build_stubbed(:group) - other_group = build_stubbed(:group, parent: other_parent).tap do |g| - g.namespace_settings = build_stubbed(:namespace_settings, namespace: g) + it 'contains for project all resource bot scopes including observability scopes' do + expect(subject.available_scopes_for(project)).to match_array %i[api read_api read_repository write_repository read_registry write_registry read_observability write_observability create_runner k8s_proxy ai_features] end - expect(subject.available_scopes_for(other_group)).to match_array %i[api read_api read_repository write_repository read_registry write_registry create_runner k8s_proxy ai_features] - end + it 'contains for other group all resource bot scopes without observability scopes' do + other_parent = build_stubbed(:group) + other_group = build_stubbed(:group, parent: other_parent).tap do |g| + g.namespace_settings = build_stubbed(:namespace_settings, namespace: g) + end - it 'contains for other project all resource bot scopes without observability scopes' do - other_parent = build_stubbed(:group) - other_group = build_stubbed(:group, parent: other_parent).tap do |g| - g.namespace_settings = build_stubbed(:namespace_settings, namespace: g) + expect(subject.available_scopes_for(other_group)).to match_array %i[api read_api read_repository write_repository read_registry write_registry create_runner k8s_proxy ai_features] end - other_project = build_stubbed(:project, namespace: other_group) - expect(subject.available_scopes_for(other_project)).to match_array %i[api read_api read_repository write_repository read_registry write_registry create_runner k8s_proxy ai_features] + it 'contains for other project all resource bot scopes without observability scopes' do + other_parent = build_stubbed(:group) + other_group = build_stubbed(:group, parent: other_parent).tap do |g| + g.namespace_settings = build_stubbed(:namespace_settings, namespace: g) + end + other_project = build_stubbed(:project, namespace: other_group) + + expect(subject.available_scopes_for(other_project)).to match_array %i[api read_api read_repository write_repository read_registry write_registry create_runner k8s_proxy ai_features] + end end end end diff --git a/spec/lib/gitlab/bitbucket_server_import/importers/pull_request_importer_spec.rb b/spec/lib/gitlab/bitbucket_server_import/importers/pull_request_importer_spec.rb index eeb2f9c8000..bff25fb723f 100644 --- a/spec/lib/gitlab/bitbucket_server_import/importers/pull_request_importer_spec.rb +++ b/spec/lib/gitlab/bitbucket_server_import/importers/pull_request_importer_spec.rb @@ -18,7 +18,8 @@ RSpec.describe Gitlab::BitbucketServerImport::Importers::PullRequestImporter, fe it 'imports the merge request correctly' do expect_next(Gitlab::Import::MergeRequestCreator, project).to receive(:execute).and_call_original expect_next(Gitlab::BitbucketServerImport::UserFinder, project).to receive(:author_id).and_call_original - expect_next(Gitlab::BitbucketServerImport::MentionsConverter, project.id).to receive(:convert).and_call_original + expect_next(Gitlab::Import::MentionsConverter, 'bitbucket_server', + project.id).to receive(:convert).and_call_original expect { importer.execute }.to change { MergeRequest.count }.by(1) @@ -42,7 +43,7 @@ RSpec.describe Gitlab::BitbucketServerImport::Importers::PullRequestImporter, fe end it 'does not convert mentions' do - expect_next(Gitlab::BitbucketServerImport::MentionsConverter, project.id).not_to receive(:convert) + expect_next(Gitlab::Import::MentionsConverter, 'bitbucket_server', project.id).not_to receive(:convert) importer.execute end diff --git a/spec/lib/gitlab/bitbucket_server_import/importers/pull_request_notes_importer_spec.rb b/spec/lib/gitlab/bitbucket_server_import/importers/pull_request_notes_importer_spec.rb index 7b662c1a2c7..31035d8844e 100644 --- a/spec/lib/gitlab/bitbucket_server_import/importers/pull_request_notes_importer_spec.rb +++ b/spec/lib/gitlab/bitbucket_server_import/importers/pull_request_notes_importer_spec.rb @@ -17,7 +17,7 @@ RSpec.describe Gitlab::BitbucketServerImport::Importers::PullRequestNotesImporte let_it_be(:pull_request_data) { Gitlab::Json.parse(fixture_file('importers/bitbucket_server/pull_request.json')) } let_it_be(:pull_request) { BitbucketServer::Representation::PullRequest.new(pull_request_data) } let_it_be(:note_author) { create(:user, username: 'note_author', email: 'note_author@example.org') } - let(:mentions_converter) { Gitlab::BitbucketServerImport::MentionsConverter.new(project) } + let(:mentions_converter) { Gitlab::Import::MentionsConverter.new('bitbucket_server', project) } let!(:pull_request_author) do create(:user, username: 'pull_request_author', email: 'pull_request_author@example.org') @@ -81,7 +81,7 @@ RSpec.describe Gitlab::BitbucketServerImport::Importers::PullRequestNotesImporte end before do - allow(Gitlab::BitbucketServerImport::MentionsConverter).to receive(:new).and_return(mentions_converter) + allow(Gitlab::Import::MentionsConverter).to receive(:new).and_return(mentions_converter) end subject(:importer) { described_class.new(project.reload, pull_request.to_hash) } diff --git a/spec/lib/gitlab/checks/lfs_check_spec.rb b/spec/lib/gitlab/checks/lfs_check_spec.rb index f00915bc1ec..ef27b30475f 100644 --- a/spec/lib/gitlab/checks/lfs_check_spec.rb +++ b/spec/lib/gitlab/checks/lfs_check_spec.rb @@ -31,18 +31,6 @@ RSpec.describe Gitlab::Checks::LfsCheck, feature_category: :source_code_manageme allow(project).to receive(:lfs_enabled?).and_return(true) end - context 'with lfs_check feature disabled' do - before do - stub_feature_flags(lfs_check: false) - end - - it 'skips integrity check' do - expect_any_instance_of(Gitlab::Git::LfsChanges).not_to receive(:new_pointers) - - subject.validate! - end - end - context 'with deletion' do shared_examples 'a skipped integrity check' do it 'skips integrity check' do diff --git a/spec/lib/gitlab/bitbucket_server_import/mentions_converter_spec.rb b/spec/lib/gitlab/import/mentions_converter_spec.rb index 46800c924c9..122d7f227cc 100644 --- a/spec/lib/gitlab/bitbucket_server_import/mentions_converter_spec.rb +++ b/spec/lib/gitlab/import/mentions_converter_spec.rb @@ -2,12 +2,13 @@ require 'spec_helper' -RSpec.describe Gitlab::BitbucketServerImport::MentionsConverter, :clean_gitlab_redis_cache, feature_category: :importers do +RSpec.describe Gitlab::Import::MentionsConverter, :clean_gitlab_redis_cache, feature_category: :importers do let(:project_id) { 12 } + let(:importer) { 'bitbucket_server' } let(:text) { 'text without @ mentions' } let(:source_user_cache_prefix) { "bitbucket_server/project/#{project_id}/source/username" } - subject(:converted_text) { described_class.new(project_id).convert(text) } + subject(:converted_text) { described_class.new(importer, project_id).convert(text) } describe '#convert' do context 'when the text has no mentions' do diff --git a/spec/lib/gitlab/bitbucket_server_import/user_from_mention_spec.rb b/spec/lib/gitlab/import/user_from_mention_spec.rb index 73f9cde8322..0dcd7f92ee6 100644 --- a/spec/lib/gitlab/bitbucket_server_import/user_from_mention_spec.rb +++ b/spec/lib/gitlab/import/user_from_mention_spec.rb @@ -2,22 +2,24 @@ require 'spec_helper' -RSpec.describe Gitlab::BitbucketServerImport::UserFromMention, :clean_gitlab_redis_cache, feature_category: :importers do +RSpec.describe Gitlab::Import::UserFromMention, :clean_gitlab_redis_cache, feature_category: :importers do let(:project_id) { 11 } let(:username) { '@johndoe' } let(:email) { 'john@gmail.com' } let(:hash) { { key: 'value' } } - let(:cache_key) { "bitbucket_server/project/#{project_id}/source/username/#{username}" } + let(:importer) { 'bitbucket_server' } + let(:cache_key) { "#{importer}/project/#{project_id}/source/username/#{username}" } let(:example) do Class.new do - include Gitlab::BitbucketServerImport::UserFromMention + include Gitlab::Import::UserFromMention - def initialize(project_id) + def initialize(importer, project_id) + @importer = importer @project_id = project_id end - attr_reader :project_id + attr_reader :project_id, :importer def foo(mention) user_from_cache(mention) @@ -29,7 +31,7 @@ RSpec.describe Gitlab::BitbucketServerImport::UserFromMention, :clean_gitlab_red end end - subject(:example_class) { example.new(project_id) } + subject(:example_class) { example.new(importer, project_id) } describe '#user_from_cache' do it 'returns nil if the cache is empty' do diff --git a/spec/lib/gitlab/observability_spec.rb b/spec/lib/gitlab/observability_spec.rb index 7af2daea11c..221923ac12a 100644 --- a/spec/lib/gitlab/observability_spec.rb +++ b/spec/lib/gitlab/observability_spec.rb @@ -56,44 +56,35 @@ RSpec.describe Gitlab::Observability, feature_category: :error_tracking do end end - before do - stub_feature_flags(observability_tracing: parent) - end - - describe 'when resource is group' do - context 'if observability_tracing FF enabled' do - it { is_expected.to be true } - end + feature_flags = [:observability_tracing, :observability_metrics] + flag_states = [true, false].repeated_permutation(feature_flags.length) + flag_tests = flag_states.map { |flags| Hash[feature_flags.zip(flags)] } - context 'if observability_tracing FF disabled' do + flag_tests.each do |flags| + context "with feature flag state #{flags}" do before do - stub_feature_flags(observability_tracing: false) + flags.transform_values! { |v| v ? parent : false } + stub_feature_flags(flags) end - it { is_expected.to be false } - end - end + let(:expected_enabled) { flags.values.any? } - describe 'when resource is project' do - let(:resource) { build_stubbed(:project, namespace: parent) } + describe 'when resource is group' do + it { is_expected.to be expected_enabled } + end - context 'if observability_tracing FF enabled' do - it { is_expected.to be true } - end + describe 'when resource is project' do + let(:resource) { build_stubbed(:project, namespace: parent) } - context 'if observability_tracing FF disabled' do - before do - stub_feature_flags(observability_tracing: false) + it { is_expected.to be expected_enabled } end - it { is_expected.to be false } - end - end + describe 'when resource is not a group or project' do + let(:resource) { build_stubbed(:user) } - describe 'when resource is not a group or project' do - let(:resource) { build_stubbed(:user) } - - it { is_expected.to be false } + it { is_expected.to be false } + end + end end end end diff --git a/spec/lib/gitlab/protocol_access_spec.rb b/spec/lib/gitlab/protocol_access_spec.rb index cae14c3d7cf..e7e81b4b3e1 100644 --- a/spec/lib/gitlab/protocol_access_spec.rb +++ b/spec/lib/gitlab/protocol_access_spec.rb @@ -10,34 +10,25 @@ RSpec.describe Gitlab::ProtocolAccess, feature_category: :source_code_management describe ".allowed?" do where(:protocol, :project, :admin_setting, :namespace_setting, :expected_result) do - "web" | nil | nil | nil | true - "ssh" | nil | nil | nil | true - "http" | nil | nil | nil | true - "ssh_certificates" | nil | nil | nil | true - "ssh" | nil | "" | nil | true - "http" | nil | "" | nil | true - "ssh_certificates" | nil | "" | nil | true - "ssh" | nil | "ssh" | nil | true - "http" | nil | "http" | nil | true - "ssh_certificates" | nil | "ssh_certificates" | nil | true - "ssh" | nil | "http" | nil | false - "http" | nil | "ssh" | nil | false - "ssh_certificates" | nil | "ssh" | nil | false - "ssh" | ref(:p1) | nil | "all" | true - "http" | ref(:p1) | nil | "all" | true - "ssh_certificates" | ref(:p1) | nil | "all" | true - "ssh" | ref(:p1) | nil | "ssh" | true - "http" | ref(:p1) | nil | "http" | true - "ssh_certificates" | ref(:p1) | nil | "ssh_certificates" | true - "ssh" | ref(:p1) | nil | "http" | false - "http" | ref(:p1) | nil | "ssh" | false - "ssh_certificates" | ref(:p1) | nil | "ssh" | false - "ssh" | ref(:p1) | "" | "all" | true - "http" | ref(:p1) | "" | "all" | true - "ssh_certificates" | ref(:p1) | "" | "all" | true - "ssh" | ref(:p1) | "ssh" | "ssh" | true - "http" | ref(:p1) | "http" | "http" | true - "ssh_certificates" | ref(:p1) | "ssh_certificates" | "ssh_certificates" | true + "web" | nil | nil | nil | true + "ssh" | nil | nil | nil | true + "http" | nil | nil | nil | true + "ssh" | nil | "" | nil | true + "http" | nil | "" | nil | true + "ssh" | nil | "ssh" | nil | true + "http" | nil | "http" | nil | true + "ssh" | nil | "http" | nil | false + "http" | nil | "ssh" | nil | false + "ssh" | ref(:p1) | nil | "all" | true + "http" | ref(:p1) | nil | "all" | true + "ssh" | ref(:p1) | nil | "ssh" | true + "http" | ref(:p1) | nil | "http" | true + "ssh" | ref(:p1) | nil | "http" | false + "http" | ref(:p1) | nil | "ssh" | false + "ssh" | ref(:p1) | "" | "all" | true + "http" | ref(:p1) | "" | "all" | true + "ssh" | ref(:p1) | "ssh" | "ssh" | true + "http" | ref(:p1) | "http" | "http" | true end with_them do diff --git a/spec/lib/integrations/google_cloud_platform/artifact_registry/client_spec.rb b/spec/lib/google_cloud_platform/artifact_registry/client_spec.rb index a258518953a..09ddba7c091 100644 --- a/spec/lib/integrations/google_cloud_platform/artifact_registry/client_spec.rb +++ b/spec/lib/google_cloud_platform/artifact_registry/client_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Integrations::GoogleCloudPlatform::ArtifactRegistry::Client, feature_category: :container_registry do +RSpec.describe GoogleCloudPlatform::ArtifactRegistry::Client, feature_category: :container_registry do let_it_be(:project) { create(:project) } let_it_be(:rsa_key) { OpenSSL::PKey::RSA.generate(3072) } let_it_be(:rsa_key_data) { rsa_key.to_s } diff --git a/spec/lib/integrations/google_cloud_platform/jwt_spec.rb b/spec/lib/google_cloud_platform/jwt_spec.rb index 51707c26a3a..d41056a8606 100644 --- a/spec/lib/integrations/google_cloud_platform/jwt_spec.rb +++ b/spec/lib/google_cloud_platform/jwt_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Integrations::GoogleCloudPlatform::Jwt, feature_category: :shared do +RSpec.describe GoogleCloudPlatform::Jwt, feature_category: :shared do let_it_be(:project) { create(:project) } let_it_be(:user) { create(:user) } |